@cocreate/render 1.13.0 → 1.14.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 +12 -0
- package/package.json +1 -1
- package/src/index.css +1 -1
- package/src/index.js +42 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# [1.14.0](https://github.com/CoCreate-app/CoCreate-render/compare/v1.13.0...v1.14.0) (2022-08-31)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* document_id was not inserting on some of the nested elements ([0ef42c7](https://github.com/CoCreate-app/CoCreate-render/commit/0ef42c73100f1af539c82c8cd0968c34c88655e6))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* render collection and document_id with and without a renderKey ([1f80cf3](https://github.com/CoCreate-app/CoCreate-render/commit/1f80cf3f224f9b894a9107bd009993f9673879c0))
|
|
12
|
+
|
|
1
13
|
# [1.13.0](https://github.com/CoCreate-app/CoCreate-render/compare/v1.12.3...v1.13.0) (2022-08-23)
|
|
2
14
|
|
|
3
15
|
|
package/package.json
CHANGED
package/src/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.template {display: none !important;}
|
|
1
|
+
.template, [template] {display: none !important;}
|
package/src/index.js
CHANGED
|
@@ -41,7 +41,6 @@ const CoCreateRender = {
|
|
|
41
41
|
return this.__getValueFromObject(data, result[1].trim());
|
|
42
42
|
}
|
|
43
43
|
return false;
|
|
44
|
-
|
|
45
44
|
},
|
|
46
45
|
|
|
47
46
|
__createObject: function (data, path) {
|
|
@@ -69,11 +68,15 @@ const CoCreateRender = {
|
|
|
69
68
|
let variables = inputValue.match(/{{([A-Za-z0-9_.,\[\]\- ]*)}}/g);
|
|
70
69
|
if (variables) {
|
|
71
70
|
variables.forEach((attr) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
let value;
|
|
72
|
+
|
|
73
|
+
if (attr == "{{data._id}}" || attr == `{{${renderKey}._id}}` || attr == "{{document_id}}")
|
|
74
|
+
value = this.document_id;
|
|
75
|
+
else if (attr == "{{collection}" || attr == `{{${renderKey}.collection}}`)
|
|
76
|
+
value = this.collection;
|
|
77
|
+
else
|
|
78
|
+
value = self.__getValue(data, attr);
|
|
79
|
+
|
|
77
80
|
if (value) {
|
|
78
81
|
if (typeof(value) == "object") {
|
|
79
82
|
value = this.generateString(value)
|
|
@@ -194,12 +197,24 @@ const CoCreateRender = {
|
|
|
194
197
|
let cloneEl = template.cloneNode(true);
|
|
195
198
|
|
|
196
199
|
let templateId = cloneEl.getAttribute('template_id');
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
200
|
+
if (templateId) {
|
|
201
|
+
cloneEl.setAttribute('templateId', templateId);
|
|
202
|
+
cloneEl.removeAttribute('template_id');
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if(cloneEl.tagName == 'TEMPLATE'){
|
|
206
|
+
cloneEl = template.content.firstElementChild
|
|
207
|
+
for (let attribute of template.attributes){
|
|
208
|
+
let attrName = attribute.name;
|
|
209
|
+
let attrValue = attribute.value || '';
|
|
210
|
+
cloneEl.setAttribute(attrName, attrValue);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
cloneEl.classList.remove('template');
|
|
215
|
+
cloneEl.removeAttribute('template');
|
|
216
|
+
}
|
|
201
217
|
cloneEl.setAttribute('render-clone', '');
|
|
202
|
-
cloneEl.classList.remove('template');
|
|
203
218
|
|
|
204
219
|
if (template.dataOriginal)
|
|
205
220
|
cloneEl.dataOriginal = template.dataOriginal
|
|
@@ -207,11 +222,19 @@ const CoCreateRender = {
|
|
|
207
222
|
return cloneEl;
|
|
208
223
|
},
|
|
209
224
|
|
|
225
|
+
document_id: '',
|
|
210
226
|
setValue: function(els, data, renderArray, renderKey){
|
|
211
227
|
if (!data) return;
|
|
228
|
+
|
|
212
229
|
let isRenderKey
|
|
213
230
|
if (data.renderKey)
|
|
214
231
|
isRenderKey = true
|
|
232
|
+
|
|
233
|
+
if (data.data && data.data._id )
|
|
234
|
+
this.document_id = data.data._id;
|
|
235
|
+
|
|
236
|
+
if (data.collection)
|
|
237
|
+
this.collection = data.collection;
|
|
215
238
|
|
|
216
239
|
const that = this;
|
|
217
240
|
Array.from(els).forEach(el => {
|
|
@@ -276,7 +299,7 @@ const CoCreateRender = {
|
|
|
276
299
|
if(el.childNodes.length > 0) {
|
|
277
300
|
that.setValue(el.childNodes, updateData || data, renderArray, renderKey);
|
|
278
301
|
}
|
|
279
|
-
if ((el.tagName == 'TEMPLATE' || el.classList.contains('template')) && !el.hasAttribute('template_id')) {
|
|
302
|
+
if ((el.tagName == 'TEMPLATE' || el.hasAttribute('template') || el.classList.contains('template')) && !el.hasAttribute('template_id')) {
|
|
280
303
|
that.render(el, data);
|
|
281
304
|
}
|
|
282
305
|
// if (el.hasAttribute('render-array') || el.hasAttribute('render-object')) {
|
|
@@ -350,10 +373,10 @@ const CoCreateRender = {
|
|
|
350
373
|
if (selector) {
|
|
351
374
|
let template = queryDocumentSelector(selector);
|
|
352
375
|
if (!template) return;
|
|
353
|
-
if (template.tagNmae === 'TEMPLATE')
|
|
354
|
-
|
|
376
|
+
// if (template.tagNmae === 'TEMPLATE')
|
|
377
|
+
// template = template.childNodes;
|
|
355
378
|
template.dataOriginal = {...data}
|
|
356
|
-
if (template.classList.contains('template')) {
|
|
379
|
+
if (template.tagName == 'TEMPLATE' || template.hasAttribute('template') || template.classList.contains('template')) {
|
|
357
380
|
this.render(template, data);
|
|
358
381
|
}
|
|
359
382
|
else
|
|
@@ -362,7 +385,7 @@ const CoCreateRender = {
|
|
|
362
385
|
for (let element of elements)
|
|
363
386
|
element.dataOriginal = {...this.dataOriginal};
|
|
364
387
|
|
|
365
|
-
if (elements.length == 1 && elements[0].classList.contains('template')){
|
|
388
|
+
if (elements.length == 1 && (elements[0].tagName == 'TEMPLATE' || elements[0].hasAttribute('template') || elements[0].classList.contains('template'))){
|
|
366
389
|
this.render(elements[0], data);
|
|
367
390
|
}
|
|
368
391
|
else
|
|
@@ -461,6 +484,9 @@ observer.init({
|
|
|
461
484
|
for (let data of array.reverse()){
|
|
462
485
|
obj = {...obj, ...data}
|
|
463
486
|
}
|
|
487
|
+
|
|
488
|
+
// if (!obj['document_id'] && obj.data._id)
|
|
489
|
+
// obj['document_id'] = obj.data._id
|
|
464
490
|
|
|
465
491
|
CoCreateRender.data({
|
|
466
492
|
elements: [element],
|