saasufy-components 3.7.1 → 3.8.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 +51 -0
- package/input-combiner.js +54 -0
- package/package.json +2 -2
- package/utils.js +8 -3
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ Components for Saasufy
|
|
|
18
18
|
|
|
19
19
|
### User input
|
|
20
20
|
- [input-provider](#input-provider)
|
|
21
|
+
- [input-combiner](#input-combiner)
|
|
21
22
|
|
|
22
23
|
### Authentication
|
|
23
24
|
- [log-in-form](#log-in-form)
|
|
@@ -65,6 +66,7 @@ To use components, you just need to include them into your `.html` file inside y
|
|
|
65
66
|
<script src="https://saasufy.com/node_modules/saasufy-components/model-text.js" type="module" defer></script>
|
|
66
67
|
<script src="https://saasufy.com/node_modules/saasufy-components/model-viewer.js" type="module" defer></script>
|
|
67
68
|
<script src="https://saasufy.com/node_modules/saasufy-components/input-provider.js" type="module" defer></script>
|
|
69
|
+
<script src="https://saasufy.com/node_modules/saasufy-components/input-combiner.js" type="module" defer></script>
|
|
68
70
|
<script src="https://saasufy.com/node_modules/saasufy-components/log-in-form.js" type="module" defer></script>
|
|
69
71
|
<script src="https://saasufy.com/node_modules/saasufy-components/log-out.js" type="module" defer></script>
|
|
70
72
|
<script src="https://saasufy.com/node_modules/saasufy-components/oauth-link.js" type="module" defer></script>
|
|
@@ -524,6 +526,55 @@ This component can be configured to provide its data to multiple components (con
|
|
|
524
526
|
- `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.
|
|
525
527
|
- `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.
|
|
526
528
|
|
|
529
|
+
### input-combiner
|
|
530
|
+
|
|
531
|
+
A component which can be used to combine data from multiple `input-provider` components and pass the combined data to other components (or HTML elements) via custom attributes.
|
|
532
|
+
A common use case for it is to pass user input to `collection-browser` or `model-viewer` components to then fetch data from Saasufy.
|
|
533
|
+
This component can be configured to provide its data to multiple components (consumers) via custom attributes.
|
|
534
|
+
|
|
535
|
+
**Import**
|
|
536
|
+
|
|
537
|
+
```html
|
|
538
|
+
<script src="https://saasufy.com/node_modules/saasufy-components/input-combiner.js" type="module" defer></script>
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
**Example usage**
|
|
542
|
+
|
|
543
|
+
The following example shows how to bind multiple `input-provider` components to an `input-combiner`.
|
|
544
|
+
In this example, the `input-combiner` component forwards the combined, formatted values to the `collection-view-params` attribute of a `company-browser` component.
|
|
545
|
+
|
|
546
|
+
```html
|
|
547
|
+
<input-provider
|
|
548
|
+
class="desc-input"
|
|
549
|
+
type="text"
|
|
550
|
+
consumers=".search-combiner"
|
|
551
|
+
provider-template="desc:description contains (?i){{value}}"
|
|
552
|
+
value=""
|
|
553
|
+
placeholder="Description filter"
|
|
554
|
+
></input-provider>
|
|
555
|
+
|
|
556
|
+
<input-provider
|
|
557
|
+
class="city-input"
|
|
558
|
+
type="text"
|
|
559
|
+
consumers=".search-combiner"
|
|
560
|
+
provider-template="city:city contains (?i){{value}}"
|
|
561
|
+
value=""
|
|
562
|
+
placeholder="City filter"
|
|
563
|
+
></input-provider>
|
|
564
|
+
|
|
565
|
+
<input-combiner
|
|
566
|
+
class="search-combiner"
|
|
567
|
+
consumers=".company-browser:collection-view-params"
|
|
568
|
+
provider-template="query='{{combineFilters(value)}}'"
|
|
569
|
+
></input-combiner>
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
**Attributes**
|
|
573
|
+
|
|
574
|
+
- `consumers`: This allows you to connect this `input-combiner` to other elements on your page. It takes a list of selectors with optional attributes to target. 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.
|
|
575
|
+
- `provider-template`: A template string within which the `{{value}}` can be injected before passing to consumers. In the case of the `input-combiner`, the value is an object wherein each key represents the unique label associated with different `input-provider` components.
|
|
576
|
+
- `debounce-delay`: The delay in milliseconds to wait before triggering a change event. This is useful to batch multiple updates together. Default is 0ms.
|
|
577
|
+
|
|
527
578
|
### log-in-form
|
|
528
579
|
|
|
529
580
|
A form component which allows end-users to authenticate themselves into your app using the Saasufy blockchain or any Capitalisk-based blockchain.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { debouncer, updateConsumerElements } from './utils.js';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_DEBOUNCE_DELAY = 0;
|
|
4
|
+
|
|
5
|
+
class InputCombiner extends HTMLElement {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.isReady = false;
|
|
9
|
+
this.inputValues = {};
|
|
10
|
+
this.debounce = debouncer();
|
|
11
|
+
}
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
this.isReady = true;
|
|
14
|
+
this.render();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static get observedAttributes() {
|
|
18
|
+
return [
|
|
19
|
+
'consumers',
|
|
20
|
+
'debounce-delay',
|
|
21
|
+
'provider-template',
|
|
22
|
+
'value'
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
27
|
+
this.render();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
render() {
|
|
31
|
+
if (!this.hasAttribute('value')) return;
|
|
32
|
+
|
|
33
|
+
let value = this.getAttribute('value') || '';
|
|
34
|
+
let debounceDelay = this.getAttribute('debounce-delay');
|
|
35
|
+
debounceDelay = debounceDelay ? Number(debounceDelay) : DEFAULT_DEBOUNCE_DELAY;
|
|
36
|
+
|
|
37
|
+
let valueParts = value.match(/^(?:([^:]*)[:])?(.*)$/);
|
|
38
|
+
let valueUpdater = valueParts[1] || '_root';
|
|
39
|
+
let rawValue = valueParts[2];
|
|
40
|
+
this.inputValues[valueUpdater] = rawValue;
|
|
41
|
+
|
|
42
|
+
if (!this.isReady) return;
|
|
43
|
+
|
|
44
|
+
let consumers = this.getAttribute('consumers');
|
|
45
|
+
if (!consumers) return;
|
|
46
|
+
|
|
47
|
+
this.debounce(async () => {
|
|
48
|
+
let providerTemplate = this.getAttribute('provider-template') || '{{value._root}}';
|
|
49
|
+
updateConsumerElements(consumers, { ...this.inputValues }, providerTemplate);
|
|
50
|
+
}, debounceDelay);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
window.customElements.define('input-combiner', InputCombiner);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saasufy-components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "Components for Saasufy.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"author": "Jonathan Gros-Dubois",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"ag-collection": "^5.0.
|
|
20
|
+
"ag-collection": "^5.0.2",
|
|
21
21
|
"ag-model": "^3.0.1",
|
|
22
22
|
"capitalisk-auth-client": "^1.5.1",
|
|
23
23
|
"socketcluster-client": "^19.1.0"
|
package/utils.js
CHANGED
|
@@ -193,9 +193,6 @@ let templateFormatters = {
|
|
|
193
193
|
fallback: (...args) => {
|
|
194
194
|
return args.filter(arg => arg)[0];
|
|
195
195
|
},
|
|
196
|
-
joinFields: (list, field, sep) => {
|
|
197
|
-
return list.map(item => item[field]).join(sep);
|
|
198
|
-
},
|
|
199
196
|
date: (timestamp) => {
|
|
200
197
|
let date = new Date(timestamp);
|
|
201
198
|
let year = date.getFullYear();
|
|
@@ -204,6 +201,12 @@ let templateFormatters = {
|
|
|
204
201
|
let hour = date.getHours();
|
|
205
202
|
let minutes = date.getMinutes();
|
|
206
203
|
return `${month} ${day}, ${year} at ${hour}:${minutes.toString().padStart(2, '0')}`;
|
|
204
|
+
},
|
|
205
|
+
joinFields: (list, field, sep) => {
|
|
206
|
+
return list.map(item => item[field]).join(sep);
|
|
207
|
+
},
|
|
208
|
+
combineFilters: (filterMap, useOr) => {
|
|
209
|
+
return Object.values(filterMap || {}).join(useOr ? ' %OR% ' : ' %AND% ');
|
|
207
210
|
}
|
|
208
211
|
};
|
|
209
212
|
|
|
@@ -293,6 +296,8 @@ export function updateConsumerElements(consumers, value, template) {
|
|
|
293
296
|
}
|
|
294
297
|
} else if (element.nodeName === 'MODEL-INPUT') {
|
|
295
298
|
element.value = value;
|
|
299
|
+
} else if (element.nodeName === 'INPUT-COMBINER') {
|
|
300
|
+
element.setAttribute('value', value);
|
|
296
301
|
} else {
|
|
297
302
|
element.innerHTML = value;
|
|
298
303
|
}
|