saasufy-components 4.3.0 → 4.5.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
@@ -532,6 +532,7 @@ Used for displaying and editing a single field of a model instance in real time.
532
532
  - `model-id` (required): The id of the model instance/record to bind to.
533
533
  - `model-field` (required): The field of the model instance/record to bind to for reading and updating.
534
534
  - `debounce-delay`: The delay in milliseconds to wait before sending an update to the server. This is useful to batch multiple updates together (as is common when user is typing). Default is 300ms.
535
+ - `disable-instant-flush`: If specified, changes will only be saved once they have settled (E.g. after the element has lost focus or when the enter key is pressed).
535
536
  - `list`: If specified, this sets the list attribute of the inner `input` element to provide input suggestions (only works with standard input elements).
536
537
  - `type`: The type of the input component; can be `text`, `number`, `select`, `textarea`, `checkbox` or `file`.
537
538
  - `placeholder`: Can be used to set the placeholder text on the inner input element.
@@ -580,6 +581,7 @@ Used to displaying a field of a model instance in real time.
580
581
  - `model-id` (required): The id of the model instance/record to bind to.
581
582
  - `model-field` (required): The field of the model instance/record to bind to for reading.
582
583
  - `slice-to`: Optional attribute which can be set to a number to trim strings down to a maximum number of characters when reading. This is useful when dealing with potentially very long field values. Note that it may affect caching if the same field is being referenced in multiple parts of the application at the same time within the same `socket-provider`.
584
+ - `default-value`: A default value to show the user if the underlying model field's value is null or undefined.
583
585
  - `hide-error-logs`: By default, this component will log errors to the console. If set, this attribute will suppress such errors from showing up on the console.
584
586
 
585
587
  ### model-viewer
@@ -649,6 +651,7 @@ This component can be configured to provide its data to multiple components (con
649
651
  - `input-id`: Can be used to set an `id` attribute on the inner `input` element.
650
652
  - `list`: If specified, this sets the list attribute of the inner `input` element to provide input suggestions (only works with standard input elements).
651
653
  - `type`: The type of the input component; can be `text`, `number`, `select`, `textarea` or `checkbox`.
654
+ - `disable-instant-flush`: If specified, changes will only be saved once they have settled (E.g. after the element has lost focus or when the enter key is pressed).
652
655
  - `placeholder`: Can be used to set the placeholder text on the inner input element.
653
656
  - `consumers`: This allows you to connect this `input-provider` 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.
654
657
  - `provider-template`: A template string within which the `{{value}}` can be injected before passing to consumers.
package/input-provider.js CHANGED
@@ -222,6 +222,7 @@ class InputProvider extends HTMLElement {
222
222
  if (inputElement.type !== 'checkbox') {
223
223
  onInputKeyUp = async (event) => {
224
224
  this.updateInputClassList(event.target.value);
225
+ if (this.hasAttribute('disable-instant-flush')) return;
225
226
  debounce(async () => {
226
227
  let elementName = this.getAttribute('name');
227
228
  let providerTemplate = this.getAttribute('provider-template');
package/model-input.js CHANGED
@@ -395,6 +395,7 @@ class ModelInput extends SocketConsumer {
395
395
  if (inputType !== 'checkbox' && inputType !== 'select' && inputType !== 'file') {
396
396
  onInputKeyUp = async (event) => {
397
397
  inputElement.classList.remove(successStyleClass);
398
+ if (this.hasAttribute('disable-instant-flush')) return;
398
399
  debounce(async () => {
399
400
  if (event.target.value === String(model.value[fieldName] || '')) return;
400
401
  let providerTemplate = this.getAttribute('provider-template');
package/model-text.js CHANGED
@@ -25,7 +25,8 @@ class ModelText extends SocketConsumer {
25
25
  'model-id',
26
26
  'model-field',
27
27
  'slice-to',
28
- 'hide-error-logs'
28
+ 'hide-error-logs',
29
+ 'default-value'
29
30
  ];
30
31
  }
31
32
 
@@ -35,6 +36,14 @@ class ModelText extends SocketConsumer {
35
36
  this.render();
36
37
  }
37
38
 
39
+ computeDisplayValue(value) {
40
+ let safeValue = toSafeHTML(value);
41
+ if (safeValue != null) {
42
+ return safeValue;
43
+ }
44
+ return this.getAttribute('default-value') || '';
45
+ }
46
+
38
47
  render() {
39
48
  this.innerHTML = '';
40
49
  let socketInstanceProperty = this.getAttribute('socket-instance-property');
@@ -107,12 +116,11 @@ class ModelText extends SocketConsumer {
107
116
  (async () => {
108
117
  for await (let event of changeConsumer) {
109
118
  if (event.resourceField !== modelField) continue;
110
- let fieldValue = toSafeHTML(model.value[modelField]);
111
- this.innerHTML = fieldValue;
119
+ this.innerHTML = this.computeDisplayValue(model.value[modelField]);
112
120
  }
113
121
  })();
114
122
  if (model.isLoaded) {
115
- this.innerHTML = toSafeHTML(model.value[modelField]);
123
+ this.innerHTML = this.computeDisplayValue(model.value[modelField]);
116
124
  }
117
125
  this.destroy = () => {
118
126
  changeConsumer.kill();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "4.3.0",
3
+ "version": "4.5.0",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {