@pushwoosh/dumb-components 1.1.12 → 1.1.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.
@@ -1,6 +1,6 @@
1
1
  import { Liquid } from 'liquidjs';
2
2
  import React, { useMemo, useState } from 'react';
3
- import { replacePlaceholders } from './helpers';
3
+ import { replaceLocalization, replacePlaceholders } from './helpers';
4
4
  import { IframeStyled } from './styles';
5
5
  const createLiquidInstance = () => {
6
6
  const liquidInstance = new Liquid();
@@ -29,11 +29,9 @@ export function EmailTemplatePreview(props) {
29
29
  const [liquidInstance] = useState(createLiquidInstance);
30
30
  const src = useMemo(() => {
31
31
  try {
32
- const realValues = {
33
- ...localization,
34
- ...values
35
- };
36
- return liquidInstance.parseAndRenderSync(replacePlaceholders(template, realValues), realValues);
32
+ const withLocalization = replaceLocalization(template, localization);
33
+ const withDynamicContent = replacePlaceholders(withLocalization, values);
34
+ return liquidInstance.parseAndRenderSync(withDynamicContent, values);
37
35
  } catch (e) {
38
36
  console.error('Error in PreviewIframe', e);
39
37
  return `<body style="font-size: 24px; color: darkred">${e.message}</body>`;
@@ -1 +1,2 @@
1
+ export declare function replaceLocalization(str: string, values: Record<string, string>): string;
1
2
  export declare function replacePlaceholders(str: string, values: Record<string, string>): string;
@@ -1,5 +1,13 @@
1
+ export function replaceLocalization(str, values) {
2
+ const re = /{{([0-9A-Za-z_ \-.[\]]+)\|(text|html|color)\|([^}]*)?}}/g;
3
+ return str.replace(re, (_, key, _type, defaultValue) => {
4
+ return (key in values ? values[key] : defaultValue) || '';
5
+ });
6
+ }
1
7
  export function replacePlaceholders(str, values) {
2
- return str.replace(/\{([^|}]+)\|([^|}]+)(?:\|([^}]*))?}/g, (_, varName, _modifier, defaultValue) => {
3
- return (varName in values ? values[varName] : defaultValue) || '';
8
+ const allAvailableModifiers = ['CapitalizeFirst', 'CapitalizeAllFirst', 'UPPERCASE', 'lowercase', 'regular', 'cent', 'dollar', 'comma', 'euro', 'jpy', 'lira', 'M-d-y', 'm-d-y', 'M d y', 'M d Y', 'l', 'M d', 'H:i', 'm-d-y H:i'];
9
+ const re = new RegExp(`{([0-9A-Za-z_ \\-]{1,64})\\|(${allAvailableModifiers.join('|')})(?:\\|([^}]*))?}`, 'g');
10
+ return str.replace(re, (_, key, _modifier, defaultValue) => {
11
+ return (key in values ? values[key] : defaultValue) || '';
4
12
  });
5
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pushwoosh/dumb-components",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "description": "React components to build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",