saasufy-components 1.0.3 → 1.0.5
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 +37 -1
- package/model-input.js +40 -31
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Saasufy Components
|
|
2
2
|
Components for Saasufy
|
|
3
|
+
|
|
4
|
+
## How to use
|
|
5
|
+
|
|
6
|
+
Coming soon.
|
|
7
|
+
|
|
8
|
+
## Components
|
|
9
|
+
|
|
10
|
+
### collection-adder
|
|
11
|
+
|
|
12
|
+
A form component for inserting data into collections.
|
|
13
|
+
|
|
14
|
+
### collection-browser
|
|
15
|
+
|
|
16
|
+
Used for rendering collections as lists, tables or other sequences based on a specific view.
|
|
17
|
+
Supports pagination by allowing you to specify custom buttons or links to navigate between pages.
|
|
18
|
+
Can also perform basic CRUD operations such as deleting or creating records.
|
|
19
|
+
|
|
20
|
+
### model-input
|
|
21
|
+
|
|
22
|
+
Used for displaying and editing a field of a model instance in real time.
|
|
23
|
+
|
|
24
|
+
### confirm-modal
|
|
25
|
+
|
|
26
|
+
A modal component to prompt the user for confirmation before performing sensitive operations.
|
|
27
|
+
|
|
28
|
+
### model-text
|
|
29
|
+
|
|
30
|
+
Used to displaying a field of a model instance in real time.
|
|
31
|
+
|
|
32
|
+
### overlay-modal
|
|
33
|
+
|
|
34
|
+
A general purpose modal component.
|
|
35
|
+
|
|
36
|
+
### render-group
|
|
37
|
+
|
|
38
|
+
A component which can be used to guarantee that certain children components are always rendered at the same time (once they are loaded) to provide a smooth user experience.
|
package/model-input.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getSocket } from './socket.js';
|
|
2
|
-
import { getSafeHTML } from './utils.js';
|
|
2
|
+
import { getSafeHTML, debouncer } from './utils.js';
|
|
3
3
|
import AGModel from '/node_modules/ag-model/ag-model.js';
|
|
4
4
|
|
|
5
5
|
class ModelInput extends HTMLElement {
|
|
@@ -30,6 +30,7 @@ class ModelInput extends HTMLElement {
|
|
|
30
30
|
'model-type',
|
|
31
31
|
'model-id',
|
|
32
32
|
'model-field',
|
|
33
|
+
'debounce-delay',
|
|
33
34
|
'options',
|
|
34
35
|
'height'
|
|
35
36
|
];
|
|
@@ -199,38 +200,21 @@ class ModelInput extends HTMLElement {
|
|
|
199
200
|
messageContainerElement.classList.add('hidden');
|
|
200
201
|
};
|
|
201
202
|
|
|
202
|
-
let
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (inputElement.type === 'checkbox') {
|
|
206
|
-
await model.update(fieldName, !!inputElement.checked);
|
|
207
|
-
inputElement.classList.remove(errorStyleClass);
|
|
208
|
-
inputElement.classList.add(successStyleClass);
|
|
209
|
-
hideErrorMessage(fieldName);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
if (event.target.value === '') {
|
|
213
|
-
await model.delete(fieldName);
|
|
214
|
-
} else {
|
|
215
|
-
let targetValue = inputElement.type === 'number' ?
|
|
216
|
-
Number(event.target.value) : event.target.value;
|
|
217
|
-
await model.update(fieldName, targetValue);
|
|
218
|
-
}
|
|
219
|
-
inputElement.classList.remove(errorStyleClass);
|
|
220
|
-
inputElement.classList.add(successStyleClass);
|
|
221
|
-
hideErrorMessage(fieldName);
|
|
222
|
-
} catch (error) {
|
|
223
|
-
inputElement.classList.add(errorStyleClass);
|
|
224
|
-
inputElement.classList.remove(successStyleClass);
|
|
225
|
-
showErrorMessage(fieldName, error.message);
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
inputElement.addEventListener('change', onInputChange);
|
|
203
|
+
let debounceDelay = this.getAttribute('debounce-delay');
|
|
204
|
+
debounceDelay = debounceDelay ? Number(debounceDelay) : null;
|
|
205
|
+
let debounce = debouncer();
|
|
229
206
|
|
|
230
|
-
let
|
|
231
|
-
|
|
232
|
-
|
|
207
|
+
let onInputChange = (event) => {
|
|
208
|
+
if (event.target.value === String(model.value[fieldName])) return;
|
|
209
|
+
debounce(async () => {
|
|
233
210
|
try {
|
|
211
|
+
if (inputElement.type === 'checkbox') {
|
|
212
|
+
await model.update(fieldName, !!inputElement.checked);
|
|
213
|
+
inputElement.classList.remove(errorStyleClass);
|
|
214
|
+
inputElement.classList.add(successStyleClass);
|
|
215
|
+
hideErrorMessage(fieldName);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
234
218
|
if (event.target.value === '') {
|
|
235
219
|
await model.delete(fieldName);
|
|
236
220
|
} else {
|
|
@@ -246,6 +230,31 @@ class ModelInput extends HTMLElement {
|
|
|
246
230
|
inputElement.classList.remove(successStyleClass);
|
|
247
231
|
showErrorMessage(fieldName, error.message);
|
|
248
232
|
}
|
|
233
|
+
}, debounceDelay);
|
|
234
|
+
};
|
|
235
|
+
inputElement.addEventListener('change', onInputChange);
|
|
236
|
+
|
|
237
|
+
let onInputKeyUp;
|
|
238
|
+
if (inputElement.type !== 'checkbox') {
|
|
239
|
+
onInputKeyUp = async (event) => {
|
|
240
|
+
debounce(async () => {
|
|
241
|
+
try {
|
|
242
|
+
if (event.target.value === '') {
|
|
243
|
+
await model.delete(fieldName);
|
|
244
|
+
} else {
|
|
245
|
+
let targetValue = inputElement.type === 'number' ?
|
|
246
|
+
Number(event.target.value) : event.target.value;
|
|
247
|
+
await model.update(fieldName, targetValue);
|
|
248
|
+
}
|
|
249
|
+
inputElement.classList.remove(errorStyleClass);
|
|
250
|
+
inputElement.classList.add(successStyleClass);
|
|
251
|
+
hideErrorMessage(fieldName);
|
|
252
|
+
} catch (error) {
|
|
253
|
+
inputElement.classList.add(errorStyleClass);
|
|
254
|
+
inputElement.classList.remove(successStyleClass);
|
|
255
|
+
showErrorMessage(fieldName, error.message);
|
|
256
|
+
}
|
|
257
|
+
}, debounceDelay);
|
|
249
258
|
};
|
|
250
259
|
inputElement.addEventListener('keyup', onInputKeyUp);
|
|
251
260
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saasufy-components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Components for Saasufy.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"ag-collection": "^3.2.0",
|
|
21
21
|
"ag-model": "^1.3.5",
|
|
22
|
-
"socketcluster-client": "^
|
|
22
|
+
"socketcluster-client": "^19.0.2"
|
|
23
23
|
},
|
|
24
24
|
"bugs": {
|
|
25
25
|
"url": "https://github.com/Saasufy/saasufy-components/issues"
|