@capillarytech/creatives-library 8.0.15 → 8.0.18

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.15",
4
+ "version": "8.0.18",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -253,5 +253,25 @@ export const preprocessHtml = (content) => {
253
253
  "\n": "", // Handling newlines by replacing them with an empty string
254
254
  };
255
255
 
256
- return content?.replace(/'|"|&|<|>|"|\n/g, match => replacements[match]);
256
+
257
+ const styleTagRegex = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
258
+
259
+ const contentWithStyleFixes = content?.replace(styleTagRegex, (match, styleContent) => {
260
+ // Replace all occurrences of %} with % } within the style content
261
+ const modifiedStyleContent = styleContent?.replace(/%}/g, '% }');
262
+ // Reconstruct the <style> tag with the modified content
263
+ return match.replace(styleContent, modifiedStyleContent);
264
+ });
265
+
266
+ // Step 2: Perform the standard replacements on the entire content
267
+ return contentWithStyleFixes?.replace(/&#39;|&quot;|&amp;|&lt;|&gt;|"|\n/g, match => replacements[match]);
268
+ };
269
+
270
+ //this is used to get the subtags from custom or extended tags
271
+ export const getTagMapValue = (object = {}) => {
272
+ return Object.values(
273
+ object
274
+ ).reduce((acc, current) => {
275
+ return { ...acc?.subtags ?? {}, ...current?.subtags ?? {} };
276
+ }, {});
257
277
  };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import '@testing-library/jest-dom';
3
- import { checkSupport, extractNames, preprocessHtml, validateIfTagClosed,validateTags} from '../tagValidations';
3
+ import { checkSupport, extractNames, getTagMapValue, preprocessHtml, validateIfTagClosed,validateTags} from '../tagValidations';
4
4
 
