saasufy-components 3.23.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 +7 -4
- package/model-input.js +12 -0
- package/model-text.js +14 -1
- package/model-viewer.js +17 -3
- package/package.json +3 -3
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
|
|
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,6 +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 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`.
|
|
502
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.
|
|
503
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.
|
|
504
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.
|
|
@@ -533,6 +534,7 @@ Used to displaying a field of a model instance in real time.
|
|
|
533
534
|
- `model-type` (required): Specifies the type of model to bind to. This should match a `Model` available in your Saasufy service.
|
|
534
535
|
- `model-id` (required): The id of the model instance/record to bind to.
|
|
535
536
|
- `model-field` (required): The field of the model instance/record to bind to for reading.
|
|
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`.
|
|
536
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.
|
|
537
539
|
|
|
538
540
|
### model-viewer
|
|
@@ -571,6 +573,7 @@ Used for rendering a single model resource using a template. This is the single-
|
|
|
571
573
|
- `model-id` (required): The id of the model instance/record to bind to.
|
|
572
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.
|
|
573
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`.
|
|
574
577
|
- `hide-error-logs`: A flag which, when present, suppresses error logs from being printed to the console.
|
|
575
578
|
|
|
576
579
|
### input-provider
|
|
@@ -602,7 +605,7 @@ This component can be configured to provide its data to multiple components (con
|
|
|
602
605
|
- `list`: If specified, this sets the list attribute of the inner `input` element to provide input suggestions (only works with standard input elements).
|
|
603
606
|
- `type`: The type of the input component; can be `text`, `number`, `select`, `textarea` or `checkbox`.
|
|
604
607
|
- `placeholder`: Can be used to set the placeholder text on the inner input element.
|
|
605
|
-
- `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
|
|
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.
|
|
606
609
|
- `provider-template`: A template string within which the `{{value}}` can be injected before passing to consumers.
|
|
607
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.
|
|
608
611
|
- `options`: A comma-separated list of options to provide - This only works if the input type is `select`.
|
|
@@ -663,7 +666,7 @@ The `combineFilters` function produces a combined query string (joined with `%AN
|
|
|
663
666
|
|
|
664
667
|
**Attributes**
|
|
665
668
|
|
|
666
|
-
- `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
|
|
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.
|
|
667
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.
|
|
668
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.
|
|
669
672
|
|
|
@@ -703,7 +706,7 @@ The following example shows how to bind an `input-provider` component to an `inp
|
|
|
703
706
|
|
|
704
707
|
**Attributes**
|
|
705
708
|
|
|
706
|
-
- `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
|
|
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.
|
|
707
710
|
- `provider-template`: A template string within which the `{{value}}` can be injected before passing to consumers.
|
|
708
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.
|
|
709
712
|
|
package/model-input.js
CHANGED
|
@@ -31,6 +31,7 @@ class ModelInput extends SocketConsumer {
|
|
|
31
31
|
'model-type',
|
|
32
32
|
'model-id',
|
|
33
33
|
'model-field',
|
|
34
|
+
'slice-to',
|
|
34
35
|
'debounce-delay',
|
|
35
36
|
'enable-rebound',
|
|
36
37
|
'options',
|
|
@@ -109,6 +110,7 @@ class ModelInput extends SocketConsumer {
|
|
|
109
110
|
let modelType = this.getAttribute('model-type');
|
|
110
111
|
let modelId = this.getAttribute('model-id');
|
|
111
112
|
let modelField = this.getAttribute('model-field');
|
|
113
|
+
let sliceTo = this.getAttribute('slice-to');
|
|
112
114
|
let options = this.getAttribute('options');
|
|
113
115
|
let height = this.getAttribute('height');
|
|
114
116
|
let hideErrorLogs = this.hasAttribute('hide-error-logs');
|
|
@@ -141,11 +143,21 @@ class ModelInput extends SocketConsumer {
|
|
|
141
143
|
|
|
142
144
|
let modelFieldList = writeOnly ? [] : [ modelField ];
|
|
143
145
|
|
|
146
|
+
let fieldTransformations;
|
|
147
|
+
if (sliceTo != null) {
|
|
148
|
+
fieldTransformations = {
|
|
149
|
+
[modelField]: { sliceTo: Number(sliceTo) }
|
|
150
|
+
};
|
|
151
|
+
} else {
|
|
152
|
+
fieldTransformations = {};
|
|
153
|
+
}
|
|
154
|
+
|
|
144
155
|
let model = new AGModel({
|
|
145
156
|
socket: this.socket,
|
|
146
157
|
type: modelType,
|
|
147
158
|
id: modelId,
|
|
148
159
|
fields: modelFieldList,
|
|
160
|
+
fieldTransformations,
|
|
149
161
|
enableRebound
|
|
150
162
|
});
|
|
151
163
|
if (!hideErrorLogs) {
|
package/model-text.js
CHANGED
|
@@ -24,6 +24,7 @@ class ModelText extends SocketConsumer {
|
|
|
24
24
|
'model-type',
|
|
25
25
|
'model-id',
|
|
26
26
|
'model-field',
|
|
27
|
+
'slice-to',
|
|
27
28
|
'hide-error-logs'
|
|
28
29
|
];
|
|
29
30
|
}
|
|
@@ -40,6 +41,7 @@ class ModelText extends SocketConsumer {
|
|
|
40
41
|
let modelType = this.getAttribute('model-type');
|
|
41
42
|
let modelId = this.getAttribute('model-id');
|
|
42
43
|
let modelField = this.getAttribute('model-field');
|
|
44
|
+
let sliceTo = this.getAttribute('slice-to');
|
|
43
45
|
let hideErrorLogs = this.hasAttribute('hide-error-logs');
|
|
44
46
|
|
|
45
47
|
let socket;
|
|
@@ -63,11 +65,22 @@ class ModelText extends SocketConsumer {
|
|
|
63
65
|
socket = this.getSocket();
|
|
64
66
|
}
|
|
65
67
|
this.socket = socket;
|
|
68
|
+
|
|
69
|
+
let fieldTransformations;
|
|
70
|
+
if (sliceTo != null) {
|
|
71
|
+
fieldTransformations = {
|
|
72
|
+
[modelField]: { sliceTo: Number(sliceTo) }
|
|
73
|
+
};
|
|
74
|
+
} else {
|
|
75
|
+
fieldTransformations = {};
|
|
76
|
+
}
|
|
77
|
+
|
|
66
78
|
let model = new AGModel({
|
|
67
79
|
socket: this.socket,
|
|
68
80
|
type: modelType,
|
|
69
81
|
id: modelId,
|
|
70
|
-
fields: [ modelField ]
|
|
82
|
+
fields: [ modelField ],
|
|
83
|
+
fieldTransformations
|
|
71
84
|
});
|
|
72
85
|
if (!hideErrorLogs) {
|
|
73
86
|
(async () => {
|
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
|
|
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.
|
|
3
|
+
"version": "3.25.0",
|
|
4
4
|
"description": "Components for Saasufy.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"author": "Jonathan Gros-Dubois",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"ag-collection": "^5.0
|
|
21
|
-
"ag-model": "^3.0
|
|
20
|
+
"ag-collection": "^5.1.0",
|
|
21
|
+
"ag-model": "^3.1.0",
|
|
22
22
|
"capitalisk-auth-client": "^1.5.1",
|
|
23
23
|
"socketcluster-client": "^19.1.0",
|
|
24
24
|
"uuid": "^8.3.2"
|