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

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.13",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -305,10 +305,13 @@ const HTMLEditor = forwardRef(({
305
305
  apiValidationErrors, // Pass API validation errors to merge with client-side validation
306
306
  }, formatSanitizerMessage, formatValidatorMessage);
307
307
 
308
- // Expose validation and content state via ref
308
+ // Expose validation and content state via ref (InApp: also expose getDeviceContent for Test and Preview)
309
309
  useImperativeHandle(ref, () => ({
310
310
  getValidation: () => validation,
311
311
  getContent: () => currentContent,
312
+ getDeviceContent: variant === HTML_EDITOR_VARIANTS.INAPP && typeof getDeviceContent === 'function'
313
+ ? getDeviceContent
314
+ : undefined,
312
315
  isContentEmpty: () => !currentContent || currentContent.trim() === '',
313
316
  getIssueCounts: () => {
314
317
  if (!validation || typeof validation.getAllIssues !== 'function') {
@@ -324,7 +327,7 @@ const HTMLEditor = forwardRef(({
324
327
  : countIssuesBySeverity(validation.getAllIssues()),
325
328
  })
326
329
  ,
327
- }), [validation, currentContent, apiValidationErrors]); // Include apiValidationErrors so ref methods return updated counts
330
+ }), [validation, currentContent, apiValidationErrors, variant, getDeviceContent]);
328
331
 
329
332
  // Use ref to store callback to avoid infinite loops (callback in deps would cause re-runs)
330
333
  const onValidationChangeRef = useRef(onValidationChange);
@@ -832,5 +835,5 @@ HTMLEditor.defaultProps = {
832
835
  apiValidationErrors: null, // API validation errors from validateLiquidTemplateContent
833
836
  };
834
837
 
835
- // Export with injectIntl - HTMLEditor now uses forwardRef internally
836
- export default injectIntl(HTMLEditor);
838
+ // Export with injectIntl - forwardRef so parent (e.g. InApp) can use ref for getDeviceContent (Test and Preview)
839
+ export default injectIntl(HTMLEditor, { forwardRef: true });
@@ -40,14 +40,14 @@ const LazyHTMLEditor = React.lazy(() =>
40
40
  *
41
41
  * This component wraps the HTMLEditor with React.lazy() and Suspense
42
42
  * to enable code splitting and reduce initial bundle size.
43
+ * Forwards ref so parent (e.g. InApp) can call getDeviceContent for Test and Preview.
43
44
  */
44
- const HTMLEditorLazy = (props) => {
45
- return (
46
- <Suspense fallback={<HTMLEditorFallback />}>
47
- <LazyHTMLEditor {...props} />
48
- </Suspense>
49
- );
50
- };
45
+ const HTMLEditorLazy = React.forwardRef((props, ref) => (
46
+ <Suspense fallback={<HTMLEditorFallback />}>
47
+ <LazyHTMLEditor {...props} ref={ref} />
48
+ </Suspense>
49
+ ));
50
+ HTMLEditorLazy.displayName = 'HTMLEditorLazy';
51
51
 
52
52
  // Forward all prop types from the original component
53
53
  HTMLEditorLazy.propTypes = {
@@ -61,7 +61,7 @@ import { validateInAppContent } from "../../utils/commonUtils";
61
61
  import { hasLiquidSupportFeature } from "../../utils/common";
62
62
  import formBuilderMessages from "../../v2Components/FormBuilder/messages";
63
63
  import HTMLEditor from "../../v2Components/HtmlEditor";
64
- import { HTML_EDITOR_VARIANTS } from "../../v2Components/HtmlEditor/constants";
64
+ import { HTML_EDITOR_VARIANTS, DEVICE_TYPES as HTML_DEVICE_TYPES } from "../../v2Components/HtmlEditor/constants";
65
65
  import { INAPP_EDITOR_TYPES } from "../InAppWrapper/constants";
66
66
  import InappAdvanced from "../InappAdvance/index";
67
67
  import { ErrorInfoNote } from "../../v2Components/ErrorInfoNote";
@@ -145,6 +145,7 @@ export const InApp = (props) => {
145
145
  // Refs to store latest content before layout changes
146
146
  const htmlContentAndroidRef = useRef(htmlContentAndroid);
147
147
  const htmlContentIosRef = useRef(htmlContentIos);
148
+ const htmlEditorRef = useRef(null);
148
149
  const [accountId, setAccountId] = useState("");
149
150
  const [accessToken, setAccessToken] = useState("");
150
151
  const [accountName, setAccountName] = useState("");
@@ -177,9 +178,19 @@ export const InApp = (props) => {
177
178
  // Transformation to payload structure happens in prepareTestMessagePayload
178
179
  // Reference: Based on getPreviewSection() function (lines 490-530) which prepares content for TemplatePreview
179
180
  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;
181
+ // For HTML template: prefer editor ref (source of truth) so library mode preview gets latest content
182
+ let androidMsg = templateMessageAndroid;
183
+ let iosMsg = templateMessageIos;
184
+ if (isHTMLTemplate) {
185
+ const getDeviceContentFromEditor = htmlEditorRef.current?.getDeviceContent;
186
+ if (typeof getDeviceContentFromEditor === 'function') {
187
+ androidMsg = getDeviceContentFromEditor(HTML_DEVICE_TYPES.ANDROID) ?? '';
188
+ iosMsg = getDeviceContentFromEditor(HTML_DEVICE_TYPES.IOS) ?? '';
189
+ } else {
190
+ androidMsg = htmlContentAndroidRef.current ?? htmlContentAndroid ?? '';
191
+ iosMsg = htmlContentIosRef.current ?? htmlContentIos ?? '';
192
+ }
193
+ }
183
194
 
184
195
  // Prepare Android content
185
196
  const androidMediaPreview = {};
@@ -1323,6 +1334,7 @@ export const InApp = (props) => {
1323
1334
  )}
1324
1335
  {shouldUseHTMLEditor ? (
1325
1336
  <HTMLEditor
1337
+ ref={htmlEditorRef}
1326
1338
  key={`inapp-html-editor-v${htmlEditorContentVersion}`}
1327
1339
  variant={HTML_EDITOR_VARIANTS.INAPP}
1328
1340
  layoutType={templateLayoutType}