saasufy-components 3.24.0 → 3.25.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
@@ -491,7 +491,7 @@ Used for displaying and editing a single field of a model instance in real time.
491
491
  - `list`: If specified, this sets the list attribute of the inner `input` element to provide input suggestions (only works with standard input elements).
492
492
  - `type`: The type of the input component; can be `text`, `number`, `select`, `textarea`, `checkbox` or `file`.
493
493
  - `placeholder`: Can be used to set the placeholder text on the inner input element.
494
- - `consumers`: This allows you to connect this `model-input` 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 `model-input` 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.
494
+ - `consumers`: This allows you to connect this `model-input` 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 `model-input` 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. Note that `model-input` elements of the `file` type are treated as write-only unless the `consumers` attribute is present.
495
495
  - `provider-template`: A template string within which the `{{value}}` can be injected before passing to consumers.
496
496
  - `show-error-message`: If this attribute is present, an error message will be displayed above the input if it fails to update the value.
497
497
  - `options`: A comma-separated list of options to provide - This only works if the input type is `select`.
@@ -499,7 +499,7 @@ Used for displaying and editing a single field of a model instance in real time.
499
499
  - `default-value`: A default value to show the user if the underlying model field's value is null or undefined. Note that setting a default value will not affect the underlying model's value.
500
500
  - `value`: Used to set the model's value.
501
501
  - `computable-value`: If this attribute is present, it will be possible to execute expressions using the `{{expression}}` syntax inside the `value` attribute.
502
- - `slice-to`: Optional field which can be set to a number to trim strings down to a maximum number of characters. This is useful when dealing with potentially very long field values. Extra care should be taken when using this attribute on a `model-input` element as it will cause values to be overwritten with shortened values if the user edits the input box. Note also 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`.
502
+ - `slice-to`: Optional attribute which can be set to a number to trim strings down to a maximum number of characters. This is useful when dealing with potentially very long field values. Extra care should be taken when using this attribute on a `model-input` element as it will cause values to be overwritten with shortened values if the user edits the input box. Note also 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`.
503
503
  - `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.
504
504
  - `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.
505
505
  - `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.
@@ -534,7 +534,7 @@ Used to displaying a field of a model instance in real time.
534
534
  - `model-type` (required): Specifies the type of model to bind to. This should match a `Model` available in your Saasufy service.
535
535
  - `model-id` (required): The id of the model instance/record to bind to.
536
536
  - `model-field` (required): The field of the model instance/record to bind to for reading.
537
- - `slice-to`: Optional field 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`.
537
+ - `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`.
538
538
  - `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.
539
539
 
540
540
  ### model-viewer
@@ -573,6 +573,7 @@ Used for rendering a single model resource using a template. This is the single-
573
573
  - `model-id` (required): The id of the model instance/record to bind to.
574
574
  - `model-fields` (required): A comma-separated list of fields to bind to. Note that unlike with `model-input` and `model-text`, the attribute name is plural and can bind to multiple fields.
575
575
  - `type-alias`: Allows you to provide an alternative name for your `Model` to use when injecting values inside the template. This is useful for situations where you may have multiple `model-browser` elements and/or `model-viewer` elements of the same type nested inside each other and want to avoid `Model` name clashes in the nested template definitions. For example, if the `type-alias` in the snippet above was set to `MyProduct`, then `{{Product.name}}` would become `{{MyProduct.name}}`.
576
+ - `fields-slice-to`: Optional attribute which can be used to trim strings down to a maximum number of characters when reading. The format is `fieldName1=number1,fieldName2=number2`. 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`.
576
577
  - `hide-error-logs`: A flag which, when present, suppresses error logs from being printed to the console.
577
578
 
578
579
  ### input-provider
@@ -604,7 +605,7 @@ This component can be configured to provide its data to multiple components (con
604
605
  - `list`: If specified, this sets the list attribute of the inner `input` element to provide input suggestions (only works with standard input elements).
605
606
  - `type`: The type of the input component; can be `text`, `number`, `select`, `textarea` or `checkbox`.
606
607
  - `placeholder`: Can be used to set the placeholder text on the inner input element.
607
- - `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.
608
+ - `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.
608
609
  - `provider-template`: A template string within which the `{{value}}` can be injected before passing to consumers.
609
610
  - `debounce-delay`: The delay in milliseconds to wait before triggering a change event. This is useful to batch multiple updates together (as is common when user is typing). Default is 800ms.
610
611
  - `options`: A comma-separated list of options to provide - This only works if the input type is `select`.
@@ -665,7 +666,7 @@ The `combineFilters` function produces a combined query string (joined with `%AN
665
666
 
666
667
  **Attributes**
667
668
 
668
- - `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 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.
669
+ - `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 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.
669
670
  - `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.
670
671
  - `debounce-delay`: The delay in milliseconds to wait before triggering a change event. This is useful to batch multiple updates together. Default is 0ms.
671
672
 
@@ -705,7 +706,7 @@ The following example shows how to bind an `input-provider` component to an `inp
705
706
 
706
707
  **Attributes**
707
708
 
708
- - `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.
709
+ - `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.
709
710
  - `provider-template`: A template string within which the `{{value}}` can be injected before passing to consumers.
710
711
  - `debounce-delay`: The delay in milliseconds to wait before triggering a change event. This is useful to batch multiple updates together. Default is 0ms.
711
712
 
package/model-viewer.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { SocketConsumer } from './socket.js';
2
2
  import AGModel from '/node_modules/ag-model/ag-model.js';
3
- import { renderTemplate } from './utils.js';
3
+ import { renderTemplate, convertStringToFieldParams } from './utils.js';
4
4
 
5
5
  class ModelViewer extends SocketConsumer {
6
6
  constructor() {
@@ -30,9 +30,11 @@ class ModelViewer extends SocketConsumer {
30
30
 
31
31
  static get observedAttributes() {
32
32
  return [
33
+ 'socket-instance-property',
33
34
  'model-type',
34
35
  'model-id',
35
36
  'model-fields',
37
+ 'fields-slice-to',
36
38
  'type-alias',
37
39
  'hide-error-logs'
38
40
  ];
@@ -85,12 +87,22 @@ class ModelViewer extends SocketConsumer {
85
87
  }
86
88
 
87
89
  render() {
90
+ let socketInstanceProperty = this.getAttribute('socket-instance-property');
88
91
  let modelType = this.getAttribute('model-type');
89
92
  let modelId = this.getAttribute('model-id');
90
93
  let modelFields = this.getAttribute('model-fields') || '';
91
- let socketInstanceProperty = this.getAttribute('socket-instance-property');
94
+ let fieldsSliceTo = this.getAttribute('fields-slice-to') || '';
92
95
  let hideErrorLogs = this.hasAttribute('hide-error-logs');
93
96
 
97
+ let {
98
+ fieldValues: sliceToMap
99
+ } = convertStringToFieldParams(fieldsSliceTo);
100
+
101
+ let fieldTransformations = {};
102
+ for (let [ fieldName, sliceTo ] of Object.entries(sliceToMap)) {
103
+ fieldTransformations[fieldName] = { sliceTo: Number(sliceTo) };
104
+ }
105
+
94
106
  if (this.model) this.model.destroy();
95
107
 
96
108
  let socket;
@@ -114,11 +126,13 @@ class ModelViewer extends SocketConsumer {
114
126
  socket = this.getSocket();
115
127
  }
116
128
  this.socket = socket;
129
+
117
130
  this.model = new AGModel({
118
131
  socket: this.socket,
119
132
  type: modelType,
120
133
  id: modelId,
121
- fields: modelFields.split(',').map(field => field.trim()).filter(field => field)
134
+ fields: modelFields.split(',').map(field => field.trim()).filter(field => field),
135
+ fieldTransformations
122
136
  });
123
137
 
124
138
  this.shadowRoot.innerHTML = `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasufy-components",
3
- "version": "3.24.0",
3
+ "version": "3.25.0",
4
4
  "description": "Components for Saasufy.",
5
5
  "main": "index.js",
6
6
  "scripts": {