@cocreate/render 1.28.2 → 1.28.4
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/CHANGELOG.md +17 -0
- package/package.json +6 -6
- package/src/index.js +38 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
## [1.28.4](https://github.com/CoCreate-app/CoCreate-render/compare/v1.28.3...v1.28.4) (2023-10-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* bump dependencies ([ac79266](https://github.com/CoCreate-app/CoCreate-render/commit/ac79266c1f0934c2e9321536626074e1d4090070))
|
|
7
|
+
* improved finding clones to update and delete ([9bafc8b](https://github.com/CoCreate-app/CoCreate-render/commit/9bafc8b56fc20a03da8963a5888164ceb5fe28fc))
|
|
8
|
+
* use tbody as new element to prevent lost of tr and td elements ([88ca483](https://github.com/CoCreate-app/CoCreate-render/commit/88ca483c30e5c66c54fc70a8064d90fa8bdadff9))
|
|
9
|
+
|
|
10
|
+
## [1.28.3](https://github.com/CoCreate-app/CoCreate-render/compare/v1.28.2...v1.28.3) (2023-10-09)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* bump dependencies ([6261af2](https://github.com/CoCreate-app/CoCreate-render/commit/6261af2d9ebaaf23d5d40695665c20159d12b2b6))
|
|
16
|
+
* bump dependencies ([8842aa0](https://github.com/CoCreate-app/CoCreate-render/commit/8842aa0be7144752ad46ae60e6b0cb5e1d2c76bd))
|
|
17
|
+
|
|
1
18
|
## [1.28.2](https://github.com/CoCreate-app/CoCreate-render/compare/v1.28.1...v1.28.2) (2023-10-09)
|
|
2
19
|
|
|
3
20
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/render",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.4",
|
|
4
4
|
"description": "A simple render component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"render",
|
|
@@ -58,10 +58,10 @@
|
|
|
58
58
|
"webpack-log": "^3.0.1"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@cocreate/actions": "^1.11.
|
|
62
|
-
"@cocreate/api": "^1.15.
|
|
63
|
-
"@cocreate/element-prototype": "^1.11.
|
|
64
|
-
"@cocreate/observer": "^1.11.
|
|
65
|
-
"@cocreate/utils": "^1.25.
|
|
61
|
+
"@cocreate/actions": "^1.11.6",
|
|
62
|
+
"@cocreate/api": "^1.15.4",
|
|
63
|
+
"@cocreate/element-prototype": "^1.11.5",
|
|
64
|
+
"@cocreate/observer": "^1.11.5",
|
|
65
|
+
"@cocreate/utils": "^1.25.3"
|
|
66
66
|
}
|
|
67
67
|
}
|
package/src/index.js
CHANGED
|
@@ -88,6 +88,13 @@ async function render({ source, element, data, key, index, currentIndex, update,
|
|
|
88
88
|
remove = remove || data.$filter.remove
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
let type = data.type
|
|
92
|
+
if (!type && data.method) {
|
|
93
|
+
type = data.method.split('.')[1]
|
|
94
|
+
} else if (type == 'key')
|
|
95
|
+
type = 'object'
|
|
96
|
+
|
|
97
|
+
|
|
91
98
|
if (!Array.isArray(element) && !(element instanceof HTMLCollection) && !(element instanceof NodeList))
|
|
92
99
|
element = [element]
|
|
93
100
|
|
|
@@ -103,6 +110,7 @@ async function render({ source, element, data, key, index, currentIndex, update,
|
|
|
103
110
|
}
|
|
104
111
|
}
|
|
105
112
|
|
|
113
|
+
// TODO: for loop data[type]?
|
|
106
114
|
if (remove) {
|
|
107
115
|
if (renderedNode.source) {
|
|
108
116
|
if (key)
|
|
@@ -112,39 +120,48 @@ async function render({ source, element, data, key, index, currentIndex, update,
|
|
|
112
120
|
}
|
|
113
121
|
}
|
|
114
122
|
|
|
115
|
-
let
|
|
123
|
+
let cloneKey
|
|
124
|
+
if (type === 'object') {
|
|
125
|
+
cloneKey = data[type][0]._id;
|
|
126
|
+
} else {
|
|
127
|
+
cloneKey = data[type][0].name;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let clone = renderedNode.clones.get(cloneKey)
|
|
116
131
|
if (!clone) return
|
|
117
132
|
|
|
118
|
-
renderedNode.clones.delete(
|
|
119
|
-
renderedNodes.delete(clone
|
|
120
|
-
clone
|
|
133
|
+
renderedNode.clones.delete(cloneKey)
|
|
134
|
+
renderedNodes.delete(clone)
|
|
135
|
+
clone.remove()
|
|
121
136
|
} else if (key || Array.isArray(data)) {
|
|
122
137
|
if (update) {
|
|
123
138
|
let clone
|
|
139
|
+
if (type === 'object') {
|
|
140
|
+
clone = renderedNode.clones.get(data[type][0]._id);
|
|
141
|
+
} else {
|
|
142
|
+
clone = renderedNode.clones.get(data[type][0].name);
|
|
143
|
+
}
|
|
124
144
|
|
|
125
145
|
if (!currentIndex)
|
|
126
146
|
currentIndex = data.$filter.currentIndex
|
|
127
147
|
|
|
128
|
-
if (currentIndex >= 0)
|
|
129
|
-
clone = Array.from(renderedNode.clones)[currentIndex]
|
|
130
|
-
else
|
|
131
|
-
clone = Array.from(renderedNode.clones)[index]
|
|
132
|
-
|
|
133
148
|
if (!clone) return
|
|
149
|
+
for (let j = 0; j < data[type].length; j++) {
|
|
150
|
+
await renderValues(clone, { object: data[type][j] });
|
|
151
|
+
if (currentIndex >= 0)
|
|
152
|
+
insertElement(renderedNode, clone, index, currentIndex)
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
134
155
|
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// TODO: if $auto here every subsequent clone will have same value, not replacing here will apply unique value to each clone
|
|
141
|
-
if (key === '$auto')
|
|
142
|
-
key = key.replace(/\$auto/g, uuid.generate(6));
|
|
156
|
+
// TODO: if $auto here every subsequent clone will have same value, not replacing here will apply unique value to each clone
|
|
157
|
+
if (key === '$auto')
|
|
158
|
+
key = key.replace(/\$auto/g, uuid.generate(6));
|
|
143
159
|
|
|
144
|
-
|
|
145
|
-
|
|
160
|
+
if (key)
|
|
161
|
+
element[i].setAttribute('render', key);
|
|
146
162
|
|
|
147
|
-
|
|
163
|
+
renderTemplate(element[i], data, key, index);
|
|
164
|
+
}
|
|
148
165
|
} else
|
|
149
166
|
await renderValues(element[i], data);
|
|
150
167
|
|
|
@@ -297,7 +314,7 @@ function cloneTemplate(template) {
|
|
|
297
314
|
}
|
|
298
315
|
|
|
299
316
|
if (typeof clone === 'string') {
|
|
300
|
-
let container = document.createElement('
|
|
317
|
+
let container = document.createElement('tbody');
|
|
301
318
|
container.innerHTML = clone;
|
|
302
319
|
clone = container.firstChild
|
|
303
320
|
container.remove()
|