@capillarytech/creatives-library 8.0.292-alpha.12 → 8.0.292-alpha.14

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "8.0.292-alpha.12",
4
+ "version": "8.0.292-alpha.14",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -324,7 +324,7 @@ const HTMLEditor = forwardRef(({
324
324
  : countIssuesBySeverity(validation.getAllIssues()),
325
325
  })
326
326
  ,
327
- }), [validation, currentContent, apiValidationErrors]); // Include apiValidationErrors so ref methods return updated counts
327
+ }), [validation, currentContent, apiValidationErrors]);
328
328
 
329
329
  // Use ref to store callback to avoid infinite loops (callback in deps would cause re-runs)
330
330
  const onValidationChangeRef = useRef(onValidationChange);
@@ -832,5 +832,5 @@ HTMLEditor.defaultProps = {
832
832
  apiValidationErrors: null, // API validation errors from validateLiquidTemplateContent
833
833
  };
834
834
 
835
- // Export with injectIntl - HTMLEditor now uses forwardRef internally
835
+ // Export with injectIntl - HTMLEditor uses forwardRef internally
836
836
  export default injectIntl(HTMLEditor);
@@ -142,9 +142,13 @@ export const InApp = (props) => {
142
142
  const [isHTMLTemplate, setIsHTMLTemplate] = useState(false);
143
143
  // Version to force HTMLEditor remount on layout changes
144
144
  const [htmlEditorContentVersion, setHtmlEditorContentVersion] = useState(0);
145
- // Refs to store latest content before layout changes
145
+ // Refs to store latest content (kept in sync in handleHtmlContentChange so Test and Preview reads fresh content in library mode)
146
146
  const htmlContentAndroidRef = useRef(htmlContentAndroid);
147
147
  const htmlContentIosRef = useRef(htmlContentIos);
148
+ useEffect(() => {
149
+ htmlContentAndroidRef.current = htmlContentAndroid;
150
+ htmlContentIosRef.current = htmlContentIos;
151
+ }, [htmlContentAndroid, htmlContentIos]);
148
152
  const [accountId, setAccountId] = useState("");
149
153
  const [accessToken, setAccessToken] = useState("");
150
154
  const [accountName, setAccountName] = useState("");
@@ -172,14 +176,15 @@ export const InApp = (props) => {
172
176
  // TestAndPreviewSlidebox state
173
177
  const [showTestAndPreviewSlidebox, setShowTestAndPreviewSlidebox] = useState(false);
174
178
 
175
- // Get template content for TestAndPreviewSlidebox
176
- // Returns simple structure with preview fields only
177
- // Transformation to payload structure happens in prepareTestMessagePayload
178
- // Reference: Based on getPreviewSection() function (lines 490-530) which prepares content for TemplatePreview
179
+ // Get template content for TestAndPreviewSlidebox (same pattern as Mobile Push: read current content for preview)
180
+ // State is updated on every keystroke via onContentChange; refs are synced so we read fresh content in library mode too.
179
181
  const getTemplateContent = useCallback(() => {
180
- // For HTML template, use HTML editor content so preview stays in sync with typing
181
- const androidMsg = isHTMLTemplate ? (htmlContentAndroid ?? '') : templateMessageAndroid;
182
- const iosMsg = isHTMLTemplate ? (htmlContentIos ?? '') : templateMessageIos;
182
+ const androidMsg = isHTMLTemplate
183
+ ? (htmlContentAndroidRef.current ?? htmlContentAndroid ?? '')
184
+ : templateMessageAndroid;
185
+ const iosMsg = isHTMLTemplate
186
+ ? (htmlContentIosRef.current ?? htmlContentIos ?? '')
187
+ : templateMessageIos;
183
188
 
184
189
  // Prepare Android content
185
190
  const androidMediaPreview = {};
@@ -1008,11 +1013,12 @@ export const InApp = (props) => {
1008
1013
  );
1009
1014
  };
1010
1015
 
1011
- // Handle HTML content changes from HTMLEditor
1016
+ // Handle HTML content changes from HTMLEditor - update state and refs so Test and Preview has fresh content (full + library mode)
1012
1017
  const handleHtmlContentChange = useCallback((deviceContent, changedDevice) => {
1013
1018
  // When "keep content same" is on, useInAppContent passes full deviceContent with both
1014
1019
  // android and ios set to the same value. We must update both states so preview shows
1015
1020
  // the synced content for each device. Otherwise only update the device that changed.
1021
+ // Refs are updated synchronously so getTemplateContent() reads latest when opening the slidebox.
1016
1022
 
1017
1023
  // Clear validation errors when content changes (similar to Bee Editor)
1018
1024
  if (changedDevice) {
@@ -1035,33 +1041,36 @@ export const InApp = (props) => {
1035
1041
  const isSyncUpdate = hasAndroid && hasIos;
1036
1042
 
1037
1043
  if (isSyncUpdate) {
1038
- // Sync mode: update both so preview shows same content for Android and iOS
1039
1044
  if (hasAndroid) {
1040
- setHtmlContentAndroid(deviceContent.android || '');
1045
+ const v = deviceContent.android || '';
1046
+ htmlContentAndroidRef.current = v;
1047
+ setHtmlContentAndroid(v);
1041
1048
  }
1042
1049
  if (hasIos) {
1043
- setHtmlContentIos(deviceContent.ios || '');
1050
+ const v = deviceContent.ios || '';
1051
+ htmlContentIosRef.current = v;
1052
+ setHtmlContentIos(v);
1044
1053
  }
1045
1054
  } else if (changedDevice) {
1046
- // Only one device changed
1047
1055
  if (changedDevice.toUpperCase() === ANDROID && hasAndroid) {
1048
- setHtmlContentAndroid(deviceContent.android || '');
1056
+ const v = deviceContent.android || '';
1057
+ htmlContentAndroidRef.current = v;
1058
+ setHtmlContentAndroid(v);
1049
1059
  } else if (changedDevice.toUpperCase() === IOS_CAPITAL && hasIos) {
1050
- setHtmlContentIos(deviceContent.ios || '');
1060
+ const v = deviceContent.ios || '';
1061
+ htmlContentIosRef.current = v;
1062
+ setHtmlContentIos(v);
1051
1063
  }
1052
1064
  } else {
1053
- // Fallback: update both if changedDevice not provided
1054
1065
  if (hasAndroid) {
1055
- setHtmlContentAndroid((prev) => {
1056
- const newValue = deviceContent.android || '';
1057
- return prev !== newValue ? newValue : prev;
1058
- });
1066
+ const newValue = deviceContent.android || '';
1067
+ htmlContentAndroidRef.current = newValue;
1068
+ setHtmlContentAndroid((prev) => (prev !== newValue ? newValue : prev));
1059
1069
  }
1060
1070
  if (hasIos) {
1061
- setHtmlContentIos((prev) => {
1062
- const newValue = deviceContent.ios || '';
1063
- return prev !== newValue ? newValue : prev;
1064
- });
1071
+ const newValue = deviceContent.ios || '';
1072
+ htmlContentIosRef.current = newValue;
1073
+ setHtmlContentIos((prev) => (prev !== newValue ? newValue : prev));
1065
1074
  }
1066
1075
  }
1067
1076
  }, [ANDROID, IOS_CAPITAL, setErrorMessage]);