saasufy-components 5.2.1 → 5.3.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 -0
- package/collection-adder-form.js +20 -2
- package/collection-adder.js +22 -4
- package/input-provider.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -213,6 +213,9 @@ This example shows how to redirect based on the user's authentication status:
|
|
|
213
213
|
Note that the app router path is based on `location.hash` so the path section in your browser's address bar needs to start with the `#` character.
|
|
214
214
|
So for example, if your `index.html` file is served up from the URL `http://mywebsite.com`, then, to activate the `/products` route as in the example above, you would need to type the URL `http://mywebsite.com#/products`.
|
|
215
215
|
|
|
216
|
+
Also note that the app router will only render once its `viewport` has been added and slotted into it.
|
|
217
|
+
If you want to make sure that some data (e.g. a config file) has been fully loaded before rendering the app, you could set the `slot="viewport"` attribute on your viewport element at a later time using JavaScript.
|
|
218
|
+
|
|
216
219
|
**Attributes of app-router**
|
|
217
220
|
|
|
218
221
|
- `default-page`: The path/route of the default page to send the user to in case no routes are matched. Commonly used to point to a `/page-not-found` page. For the home page, it's typically recommended to create a page template with `route-path=""` instead.
|
|
@@ -360,6 +363,8 @@ This component is a simplified version of the `collection-adder-form` component
|
|
|
360
363
|
- `autocapitalize`: Can be set to `off` to disable auto-capitalization of the first input character on mobile devices.
|
|
361
364
|
- `autocorrect`: Can be set to `off` to disable auto-correction of input on mobile devices.
|
|
362
365
|
- `trim-spaces`: If this attribute exists on the element, then leading and trailing spaces will be trimmed from each input element's value before submitting the form.
|
|
366
|
+
- `consumers`: This allows you to connect this `collection-adder` to other elements on your page. It should be used in conjunction with the `provider-template` attribute. The `consumers` attribute 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 output of the `collection-adder` component on submit. 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.
|
|
367
|
+
- `provider-template`: A template string within which the `{{value}}` can be injected before passing to consumers. In the case of the `collection-adder` component, the value is an object with either a `resource` property (on successful insert) or `error` (on failure). On success, the `resource` object will be the object which was added to the collection. On failure, the `error` object will be a JavaScript `Error` object with a `message` property.
|
|
363
368
|
|
|
364
369
|
### collection-adder-form
|
|
365
370
|
|
|
@@ -396,6 +401,8 @@ This component is similar to the `collection-adder` component except that it req
|
|
|
396
401
|
- `trim-spaces`: If this attribute exists on the element, then leading and trailing spaces will be trimmed from each input element's value before submitting the form.
|
|
397
402
|
- `auto-reset-hidden-inputs`: If this attribute exists, then `hidden` input elements which are inside the `collection-adder-form` will be cleared along with other input fields. By default, `hidden` input elements are not cleared when the form is reset.
|
|
398
403
|
- `greedy-refresh`: If this attribute exists, the component will refresh itself whenever an attribute is set, even if that attribute's value did not change.
|
|
404
|
+
- `consumers`: This allows you to connect this `collection-adder-form` to other elements on your page. It should be used in conjunction with the `provider-template` attribute. The `consumers` attribute 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 output of the `collection-adder-form` component on submit. 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.
|
|
405
|
+
- `provider-template`: A template string within which the `{{value}}` can be injected before passing to consumers. In the case of the `collection-adder-form` component, the value is an object with either a `resource` property (on successful insert) or `error` (on failure). On success, the `resource` object will be the object which was added to the collection. On failure, the `error` object will be a JavaScript `Error` object with a `message` property.
|
|
399
406
|
|
|
400
407
|
**Attributes of slotted input, select, textarea... elements**
|
|
401
408
|
|
package/collection-adder-form.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SocketConsumer } from './socket.js';
|
|
2
2
|
import {
|
|
3
|
+
updateConsumerElements,
|
|
3
4
|
convertStringToFieldParams,
|
|
4
5
|
getTypeCastFunction,
|
|
5
6
|
formatError
|
|
@@ -58,6 +59,7 @@ class CollectionAdderForm extends SocketConsumer {
|
|
|
58
59
|
let trimSpaces = this.hasAttribute('trim-spaces');
|
|
59
60
|
|
|
60
61
|
let inputElements = this.getAllInputElements();
|
|
62
|
+
let outputValue;
|
|
61
63
|
|
|
62
64
|
try {
|
|
63
65
|
let newModelData = {
|
|
@@ -105,14 +107,23 @@ class CollectionAdderForm extends SocketConsumer {
|
|
|
105
107
|
)
|
|
106
108
|
};
|
|
107
109
|
|
|
108
|
-
await this.collection.create(newModelData);
|
|
110
|
+
let resourceId = await this.collection.create(newModelData);
|
|
111
|
+
let insertedModelData = {
|
|
112
|
+
...newModelData,
|
|
113
|
+
id: resourceId
|
|
114
|
+
};
|
|
109
115
|
this.dispatchEvent(
|
|
110
116
|
new CustomEvent('success', {
|
|
111
|
-
detail:
|
|
117
|
+
detail: insertedModelData
|
|
112
118
|
})
|
|
113
119
|
);
|
|
120
|
+
|
|
114
121
|
this.reset();
|
|
115
122
|
|
|
123
|
+
outputValue = {
|
|
124
|
+
resource: insertedModelData
|
|
125
|
+
};
|
|
126
|
+
|
|
116
127
|
messageContainer = this.shadowRoot.querySelector('slot[name="message"]').assignedElements()[0];
|
|
117
128
|
if (messageContainer) {
|
|
118
129
|
messageContainer.classList.add('success');
|
|
@@ -135,7 +146,14 @@ class CollectionAdderForm extends SocketConsumer {
|
|
|
135
146
|
detail: error
|
|
136
147
|
})
|
|
137
148
|
);
|
|
149
|
+
|
|
150
|
+
outputValue = {
|
|
151
|
+
error
|
|
152
|
+
};
|
|
138
153
|
}
|
|
154
|
+
let consumers = this.getAttribute('consumers');
|
|
155
|
+
let providerTemplate = this.getAttribute('provider-template');
|
|
156
|
+
updateConsumerElements(consumers, outputValue, providerTemplate, this.getAttribute('name'));
|
|
139
157
|
}
|
|
140
158
|
|
|
141
159
|
getAllInputElements() {
|
package/collection-adder.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SocketConsumer } from './socket.js';
|
|
2
2
|
import {
|
|
3
|
+
updateConsumerElements,
|
|
3
4
|
convertStringToFieldParams,
|
|
4
5
|
getTypeCastFunction,
|
|
5
6
|
formatError
|
|
@@ -66,6 +67,7 @@ class CollectionAdder extends SocketConsumer {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
let trimSpaces = this.hasAttribute('trim-spaces');
|
|
70
|
+
let outputValue;
|
|
69
71
|
|
|
70
72
|
try {
|
|
71
73
|
let newModelData = {
|
|
@@ -108,16 +110,26 @@ class CollectionAdder extends SocketConsumer {
|
|
|
108
110
|
)
|
|
109
111
|
)
|
|
110
112
|
};
|
|
111
|
-
await this.collection.create(newModelData);
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
let resourceId = await this.collection.create(newModelData);
|
|
114
|
+
let insertedModelData = {
|
|
115
|
+
...newModelData,
|
|
116
|
+
id: resourceId
|
|
117
|
+
};
|
|
114
118
|
this.dispatchEvent(
|
|
115
119
|
new CustomEvent('success', {
|
|
116
|
-
detail:
|
|
120
|
+
detail: insertedModelData
|
|
117
121
|
})
|
|
118
122
|
);
|
|
119
123
|
let form = this.querySelector('.collection-adder-form');
|
|
120
124
|
form.reset();
|
|
125
|
+
|
|
126
|
+
outputValue = {
|
|
127
|
+
resource: insertedModelData
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
messageContainer.classList.add('success');
|
|
131
|
+
messageContainer.classList.remove('error');
|
|
132
|
+
|
|
121
133
|
if (successMessage) {
|
|
122
134
|
messageContainer.textContent = successMessage;
|
|
123
135
|
} else {
|
|
@@ -132,7 +144,13 @@ class CollectionAdder extends SocketConsumer {
|
|
|
132
144
|
detail: error
|
|
133
145
|
})
|
|
134
146
|
);
|
|
147
|
+
outputValue = {
|
|
148
|
+
error
|
|
149
|
+
};
|
|
135
150
|
}
|
|
151
|
+
let consumers = this.getAttribute('consumers');
|
|
152
|
+
let providerTemplate = this.getAttribute('provider-template');
|
|
153
|
+
updateConsumerElements(consumers, outputValue, providerTemplate, this.getAttribute('name'));
|
|
136
154
|
}
|
|
137
155
|
|
|
138
156
|
reset() {
|
package/input-provider.js
CHANGED