saasufy-components 3.28.0 → 3.30.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 -0
- package/input-transformer.js +3 -1
- package/package.json +1 -1
- package/utils.js +12 -9
package/README.md
CHANGED
|
@@ -710,6 +710,7 @@ The following example shows how to bind an `input-provider` component to an `inp
|
|
|
710
710
|
|
|
711
711
|
- `consumers`: This allows you to connect this `input-transformer` to other elements on your page. It takes a list of selectors with optional attributes to target in the format `element-selector:attribute-name`. For example `.my-input:value` will find all elements with a `my-input` class and update their `value` attributes with the value of the `input-provider` component in real-time. You can specify multiple selectors separated by commas such as `.my-input,my-div`; in this case, because attribute names are not specified, values will be injected into the `value` attribute (for input elements) or into the `innerHTML` property (for other kinds of elements). The default attribute/property depends on the element type.
|
|
712
712
|
- `provider-template`: A template string within which the `{{value}}` can be injected before passing to consumers.
|
|
713
|
+
- `output-type`: The default output type is `string`. This property can be used to convert the output to either `boolean` or `number`.
|
|
713
714
|
- `debounce-delay`: The delay in milliseconds to wait before triggering a change event. This is useful to batch multiple updates together. Default is 0ms.
|
|
714
715
|
|
|
715
716
|
### log-in-form
|
package/input-transformer.js
CHANGED
|
@@ -18,6 +18,7 @@ class InputTransformer extends HTMLElement {
|
|
|
18
18
|
'consumers',
|
|
19
19
|
'debounce-delay',
|
|
20
20
|
'provider-template',
|
|
21
|
+
'output-type',
|
|
21
22
|
'value'
|
|
22
23
|
];
|
|
23
24
|
}
|
|
@@ -30,6 +31,7 @@ class InputTransformer extends HTMLElement {
|
|
|
30
31
|
if (!this.hasAttribute('value')) return;
|
|
31
32
|
|
|
32
33
|
let value = this.getAttribute('value') || '';
|
|
34
|
+
let outputType = this.getAttribute('output-type');
|
|
33
35
|
let debounceDelay = this.getAttribute('debounce-delay');
|
|
34
36
|
debounceDelay = debounceDelay ? Number(debounceDelay) : DEFAULT_DEBOUNCE_DELAY;
|
|
35
37
|
|
|
@@ -40,7 +42,7 @@ class InputTransformer extends HTMLElement {
|
|
|
40
42
|
|
|
41
43
|
this.debounce(async () => {
|
|
42
44
|
let providerTemplate = this.getAttribute('provider-template') || '{{value}}';
|
|
43
|
-
updateConsumerElements(consumers, value, providerTemplate);
|
|
45
|
+
updateConsumerElements(consumers, value, providerTemplate, null, outputType);
|
|
44
46
|
}, debounceDelay);
|
|
45
47
|
}
|
|
46
48
|
}
|
package/package.json
CHANGED
package/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import AGCollection from '/node_modules/ag-collection/ag-collection.js';
|
|
2
2
|
import AGModel from '/node_modules/ag-model/ag-model.js';
|
|
3
|
-
|
|
3
|
+
export * as uuid from '/node_modules/uuid/dist/esm-browser/index.js';
|
|
4
4
|
import { sha256 } from './sha256.js';
|
|
5
5
|
|
|
6
6
|
const DEFAULT_DEBOUNCE_DELAY = 300;
|
|
@@ -183,7 +183,7 @@ export function createModel(modelOptions) {
|
|
|
183
183
|
return model;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
function computeId(...parts) {
|
|
186
|
+
export function computeId(...parts) {
|
|
187
187
|
let encoder = new TextEncoder();
|
|
188
188
|
let data = encoder.encode(parts.join('-'));
|
|
189
189
|
let start = Date.now();
|
|
@@ -233,7 +233,7 @@ let templateFormatters = {
|
|
|
233
233
|
computeId
|
|
234
234
|
};
|
|
235
235
|
|
|
236
|
-
let
|
|
236
|
+
let templateTripleTagsRegExp = /{{{.*?}}}/gs;
|
|
237
237
|
let templateTagsRegExp = /{{.*?}}/gs;
|
|
238
238
|
|
|
239
239
|
function execExpression(expression, options) {
|
|
@@ -264,7 +264,7 @@ function getRenderOptions(data, socket) {
|
|
|
264
264
|
|
|
265
265
|
export function renderTemplate(templateString, data, socket) {
|
|
266
266
|
return templateString
|
|
267
|
-
.replace(
|
|
267
|
+
.replace(templateTripleTagsRegExp, (match) => {
|
|
268
268
|
let expString = match.slice(3, -3);
|
|
269
269
|
let options = getRenderOptions(data, socket);
|
|
270
270
|
try {
|
|
@@ -292,7 +292,7 @@ export function renderTemplate(templateString, data, socket) {
|
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
export function updateConsumerElements(consumers, value, template, sourceElementName) {
|
|
295
|
+
export function updateConsumerElements(consumers, value, template, sourceElementName, outputType) {
|
|
296
296
|
if (consumers) {
|
|
297
297
|
let consumerParts = consumers.split(',')
|
|
298
298
|
.filter(part => part)
|
|
@@ -303,10 +303,13 @@ export function updateConsumerElements(consumers, value, template, sourceElement
|
|
|
303
303
|
.filter(([ selector, attributeName ]) => selector);
|
|
304
304
|
|
|
305
305
|
if (template) {
|
|
306
|
-
value = renderTemplate(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
306
|
+
value = renderTemplate(template, { value });
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
if (outputType === 'boolean') {
|
|
310
|
+
value = value !== 'false' && value !== '';
|
|
311
|
+
} else if (outputType === 'number') {
|
|
312
|
+
value = Number(value);
|
|
310
313
|
}
|
|
311
314
|
|
|
312
315
|
for (let [ selector, attributeName ] of consumerParts) {
|