saasufy-components 7.10.0 → 7.12.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.
package/README.md CHANGED
@@ -696,7 +696,7 @@ This component can be configured to provide its data to multiple components (con
696
696
  - `autocapitalize`: Can be `on` or `off` - It will set the auto-capitalize attribute on the inner input element. This is useful for mobile devices to enable or disable auto-capitalization of the first character which is typed into the input element.
697
697
  - `autocorrect`: Can be `on` or `off` - It will set the auto-correct attribute on the inner input element. This is useful for mobile devices to enable or disable auto-correct.
698
698
  - `input-props`: Can be used to set additional attributes on the inner `input` element. Must be in the format `attr1=value1,attr2=value2`.
699
- - `skip-init-change`: This attribute can be used to prevent an `input-provider` of type `select` from triggering a change when initialized with a default option. By default, the `input-provider` will trigger a change when initialized with a default value.
699
+ - `skip-init-change`: This attribute can be used to prevent an `input-provider` from triggering a change when initialized with a default value. By default, the `input-provider` will trigger a change when initialized with a default value.
700
700
  - `force-init-change`: This attribute can be used to force an `input-provider` to always trigger a change when initialized, even if the value is empty.
701
701
 
702
702
  ### input-combiner
package/input-provider.js CHANGED
@@ -74,6 +74,8 @@ class InputProvider extends HTMLElement {
74
74
  if (forceInitChange) {
75
75
  delete this.forceTriggerChange;
76
76
  }
77
+ let skipInitChange = this.skipInitChange && !forceInitChange;
78
+ delete this.skipInitChange;
77
79
  if (newValue && this.hasAttribute('computable-value')) {
78
80
  newValue = renderTemplate(newValue, null, null, true);
79
81
  }
@@ -86,14 +88,14 @@ class InputProvider extends HTMLElement {
86
88
  } else {
87
89
  this.inputElement.checked = newValue;
88
90
  }
89
- if (oldValue !== newValue || forceInitChange) {
91
+ if ((oldValue !== newValue || forceInitChange) && !skipInitChange) {
90
92
  this.triggerChange();
91
93
  }
92
94
  return;
93
95
  }
94
96
  oldValue = this.inputElement.value;
95
97
  this.inputElement.value = newValue;
96
- if (oldValue !== newValue || forceInitChange) {
98
+ if ((oldValue !== newValue || forceInitChange) && !skipInitChange) {
97
99
  this.triggerChange();
98
100
  }
99
101
  }
@@ -197,7 +199,9 @@ class InputProvider extends HTMLElement {
197
199
  this.forceTriggerChange = true;
198
200
  this.value = value;
199
201
  } else if (value) {
200
- if (type === 'select' && !this.hasAttribute('skip-init-change')) {
202
+ if (this.hasAttribute('skip-init-change')) {
203
+ this.skipInitChange = true;
204
+ } else if (type === 'select') {
201
205
  this.forceTriggerChange = true;
202
206
  }
203
207
  this.value = value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "7.10.0",
3
+ "version": "7.12.0",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils.js CHANGED
@@ -5,9 +5,23 @@ import { sha256 } from './sha256.js';
5
5
 
6
6
  const DEFAULT_DEBOUNCE_DELAY = 300;
7
7
  const DEFAULT_RELOAD_DELAY = 0;
8
+
9
+ let expressionCharsRegExp = /\$\{(.*?)\}/g;
10
+ let backtickRegExp = /`/g;
11
+ let templateMultiStartBracesRegExp = /{{{*/g
12
+ let templateMultiEndBracesRegExp = /}}}*/g
13
+
14
+ export function toSafeString(value) {
15
+ return value.replace(expressionCharsRegExp, '$!{$1}')
16
+ .replace(backtickRegExp, `'`)
17
+ .replace(templateMultiStartBracesRegExp, '[[')
18
+ .replace(templateMultiEndBracesRegExp, ']]');
19
+ }
20
+
8
21
  export function toSafeHTML(value) {
9
22
  if (typeof value === 'string') {
10
- return value.replace(/&(?!(amp|lt|gt|quot|#039|#123|#125);)/g, '&')
23
+ return toSafeString(value)
24
+ .replace(/&(?!(amp|lt|gt|quot|#039|#123|#125);)/g, '&')
11
25
  .replace(/<(?!br ?\/?>)/g, '&lt;')
12
26
  .replace(/(?<!br ?\/?)>/g, '&gt;')
13
27
  .replace(/"/g, '&quot;')
@@ -296,9 +310,6 @@ function replaceExpressions(string, replaceFn) {
296
310
  return charList.join('');
297
311
  }
298
312
 
299
- let templateMultiStartBracesRegExp = /{{{*/g
300
- let templateMultiEndBracesRegExp = /}}}*/g
301
-
302
313
  export function renderTemplate(templateString, data, socket, autoExecFunction) {
303
314
  let options = getRenderOptions(data, socket);
304
315
  return replaceExpressions(templateString, (expression) => {
@@ -333,15 +344,6 @@ export function renderTemplate(templateString, data, socket, autoExecFunction) {
333
344
  }
334
345
  result = result();
335
346
  }
336
- if (typeof result === 'string') {
337
- // Double braces cannot contain sub-expressions as it
338
- // would present an XSS vulnerability.
339
- // Replace them with square braces so that any code inside
340
- // will not be executed if output is re-processed later.
341
- result = result
342
- .replace(templateMultiStartBracesRegExp, '[[')
343
- .replace(templateMultiEndBracesRegExp, ']]');
344
- }
345
347
  return toSafeHTML(result);
346
348
  } catch (error) {
347
349
  return expression;