5
5
  describe("check if curly brackets are balanced", () => {
6
6
  it("test for balanced curly brackets", () => {
@@ -415,5 +415,32 @@ describe('preprocessHtml', () => {
415
415
  const expectedOutput = "This is &amplt; not an entity.";
416
416
  expect(preprocessHtml(input)).toEqual(expectedOutput);
417
417
  });
418
+ it('Should handle style tags with %}', () => {
419
+ const input = "<style {line-height:0;font-size:75%} >sup{line-height:0;font-size:75%}</style> ";
420
+ const expectedOutput = "<style {line-height:0;font-size:75%} >sup{line-height:0;font-size:75% }</style> ";
421
+ expect(preprocessHtml(input)).toEqual(expectedOutput);
422
+ });
423
+
424
+
425
+ });
426
+
418
427
 
428
+ describe("getTagMapValue", () => {
429
+ it("should return an empty object when no object is provided", () => {
430
+ const result = getTagMapValue();
431
+ expect(result).toEqual({});
432
+ });
433
+
434
+ it("should return the tag map value when an object is provided", () => {
435
+ const object = {
436
+ "key 1": {
437
+ name: "23",
438
+ subtags: {
439
+ name: "233",
440
+ },
441
+ },
442
+ };
443
+ const result = getTagMapValue(object);
444
+ expect(result).toEqual({ name: "233" });
445
+ });
419
446
  });
@@ -19,8 +19,9 @@ import './style.scss';
19
19
  const loadScript = require('load-script');
20
20
 
21
21
  const defaultScriptUrl = `${window.location.origin}/arya/ui/library/ckeditor/ckeditor.js`;
22
- // const defaultScriptUrl = 'https://crm-nightly-new.cc.capillarytech.com/arya/ui/library/ckeditor/ckeditor.js';
23
- //Uncomment the above line to use CKEDITOR in local
22
+ //const defaultScriptUrl = 'https://nightly.intouch.capillarytech.com/arya/ui/library/ckeditor/ckeditor.js';
23
+ /*Uncomment the above line to use CKEDITOR in local
24
+ */
24
25
  const user = localStorage.getItem('user');
25
26
  let locale = 'en';
26
27
  if (user && JSON.parse(user).lang) {
@@ -1062,6 +1062,26 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
1062
1062
  continueSaveForm = (id) => {
1063
1063
 
1064
1064
  };
1065
+ handleLiquidTemplateSubmit =(templateContent) => {
1066
+ if(templateContent){this.setState((prevState) => {
1067
+ return {
1068
+ formData: {
1069
+ ...prevState?.formData,
1070
+ base: {
1071
+ ...prevState?.formData?.base,
1072
+ en: {
1073
+ ...prevState?.formData?.base?.en,
1074
+ "template-content": preprocessHtml(templateContent)
1075
+ }
1076
+ }
1077
+ }
1078
+ };
1079
+ }, () => {
1080
+ if (this.props.onSubmit) {
1081
+ this.props.onSubmit(this.state.formData);
1082
+ }
1083
+ });}
1084
+ }
1065
1085
  saveForm(saveForm) {
1066
1086
  if (this.props.isNewVersionFlow && !saveForm) {
1067
1087
  this.props.getValidationData();
@@ -1069,9 +1089,10 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
1069
1089
  }
1070
1090
  if ( this.state.isFormValid ) {
1071
1091
  if (this.liquidFlow) {
1092
+ const templateContent = this.state.formData?.base?.en?.["template-content"] || "";
1072
1093
  //Converts given HTML content to plain text string.
1073
1094
  const content = convert(
1074
- this.state.formData?.base?.en?.["template-content"]
1095
+ templateContent
1075
1096
  );
1076
1097
  /*
1077
1098
  The `handleResult` function is used as a callback for `getLiquidTags` to handle the results post-processing.
@@ -1124,7 +1145,7 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
1124
1145
  this.props.stopValidation();
1125
1146
  return;
1126
1147
  }
1127
- this.props.onSubmit(this.state.formData);
1148
+ this.handleLiquidTemplateSubmit(templateContent);
1128
1149
  }
1129
1150
  };
1130
1151
  this.props.actions.getLiquidTags(preprocessHtml(content), handleResult);
@@ -51,7 +51,7 @@ export const expectedStateGetLiquidTagsRequest = {
51
51
  messages: [],
52
52
  metaEntities: {
53
53
  layouts: undefined,
54
- tagLookupMap: { undefined: "32" },
54
+ tagLookupMap: { undefined: {definition: {}} },
55
55
  tags: { standard: { random: "32" } }
56
56
  },
57
57
  orgID: "",
@@ -7,6 +7,7 @@ import * as types from './constants';
7
7
  import initialState from '../../initialState';
8
8
  import { FAILURE } from '../App/constants';
9
9
  import { TAG } from '../Whatsapp/constants';
10
+ import { getTagMapValue } from '../../utils/tagValidations';
10
11
 
11
12
  function capReducer(state = fromJS(initialState.cap), action) {
12
13
  switch (action.type) {
@@ -96,14 +97,34 @@ function capReducer(state = fromJS(initialState.cap), action) {
96
97
  return state
97
98
  .set('fetchingLiquidTags', false)
98
99
  case types.GET_SCHEMA_FOR_ENTITY_SUCCESS: {
99
- const stateMeta = state.get('metaEntities');
100
- const standardTagMap = _.keyBy(action?.data?.metaEntities?.standard, item => item?.definition?.value);
100
+ //Process standard tags
101
+ const standardTagMapInitial = _.keyBy(
102
+ action?.data?.metaEntities?.standard,
103
+ item => item?.definition?.value
104
+ );
105
+ // Mapping only the `definition` object instead of the entire item, to reduce space used
106
+ const standardTagMap = _.mapValues(standardTagMapInitial, item => ({
107
+ definition: item?.definition ?? {},
108
+ }));
109
+
110
+ // Process custom tags
111
+ const customSubtags = getTagMapValue(action?.data?.metaEntities?.custom)
112
+ // Process extended tags
113
+ const extendedSubtags = getTagMapValue(action?.data?.metaEntities?.extended);
114
+
115
+ // Combine all maps
116
+ const combinedTagMap = {
117
+ ...standardTagMap,
118
+ ...customSubtags,
119
+ ...extendedSubtags
120
+ };
121
+ const stateMeta = state.get("metaEntities");
101
122
  return state
102
123
  .set('fetchingSchema', false)
103
124
  .set('metaEntities', {
104
125
  layouts: action.data && action.entityType === 'LAYOUT' ? action.data.metaEntities : stateMeta.layouts,
105
126
  tags: action.data && action.entityType === 'TAG' ? action.data.metaEntities : stateMeta.tags,
106
- tagLookupMap: action?.data && action?.entityType === TAG ? standardTagMap : stateMeta?.tagLookupMap,
127
+ tagLookupMap: action?.data && action?.entityType === TAG ? combinedTagMap : stateMeta?.tagLookupMap,
107
128
  })
108
129
  .set('fetchingSchemaError', false);
109
130
  }