@dile/ui 3.7.1 → 3.7.2
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.
|
@@ -20,11 +20,11 @@ export const DileForm = (superclass) => class extends superclass {
|
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
firstUpdated() {
|
|
23
|
+
async firstUpdated() {
|
|
24
24
|
super.firstUpdated();
|
|
25
25
|
this.firstValue = this.getData();
|
|
26
26
|
if(this.setOnInit) {
|
|
27
|
-
this.setData(this.setOnInit);
|
|
27
|
+
await this.setData(this.setOnInit);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -32,6 +32,7 @@ export const DileForm = (superclass) => class extends superclass {
|
|
|
32
32
|
let data = {};
|
|
33
33
|
this.allNodeElements.forEach(node => {
|
|
34
34
|
const name = node.getAttribute('name');
|
|
35
|
+
if (!name) return;
|
|
35
36
|
const isArray = name.endsWith('[]');
|
|
36
37
|
const fieldName = isArray ? name.slice(0, -2) : name;
|
|
37
38
|
|
|
@@ -47,16 +48,18 @@ export const DileForm = (superclass) => class extends superclass {
|
|
|
47
48
|
return this.adaptDataOut(data);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
setData(data) {
|
|
51
|
+
async setData(data) {
|
|
52
|
+
await this.updateComplete;
|
|
51
53
|
const adaptedData = this.adaptDataIn(data);
|
|
52
|
-
this.allNodeElements
|
|
54
|
+
const allNodeElements = this.allNodeElements;
|
|
55
|
+
allNodeElements.forEach(node => {
|
|
53
56
|
const name = node.getAttribute('name');
|
|
57
|
+
if (!name) return;
|
|
54
58
|
const isArray = name.endsWith('[]');
|
|
55
59
|
const fieldName = isArray ? name.slice(0, -2) : name;
|
|
56
60
|
|
|
57
61
|
if (isArray && Array.isArray(adaptedData[fieldName])) {
|
|
58
|
-
|
|
59
|
-
const arrayElements = Array.from(this.allNodeElements).filter(el => el.getAttribute('name') === name);
|
|
62
|
+
const arrayElements = Array.from(allNodeElements).filter(el => el.getAttribute('name') === name);
|
|
60
63
|
const elementIndex = arrayElements.indexOf(node);
|
|
61
64
|
if (elementIndex >= 0 && elementIndex < adaptedData[fieldName].length) {
|
|
62
65
|
const value = adaptedData[fieldName][elementIndex];
|
|
@@ -104,7 +107,7 @@ export const DileForm = (superclass) => class extends superclass {
|
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
resetData() {
|
|
107
|
-
this.setData(this.firstValue);
|
|
110
|
+
return this.setData(this.firstValue);
|
|
108
111
|
}
|
|
109
112
|
|
|
110
113
|
resetField(name) {
|
|
@@ -189,7 +192,7 @@ export const DileForm = (superclass) => class extends superclass {
|
|
|
189
192
|
|
|
190
193
|
isDirty() {
|
|
191
194
|
const currentData = this.getData();
|
|
192
|
-
const originProperties = Object.keys(this.firstValue);
|
|
195
|
+
const originProperties = Object.keys(this.firstValue || {});
|
|
193
196
|
const currentProperties = Object.keys(currentData);
|
|
194
197
|
if (originProperties.length !== currentProperties.length) {
|
|
195
198
|
return true;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import { LitElement, html } from 'lit';
|
|
3
|
+
import { DileForm } from './DileForm.js';
|
|
4
|
+
|
|
5
|
+
class RaceTestForm extends DileForm(LitElement) {
|
|
6
|
+
render() {
|
|
7
|
+
return html`<input name="name" />`;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (!customElements.get('race-test-form')) {
|
|
12
|
+
customElements.define('race-test-form', RaceTestForm);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('DileForm', () => {
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
document.body.innerHTML = '';
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('applies setData after the first render is ready even when called immediately', async () => {
|
|
21
|
+
const form = document.createElement('race-test-form');
|
|
22
|
+
document.body.appendChild(form);
|
|
23
|
+
|
|
24
|
+
form.setData({ name: 'Alice' });
|
|
25
|
+
await form.updateComplete;
|
|
26
|
+
|
|
27
|
+
expect(form.shadowRoot.querySelector('input').value).toBe('Alice');
|
|
28
|
+
});
|
|
29
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/ui",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.2",
|
|
4
4
|
"description": "UI Core components from dile-components.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "47effc45eac082504ecaa3554c8af5a8a1055a38"
|
|
32
32
|
}
|