saasufy-components 6.2.0 → 7.0.0

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils.js +58 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "6.2.0",
3
+ "version": "7.0.0",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils.js CHANGED
@@ -8,11 +8,12 @@ const DEFAULT_RELOAD_DELAY = 0;
8
8
 
9
9
  export function toSafeHTML(text) {
10
10
  if (typeof text === 'string') {
11
- return text.replace(/&/g, '&')
12
- .replace(/</g, '&lt;')
11
+ return text.replace(/</g, '&lt;')
13
12
  .replace(/>/g, '&gt;')
14
13
  .replace(/"/g, '&quot;')
15
14
  .replace(/'/g, '&#039;')
15
+ .replace(/\{/g, '&#123;')
16
+ .replace(/\}/g, '&#125;')
16
17
  .replace(/\n/g, '<br />');
17
18
  } else if (text != null && typeof text.toString !== 'function') {
18
19
  return '[invalid]';
@@ -266,34 +267,72 @@ function getRenderOptions(data, socket) {
266
267
  };
267
268
  }
268
269
 
270
+ function* selectExpressions(string) {
271
+ let charList = string.split('');
272
+ let isCapturing = false;
273
+ let isTripleBracket = false;
274
+ let captureList = [];
275
+ for (let i = 1; i < charList.length; i++) {
276
+ if (charList[i - 1] === '{' && charList[i] === '{') {
277
+ captureList = [];
278
+ captureList.push('{');
279
+ isCapturing = true;
280
+ isTripleBracket = charList[i - 2] === '{';
281
+ if (isTripleBracket) {
282
+ captureList.push('{');
283
+ }
284
+ }
285
+ if (isCapturing) {
286
+ captureList.push(charList[i]);
287
+ } else if (captureList.length) {
288
+ captureList.push('}');
289
+ captureList.push('}');
290
+ if (isTripleBracket) {
291
+ captureList.push('}');
292
+ }
293
+ yield captureList.join('');
294
+ captureList = [];
295
+ }
296
+ if (
297
+ charList[i + 1] === '}' && charList[i + 2] === '}' &&
298
+ (!isTripleBracket || charList[i + 3] === '}')
299
+ ) {
300
+ isCapturing = false;
301
+ }
302
+ }
303
+ }
304
+
269
305
  export function renderTemplate(templateString, data, socket) {
270
- return templateString
271
- .replace(templateTripleTagsRegExp, (match) => {
272
- let expString = match.slice(3, -3);
273
- let options = getRenderOptions(data, socket);
306
+ let expressionIterator = selectExpressions(templateString);
307
+ let options = getRenderOptions(data, socket);
308
+ for (let expression of expressionIterator) {
309
+ let computedValue;
310
+ if (expression.match(templateTripleTagsRegExp)) {
311
+ let expString = expression.slice(3, -3);
274
312
  try {
275
- return execExpression(
313
+ computedValue = execExpression(
276
314
  toExpression(expString),
277
315
  options
278
316
  );
279
317
  } catch (error) {
280
- return match;
318
+ computedValue = expression;
281
319
  }
282
- })
283
- .replace(templateTagsRegExp, (match) => {
284
- let expString = match.slice(2, -2);
285
- let options = getRenderOptions(data, socket);
320
+ } else {
321
+ let expString = expression.slice(2, -2);
286
322
  try {
287
- return toSafeHTML(
323
+ computedValue = toSafeHTML(
288
324
  execExpression(
289
325
  toExpression(expString),
290
326
  options
291
327
  )
292
328
  );
293
329
  } catch (error) {
294
- return match;
330
+ computedValue = expression;
295
331
  }
296
- });
332
+ }
333
+ templateString = templateString.replace(expression, computedValue);
334
+ }
335
+ return templateString;
297
336
  }
298
337
 
299
338
  export function updateConsumerElements(consumers, value, template, sourceElementName, outputType) {
@@ -344,7 +383,10 @@ export function updateConsumerElements(consumers, value, template, sourceElement
344
383
  }
345
384
  } else if (element.nodeName === 'MODEL-INPUT') {
346
385
  element.value = value;
347
- } else if (element.nodeName === 'INPUT-TRANSFORMER') {
386
+ } else if (
387
+ element.nodeName === 'INPUT-TRANSFORMER' ||
388
+ element.nodeName === 'INPUT-PROVIDER'
389
+ ) {
348
390
  element.setAttribute('value', value);
349
391
  } else if (element.nodeName === 'INPUT-COMBINER') {
350
392
  element.setAttribute(