saasufy-components 6.2.0 → 7.0.1

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