saasufy-components 3.15.2 → 3.16.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
@@ -19,6 +19,7 @@ Components for Saasufy
19
19
  ### User input
20
20
  - [input-provider](#input-provider)
21
21
  - [input-combiner](#input-combiner)
22
+ - [input-transformer](#input-transformer)
22
23
 
23
24
  ### Authentication
24
25
  - [log-in-form](#log-in-form)
@@ -67,6 +68,7 @@ To use components, you just need to include them into your `.html` file inside y
67
68
  <script src="https://saasufy.com/node_modules/saasufy-components/model-viewer.js" type="module" defer></script>
68
69
  <script src="https://saasufy.com/node_modules/saasufy-components/input-provider.js" type="module" defer></script>
69
70
  <script src="https://saasufy.com/node_modules/saasufy-components/input-combiner.js" type="module" defer></script>
71
+ <script src="https://saasufy.com/node_modules/saasufy-components/input-transformer.js" type="module" defer></script>
70
72
  <script src="https://saasufy.com/node_modules/saasufy-components/log-in-form.js" type="module" defer></script>
71
73
  <script src="https://saasufy.com/node_modules/saasufy-components/log-out.js" type="module" defer></script>
72
74
  <script src="https://saasufy.com/node_modules/saasufy-components/oauth-link.js" type="module" defer></script>
@@ -609,6 +611,46 @@ The `combineFilters` function produces a combined query string (joined with `%AN
609
611
  - `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.
610
612
  - `debounce-delay`: The delay in milliseconds to wait before triggering a change event. This is useful to batch multiple updates together. Default is 0ms.
611
613
 
614
+ ### input-transformer
615
+
616
+ A component which can be used to transform data from an `input-provider` component and pass the transformed data to other components (or HTML elements) via custom attributes.
617
+ This component can be configured to provide its data to multiple components (consumers) via custom attributes.
618
+
619
+ **Import**
620
+
621
+ ```html
622
+ <script src="https://saasufy.com/node_modules/saasufy-components/input-transformer.js" type="module" defer></script>
623
+ ```
624
+
625
+ **Example usage**
626
+
627
+ The following example shows how to bind an `input-provider` component to an `input-transformer`.
628
+
629
+ ```html
630
+ <input-provider
631
+ class="dollar-input"
632
+ name="count"
633
+ type="text"
634
+ consumers=".cents-transformer"
635
+ value=""
636
+ placeholder="Dollars"
637
+ ></input-provider>
638
+
639
+ <input-transformer
640
+ class="cents-transformer"
641
+ consumers=".cents-container"
642
+ provider-template="{{Number(value) * 100}}"
643
+ ></input-transformer>
644
+
645
+ <div class="cents-container"></div>
646
+ ```
647
+
648
+ **Attributes**
649
+
650
+ - `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. 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.
651
+ - `provider-template`: A template string within which the `{{value}}` can be injected before passing to consumers.
652
+ - `debounce-delay`: The delay in milliseconds to wait before triggering a change event. This is useful to batch multiple updates together. Default is 0ms.
653
+
612
654
  ### log-in-form
613
655
 
614
656
  A form component which allows end-users to authenticate themselves into your app using the Saasufy blockchain or any Capitalisk-based blockchain.
@@ -139,8 +139,14 @@ class CollectionBrowser extends SocketConsumer {
139
139
  let currentPageElements = this.shadowRoot.querySelector('slot[name="page-number"]').assignedElements();
140
140
  let pageNumber = Math.floor(this.collection.meta.pageOffset / this.collection.meta.pageSize + 1);
141
141
  for (let element of currentPageElements) {
142
- if (element.nodeName === 'INPUT') {
142
+ if (element.nodeName === 'INPUT' || element.nodeName === 'MODEL-INPUT') {
143
143
  element.value = pageNumber;
144
+ } else if (
145
+ element.nodeName === 'INPUT-PROVIDER' ||
146
+ element.nodeName === 'INPUT-COMBINER' ||
147
+ element.nodeName === 'INPUT-TRANSFORMER'
148
+ ) {
149
+ element.setAttribute('value', pageNumber);
144
150
  } else {
145
151
  element.innerHTML = pageNumber;
146
152
  }
@@ -0,0 +1,48 @@
1
+ import { debouncer, updateConsumerElements } from './utils.js';
2
+
3
+ const DEFAULT_DEBOUNCE_DELAY = 0;
4
+
5
+ class InputTransformer extends HTMLElement {
6
+ constructor() {
7
+ super();
8
+ this.isReady = false;
9
+ this.debounce = debouncer();
10
+ }
11
+ connectedCallback() {
12
+ this.isReady = true;
13
+ this.render();
14
+ }
15
+
16
+ static get observedAttributes() {
17
+ return [
18
+ 'consumers',
19
+ 'debounce-delay',
20
+ 'provider-template',
21
+ 'value'
22
+ ];
23
+ }
24
+
25
+ attributeChangedCallback(name, oldValue, newValue) {
26
+ this.render();
27
+ }
28
+
29
+ render() {
30
+ if (!this.hasAttribute('value')) return;
31
+
32
+ let value = this.getAttribute('value') || '';
33
+ let debounceDelay = this.getAttribute('debounce-delay');
34
+ debounceDelay = debounceDelay ? Number(debounceDelay) : DEFAULT_DEBOUNCE_DELAY;
35
+
36
+ if (!this.isReady) return;
37
+
38
+ let consumers = this.getAttribute('consumers');
39
+ if (!consumers) return;
40
+
41
+ this.debounce(async () => {
42
+ let providerTemplate = this.getAttribute('provider-template') || '{{value}}';
43
+ updateConsumerElements(consumers, value, providerTemplate);
44
+ }, debounceDelay);
45
+ }
46
+ }
47
+
48
+ window.customElements.define('input-transformer', InputTransformer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "3.15.2",
3
+ "version": "3.16.0",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils.js CHANGED
@@ -320,6 +320,8 @@ export function updateConsumerElements(consumers, value, template, sourceElement
320
320
  }
321
321
  } else if (element.nodeName === 'MODEL-INPUT') {
322
322
  element.value = value;
323
+ } else if (element.nodeName === 'INPUT-TRANSFORMER') {
324
+ element.setAttribute('value', value);
323
325
  } else if (element.nodeName === 'INPUT-COMBINER') {
324
326
  element.setAttribute(
325
327
  'value',