@cocreate/render 1.12.3 → 1.13.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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/index.js +21 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.13.0](https://github.com/CoCreate-app/CoCreate-render/compare/v1.12.3...v1.13.0) (2022-08-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add a map containing rendered keys to templates, if key not rendered clone template and render key ([0fd8cfd](https://github.com/CoCreate-app/CoCreate-render/commit/0fd8cfd3695280e19b6e518fd45d873d1637ed6e))
|
|
7
|
+
|
|
1
8
|
## [1.12.3](https://github.com/CoCreate-app/CoCreate-render/compare/v1.12.2...v1.12.3) (2022-08-19)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import './index.css';
|
|
|
9
9
|
|
|
10
10
|
const CoCreateRender = {
|
|
11
11
|
// Can be called from crud getObjectValueByPath
|
|
12
|
-
__getValueFromObject
|
|
12
|
+
__getValueFromObject: function(json, path) {
|
|
13
13
|
try {
|
|
14
14
|
if(typeof json == 'undefined' || !path)
|
|
15
15
|
return false;
|
|
@@ -114,6 +114,7 @@ const CoCreateRender = {
|
|
|
114
114
|
|
|
115
115
|
render: function(template, data) {
|
|
116
116
|
const self = this;
|
|
117
|
+
const templateId = template.getAttribute('templateId')
|
|
117
118
|
let type = '';
|
|
118
119
|
let arrayData = data;
|
|
119
120
|
|
|
@@ -132,14 +133,20 @@ const CoCreateRender = {
|
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
let renderKey = template.getAttribute('render-key') || type;
|
|
135
|
-
|
|
136
|
+
|
|
137
|
+
if (!template.renderedKeys)
|
|
138
|
+
template.renderedKeys = new Map()
|
|
139
|
+
|
|
136
140
|
if (isRenderObject && type) {
|
|
137
141
|
let Data = self.__getValueFromObject(arrayData, type);
|
|
138
142
|
let array = self.isRenderObject(Data, renderKey)
|
|
139
143
|
for (let item of array) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
144
|
+
if (!template.renderedKeys.has(item[renderKey].key)){
|
|
145
|
+
template.renderedKeys.set(item[renderKey].key, '')
|
|
146
|
+
let cloneEl = this.cloneEl(template);
|
|
147
|
+
self.setValue([cloneEl], item, renderArray, renderKey);
|
|
148
|
+
template.insertAdjacentElement('beforebegin', cloneEl);
|
|
149
|
+
}
|
|
143
150
|
}
|
|
144
151
|
} else {
|
|
145
152
|
|
|
@@ -154,10 +161,14 @@ const CoCreateRender = {
|
|
|
154
161
|
|
|
155
162
|
if(type && Array.isArray(arrayData)) {
|
|
156
163
|
arrayData.forEach((item) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
164
|
+
if (!template.renderedKeys.has(item)){
|
|
165
|
+
template.renderedKeys.set(item, '')
|
|
166
|
+
|
|
167
|
+
let cloneEl = this.cloneEl(template);
|
|
168
|
+
let object = self.__createObject(item, renderKey);
|
|
169
|
+
self.setValue([cloneEl], object, renderArray, renderKey);
|
|
170
|
+
template.insertAdjacentElement('beforebegin', cloneEl);
|
|
171
|
+
}
|
|
161
172
|
});
|
|
162
173
|
}
|
|
163
174
|
}
|
|
@@ -265,7 +276,7 @@ const CoCreateRender = {
|
|
|
265
276
|
if(el.childNodes.length > 0) {
|
|
266
277
|
that.setValue(el.childNodes, updateData || data, renderArray, renderKey);
|
|
267
278
|
}
|
|
268
|
-
if (el.classList.contains('template') && !el.hasAttribute('template_id')) {
|
|
279
|
+
if ((el.tagName == 'TEMPLATE' || el.classList.contains('template')) && !el.hasAttribute('template_id')) {
|
|
269
280
|
that.render(el, data);
|
|
270
281
|
}
|
|
271
282
|
// if (el.hasAttribute('render-array') || el.hasAttribute('render-object')) {
|