@cocreate/render 1.12.3 → 1.14.1
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 +5 -5
- package/src/index.css +1 -1
- package/src/index.js +62 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
## [1.14.1](https://github.com/CoCreate-app/CoCreate-render/compare/v1.14.0...v1.14.1) (2022-09-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* bump all of [@cocreate](https://github.com/cocreate) dependencies ([bfc8fd9](https://github.com/CoCreate-app/CoCreate-render/commit/bfc8fd933a783a66b177ca0633f974fc3df2d335))
|
|
7
|
+
|
|
8
|
+
# [1.14.0](https://github.com/CoCreate-app/CoCreate-render/compare/v1.13.0...v1.14.0) (2022-08-31)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* document_id was not inserting on some of the nested elements ([0ef42c7](https://github.com/CoCreate-app/CoCreate-render/commit/0ef42c73100f1af539c82c8cd0968c34c88655e6))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* render collection and document_id with and without a renderKey ([1f80cf3](https://github.com/CoCreate-app/CoCreate-render/commit/1f80cf3f224f9b894a9107bd009993f9673879c0))
|
|
19
|
+
|
|
20
|
+
# [1.13.0](https://github.com/CoCreate-app/CoCreate-render/compare/v1.12.3...v1.13.0) (2022-08-23)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* 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))
|
|
26
|
+
|
|
1
27
|
## [1.12.3](https://github.com/CoCreate-app/CoCreate-render/compare/v1.12.2...v1.12.3) (2022-08-19)
|
|
2
28
|
|
|
3
29
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/render",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.1",
|
|
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",
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"webpack-log": "^3.0.1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@cocreate/actions": "^1.
|
|
65
|
-
"@cocreate/api": "^1.3.
|
|
66
|
-
"@cocreate/docs": "^1.3.
|
|
67
|
-
"@cocreate/utils": "^1.
|
|
64
|
+
"@cocreate/actions": "^1.5.0",
|
|
65
|
+
"@cocreate/api": "^1.3.5",
|
|
66
|
+
"@cocreate/docs": "^1.3.5",
|
|
67
|
+
"@cocreate/utils": "^1.10.0"
|
|
68
68
|
}
|
|
69
69
|
}
|
package/src/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.template {display: none !important;}
|
|
1
|
+
.template, [template] {display: none !important;}
|
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;
|
|
@@ -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)
|
|
@@ -114,6 +117,7 @@ const CoCreateRender = {
|
|
|
114
117
|
|
|
115
118
|
render: function(template, data) {
|
|
116
119
|
const self = this;
|
|
120
|
+
const templateId = template.getAttribute('templateId')
|
|
117
121
|
let type = '';
|
|
118
122
|
let arrayData = data;
|
|
119
123
|
|
|
@@ -132,14 +136,20 @@ const CoCreateRender = {
|
|
|
132
136
|
}
|
|
133
137
|
|
|
134
138
|
let renderKey = template.getAttribute('render-key') || type;
|
|
135
|
-
|
|
139
|
+
|
|
140
|
+
if (!template.renderedKeys)
|
|
141
|
+
template.renderedKeys = new Map()
|
|
142
|
+
|
|
136
143
|
if (isRenderObject && type) {
|
|
137
144
|
let Data = self.__getValueFromObject(arrayData, type);
|
|
138
145
|
let array = self.isRenderObject(Data, renderKey)
|
|
139
146
|
for (let item of array) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
}
|
|
143
153
|
}
|
|
144
154
|
} else {
|
|
145
155
|
|
|
@@ -154,10 +164,14 @@ const CoCreateRender = {
|
|
|
154
164
|
|
|
155
165
|
if(type && Array.isArray(arrayData)) {
|
|
156
166
|
arrayData.forEach((item) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
+
}
|
|
161
175
|
});
|
|
162
176
|
}
|
|
163
177
|
}
|
|
@@ -183,12 +197,24 @@ const CoCreateRender = {
|
|
|
183
197
|
let cloneEl = template.cloneNode(true);
|
|
184
198
|
|
|
185
199
|
let templateId = cloneEl.getAttribute('template_id');
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
+
}
|
|
190
217
|
cloneEl.setAttribute('render-clone', '');
|
|
191
|
-
cloneEl.classList.remove('template');
|
|
192
218
|
|
|
193
219
|
if (template.dataOriginal)
|
|
194
220
|
cloneEl.dataOriginal = template.dataOriginal
|
|
@@ -196,11 +222,19 @@ const CoCreateRender = {
|
|
|
196
222
|
return cloneEl;
|
|
197
223
|
},
|
|
198
224
|
|
|
225
|
+
document_id: '',
|
|
199
226
|
setValue: function(els, data, renderArray, renderKey){
|
|
200
227
|
if (!data) return;
|
|
228
|
+
|
|
201
229
|
let isRenderKey
|
|
202
230
|
if (data.renderKey)
|
|
203
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;
|
|
204
238
|
|
|
205
239
|
const that = this;
|
|
206
240
|
Array.from(els).forEach(el => {
|
|
@@ -265,7 +299,7 @@ const CoCreateRender = {
|
|
|
265
299
|
if(el.childNodes.length > 0) {
|
|
266
300
|
that.setValue(el.childNodes, updateData || data, renderArray, renderKey);
|
|
267
301
|
}
|
|
268
|
-
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')) {
|
|
269
303
|
that.render(el, data);
|
|
270
304
|
}
|
|
271
305
|
// if (el.hasAttribute('render-array') || el.hasAttribute('render-object')) {
|
|
@@ -339,10 +373,10 @@ const CoCreateRender = {
|
|
|
339
373
|
if (selector) {
|
|
340
374
|
let template = queryDocumentSelector(selector);
|
|
341
375
|
if (!template) return;
|
|
342
|
-
if (template.tagNmae === 'TEMPLATE')
|
|
343
|
-
|
|
376
|
+
// if (template.tagNmae === 'TEMPLATE')
|
|
377
|
+
// template = template.childNodes;
|
|
344
378
|
template.dataOriginal = {...data}
|
|
345
|
-
if (template.classList.contains('template')) {
|
|
379
|
+
if (template.tagName == 'TEMPLATE' || template.hasAttribute('template') || template.classList.contains('template')) {
|
|
346
380
|
this.render(template, data);
|
|
347
381
|
}
|
|
348
382
|
else
|
|
@@ -351,7 +385,7 @@ const CoCreateRender = {
|
|
|
351
385
|
for (let element of elements)
|
|
352
386
|
element.dataOriginal = {...this.dataOriginal};
|
|
353
387
|
|
|
354
|
-
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'))){
|
|
355
389
|
this.render(elements[0], data);
|
|
356
390
|
}
|
|
357
391
|
else
|
|
@@ -450,6 +484,9 @@ observer.init({
|
|
|
450
484
|
for (let data of array.reverse()){
|
|
451
485
|
obj = {...obj, ...data}
|
|
452
486
|
}
|
|
487
|
+
|
|
488
|
+
// if (!obj['document_id'] && obj.data._id)
|
|
489
|
+
// obj['document_id'] = obj.data._id
|
|
453
490
|
|
|
454
491
|
CoCreateRender.data({
|
|
455
492
|
elements: [element],
|