saasufy-components 7.9.2 → 7.11.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 +1 -1
- package/input-provider.js +8 -4
- package/model-input.js +1 -1
- package/package.json +1 -1
- package/utils.js +39 -19
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`
|
|
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,8 +74,10 @@ 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
|
-
newValue = renderTemplate(newValue);
|
|
80
|
+
newValue = renderTemplate(newValue, null, null, true);
|
|
79
81
|
}
|
|
80
82
|
this.updateInputClassList(newValue);
|
|
81
83
|
let oldValue;
|
|
@@ -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 (
|
|
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/model-input.js
CHANGED
|
@@ -71,7 +71,7 @@ class ModelInput extends SocketConsumer {
|
|
|
71
71
|
set value(newValue) {
|
|
72
72
|
if (this.inputElement) {
|
|
73
73
|
if (newValue && this.hasAttribute('computable-value')) {
|
|
74
|
-
newValue = renderTemplate(newValue);
|
|
74
|
+
newValue = renderTemplate(newValue, null, null, true);
|
|
75
75
|
}
|
|
76
76
|
let oldValue;
|
|
77
77
|
if (this.inputElement.type === 'checkbox') {
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -5,10 +5,9 @@ import { sha256 } from './sha256.js';
|
|
|
5
5
|
|
|
6
6
|
const DEFAULT_DEBOUNCE_DELAY = 300;
|
|
7
7
|
const DEFAULT_RELOAD_DELAY = 0;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return text.replace(/&(?!(amp|lt|gt|quot|#039|#123|#125);)/g, '&')
|
|
8
|
+
export function toSafeHTML(value) {
|
|
9
|
+
if (typeof value === 'string') {
|
|
10
|
+
return value.replace(/&(?!(amp|lt|gt|quot|#039|#123|#125);)/g, '&')
|
|
12
11
|
.replace(/<(?!br ?\/?>)/g, '<')
|
|
13
12
|
.replace(/(?<!br ?\/?)>/g, '>')
|
|
14
13
|
.replace(/"/g, '"')
|
|
@@ -16,14 +15,14 @@ export function toSafeHTML(text) {
|
|
|
16
15
|
.replace(/\{/g, '{')
|
|
17
16
|
.replace(/\}/g, '}')
|
|
18
17
|
.replace(/\n/g, '<br>');
|
|
19
|
-
} else if (
|
|
18
|
+
} else if (value != null && typeof value.toString !== 'function') {
|
|
20
19
|
return '[invalid]';
|
|
21
20
|
}
|
|
22
|
-
return
|
|
21
|
+
return value;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
export function toExpression(
|
|
26
|
-
return
|
|
24
|
+
export function toExpression(value) {
|
|
25
|
+
return value.replace(/&/g, '&')
|
|
27
26
|
.replace(/</g, '<')
|
|
28
27
|
.replace(/>/g, '>');
|
|
29
28
|
}
|
|
@@ -216,9 +215,6 @@ let templateFormatters = {
|
|
|
216
215
|
safeString: toSafeHTML
|
|
217
216
|
};
|
|
218
217
|
|
|
219
|
-
let templateTripleTagsRegExp = /{{{.*?}}}/gs;
|
|
220
|
-
let templateTagsRegExp = /{{.*?}}/gs;
|
|
221
|
-
|
|
222
218
|
function execExpression(expression, options) {
|
|
223
219
|
let keys = Object.keys(options);
|
|
224
220
|
let args = [
|
|
@@ -300,29 +296,53 @@ function replaceExpressions(string, replaceFn) {
|
|
|
300
296
|
return charList.join('');
|
|
301
297
|
}
|
|
302
298
|
|
|
303
|
-
|
|
299
|
+
let templateMultiStartBracesRegExp = /{{{*/g
|
|
300
|
+
let templateMultiEndBracesRegExp = /}}}*/g
|
|
301
|
+
|
|
302
|
+
export function renderTemplate(templateString, data, socket, autoExecFunction) {
|
|
304
303
|
let options = getRenderOptions(data, socket);
|
|
305
304
|
return replaceExpressions(templateString, (expression) => {
|
|
306
305
|
let expString;
|
|
307
306
|
if (expression.startsWith('{{{') && expression.endsWith('}}}')) {
|
|
308
307
|
expString = expression.slice(3, -3);
|
|
309
308
|
try {
|
|
310
|
-
|
|
309
|
+
let result = execExpression(
|
|
311
310
|
toExpression(expString),
|
|
312
311
|
options
|
|
313
312
|
);
|
|
313
|
+
if (typeof result === 'function') {
|
|
314
|
+
if (!autoExecFunction) {
|
|
315
|
+
return expression;
|
|
316
|
+
}
|
|
317
|
+
result = result();
|
|
318
|
+
}
|
|
319
|
+
return result;
|
|
314
320
|
} catch (error) {
|
|
315
321
|
return expression;
|
|
316
322
|
}
|
|
317
323
|
}
|
|
318
324
|
expString = expression.slice(2, -2);
|
|
319
325
|
try {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
options
|
|
324
|
-
)
|
|
326
|
+
let result = execExpression(
|
|
327
|
+
toExpression(expString),
|
|
328
|
+
options
|
|
325
329
|
);
|
|
330
|
+
if (typeof result === 'function') {
|
|
331
|
+
if (!autoExecFunction) {
|
|
332
|
+
return expression;
|
|
333
|
+
}
|
|
334
|
+
result = result();
|
|
335
|
+
}
|
|
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
|
+
return toSafeHTML(result);
|
|
326
346
|
} catch (error) {
|
|
327
347
|
return expression;
|
|
328
348
|
}
|
|
@@ -340,7 +360,7 @@ export function updateConsumerElements(consumers, value, template, sourceElement
|
|
|
340
360
|
.filter(([ selector, attributeName ]) => selector);
|
|
341
361
|
|
|
342
362
|
if (template) {
|
|
343
|
-
value = renderTemplate(template, { value });
|
|
363
|
+
value = renderTemplate(template, { value }, null, true);
|
|
344
364
|
}
|
|
345
365
|
|
|
346
366
|
if (outputType === 'boolean') {
|