@cocreate/render 1.12.2 → 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 +26 -0
- package/package.json +1 -1
- package/src/index.css +1 -0
- package/src/index.js +63 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
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
|
+
|
|
13
|
+
# [1.13.0](https://github.com/CoCreate-app/CoCreate-render/compare/v1.12.3...v1.13.0) (2022-08-23)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* 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))
|
|
19
|
+
|
|
20
|
+
## [1.12.3](https://github.com/CoCreate-app/CoCreate-render/compare/v1.12.2...v1.12.3) (2022-08-19)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* add css file for class template display none ([4cfa7ee](https://github.com/CoCreate-app/CoCreate-render/commit/4cfa7ee8a6a1d4105f9144ce713a3435db4090f6))
|
|
26
|
+
|
|
1
27
|
## [1.12.2](https://github.com/CoCreate-app/CoCreate-render/compare/v1.12.1...v1.12.2) (2022-08-01)
|
|
2
28
|
|
|
3
29
|
|
package/package.json
CHANGED
package/src/index.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.template, [template] {display: none !important;}
|
package/src/index.js
CHANGED
|
@@ -3,12 +3,13 @@ import action from '@cocreate/actions';
|
|
|
3
3
|
import observer from '@cocreate/observer';
|
|
4
4
|
import uuid from '@cocreate/uuid';
|
|
5
5
|
import { queryDocumentSelector } from '@cocreate/utils';
|
|
6
|
+
import './index.css';
|
|
6
7
|
// import { getValue } from '../../CoCreate-elements/src/getValue';
|
|
7
8
|
// import api from '@cocreate/api';
|
|
8
9
|
|
|
9
10
|
const CoCreateRender = {
|
|
10
11
|
// Can be called from crud getObjectValueByPath
|
|
11
|
-
__getValueFromObject
|
|
12
|
+
__getValueFromObject: function(json, path) {
|
|
12
13
|
try {
|
|
13
14
|
if(typeof json == 'undefined' || !path)
|
|
14
15
|
return false;
|
|
@@ -40,7 +41,6 @@ const CoCreateRender = {
|
|
|
40
41
|
return this.__getValueFromObject(data, result[1].trim());
|
|
41
42
|
}
|
|
42
43
|
return false;
|
|
43
|
-
|
|
44
44
|
},
|
|
45
45
|
|
|
46
46
|
__createObject: function (data, path) {
|
|
@@ -68,11 +68,15 @@ const CoCreateRender = {
|
|
|
68
68
|
let variables = inputValue.match(/{{([A-Za-z0-9_.,\[\]\- ]*)}}/g);
|
|
69
69
|
if (variables) {
|
|
70
70
|
variables.forEach((attr) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
+
|
|
76
80
|
if (value) {
|
|
77
81
|
if (typeof(value) == "object") {
|
|
78
82
|
value = this.generateString(value)
|
|
@@ -113,6 +117,7 @@ const CoCreateRender = {
|
|
|
113
117
|
|
|
114
118
|
render: function(template, data) {
|
|
115
119
|
const self = this;
|
|
120
|
+
const templateId = template.getAttribute('templateId')
|
|
116
121
|
let type = '';
|
|
117
122
|
let arrayData = data;
|
|
118
123
|
|
|
@@ -131,14 +136,20 @@ const CoCreateRender = {
|
|
|
131
136
|
}
|
|
132
137
|
|
|
133
138
|
let renderKey = template.getAttribute('render-key') || type;
|
|
134
|
-
|
|
139
|
+
|
|
140
|
+
if (!template.renderedKeys)
|
|
141
|
+
template.renderedKeys = new Map()
|
|
142
|
+
|
|
135
143
|
if (isRenderObject && type) {
|
|
136
144
|
let Data = self.__getValueFromObject(arrayData, type);
|
|
137
145
|
let array = self.isRenderObject(Data, renderKey)
|
|
138
146
|
for (let item of array) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
147
|
+
if (!template.renderedKeys.has(item[renderKey].key)){
|
|
148
|
+
template.renderedKeys.set(item[renderKey].key, '')
|
|
149
|
+
let cloneEl = this.cloneEl(template);
|
|
150
|
+
self.setValue([cloneEl], item, renderArray, renderKey);
|
|
151
|
+
template.insertAdjacentElement('beforebegin', cloneEl);
|
|
152
|
+
}
|
|
142
153
|
}
|
|
143
154
|
} else {
|
|
144
155
|
|
|
@@ -153,10 +164,14 @@ const CoCreateRender = {
|
|
|
153
164
|
|
|
154
165
|
if(type && Array.isArray(arrayData)) {
|
|
155
166
|
arrayData.forEach((item) => {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
167
|
+
if (!template.renderedKeys.has(item)){
|
|
168
|
+
template.renderedKeys.set(item, '')
|
|
169
|
+
|
|
170
|
+
let cloneEl = this.cloneEl(template);
|
|
171
|
+
let object = self.__createObject(item, renderKey);
|
|
172
|
+
self.setValue([cloneEl], object, renderArray, renderKey);
|
|
173
|
+
template.insertAdjacentElement('beforebegin', cloneEl);
|
|
174
|
+
}
|
|
160
175
|
});
|
|
161
176
|
}
|
|
162
177
|
}
|
|
@@ -182,12 +197,24 @@ const CoCreateRender = {
|
|
|
182
197
|
let cloneEl = template.cloneNode(true);
|
|
183
198
|
|
|
184
199
|
let templateId = cloneEl.getAttribute('template_id');
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
+
}
|
|
189
217
|
cloneEl.setAttribute('render-clone', '');
|
|
190
|
-
cloneEl.classList.remove('template');
|
|
191
218
|
|
|
192
219
|
if (template.dataOriginal)
|
|
193
220
|
cloneEl.dataOriginal = template.dataOriginal
|
|
@@ -195,11 +222,19 @@ const CoCreateRender = {
|
|
|
195
222
|
return cloneEl;
|
|
196
223
|
},
|
|
197
224
|
|
|
225
|
+
document_id: '',
|
|
198
226
|
setValue: function(els, data, renderArray, renderKey){
|
|
199
227
|
if (!data) return;
|
|
228
|
+
|
|
200
229
|
let isRenderKey
|
|
201
230
|
if (data.renderKey)
|
|
202
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;
|
|
203
238
|
|
|
204
239
|
const that = this;
|
|
205
240
|
Array.from(els).forEach(el => {
|
|
@@ -264,7 +299,7 @@ const CoCreateRender = {
|
|
|
264
299
|
if(el.childNodes.length > 0) {
|
|
265
300
|
that.setValue(el.childNodes, updateData || data, renderArray, renderKey);
|
|
266
301
|
}
|
|
267
|
-
if (el.classList.contains('template') && !el.hasAttribute('template_id')) {
|
|
302
|
+
if ((el.tagName == 'TEMPLATE' || el.hasAttribute('template') || el.classList.contains('template')) && !el.hasAttribute('template_id')) {
|
|
268
303
|
that.render(el, data);
|
|
269
304
|
}
|
|
270
305
|
// if (el.hasAttribute('render-array') || el.hasAttribute('render-object')) {
|
|
@@ -338,8 +373,10 @@ const CoCreateRender = {
|
|
|
338
373
|
if (selector) {
|
|
339
374
|
let template = queryDocumentSelector(selector);
|
|
340
375
|
if (!template) return;
|
|
376
|
+
// if (template.tagNmae === 'TEMPLATE')
|
|
377
|
+
// template = template.childNodes;
|
|
341
378
|
template.dataOriginal = {...data}
|
|
342
|
-
if (template.classList.contains('template')) {
|
|
379
|
+
if (template.tagName == 'TEMPLATE' || template.hasAttribute('template') || template.classList.contains('template')) {
|
|
343
380
|
this.render(template, data);
|
|
344
381
|
}
|
|
345
382
|
else
|
|
@@ -348,7 +385,7 @@ const CoCreateRender = {
|
|
|
348
385
|
for (let element of elements)
|
|
349
386
|
element.dataOriginal = {...this.dataOriginal};
|
|
350
387
|
|
|
351
|
-
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'))){
|
|
352
389
|
this.render(elements[0], data);
|
|
353
390
|
}
|
|
354
391
|
else
|
|
@@ -447,6 +484,9 @@ observer.init({
|
|
|
447
484
|
for (let data of array.reverse()){
|
|
448
485
|
obj = {...obj, ...data}
|
|
449
486
|
}
|
|
487
|
+
|
|
488
|
+
// if (!obj['document_id'] && obj.data._id)
|
|
489
|
+
// obj['document_id'] = obj.data._id
|
|
450
490
|
|
|
451
491
|
CoCreateRender.data({
|
|
452
492
|
elements: [element],
|