@cocreate/render 1.16.21 → 1.17.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 +7 -7
- package/src/index.js +22 -43
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
# [1.17.0](https://github.com/CoCreate-app/CoCreate-render/compare/v1.16.21...v1.17.0) (2022-12-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* bump dependencies ([eb9a3c7](https://github.com/CoCreate-app/CoCreate-render/commit/eb9a3c79fadb6bf22829b3d1cf42334530936581))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* render-exclude to define keys to be excluded from rendering. depreciated dataOriginal ([475b641](https://github.com/CoCreate-app/CoCreate-render/commit/475b641c4d37b4d0395142e03baa979df2bf0032))
|
|
12
|
+
|
|
1
13
|
## [1.16.21](https://github.com/CoCreate-app/CoCreate-render/compare/v1.16.20...v1.16.21) (2022-12-09)
|
|
2
14
|
|
|
3
15
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/render",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
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,11 +61,11 @@
|
|
|
61
61
|
"webpack-log": "^3.0.1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@cocreate/actions": "^1.5.
|
|
65
|
-
"@cocreate/api": "^1.5.
|
|
66
|
-
"@cocreate/docs": "^1.4.
|
|
67
|
-
"@cocreate/element-prototype": "^1.1.
|
|
68
|
-
"@cocreate/observer": "^1.5.
|
|
69
|
-
"@cocreate/utils": "^1.15.
|
|
64
|
+
"@cocreate/actions": "^1.5.33",
|
|
65
|
+
"@cocreate/api": "^1.5.20",
|
|
66
|
+
"@cocreate/docs": "^1.4.17",
|
|
67
|
+
"@cocreate/element-prototype": "^1.1.23",
|
|
68
|
+
"@cocreate/observer": "^1.5.37",
|
|
69
|
+
"@cocreate/utils": "^1.15.2"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/src/index.js
CHANGED
|
@@ -91,12 +91,18 @@ const CoCreateRender = {
|
|
|
91
91
|
|
|
92
92
|
render: function(template, data) {
|
|
93
93
|
const self = this;
|
|
94
|
-
const templateId = template.getAttribute('templateId')
|
|
95
94
|
let type = '';
|
|
96
95
|
let arrayData = data;
|
|
97
96
|
|
|
97
|
+
let exclude = template.getAttribute('render-exclude')
|
|
98
|
+
if (exclude) {
|
|
99
|
+
exclude = exclude.replace(/ /g, '').split(",")
|
|
100
|
+
if (!Array.isArray(exclude))
|
|
101
|
+
exclude = [exclude]
|
|
102
|
+
}
|
|
103
|
+
|
|
98
104
|
const isRenderObject = template.hasAttribute('render-object');
|
|
99
|
-
if (isRenderObject){
|
|
105
|
+
if (isRenderObject) {
|
|
100
106
|
const renderObject = template.getAttribute('render-object');
|
|
101
107
|
type = renderObject || ''
|
|
102
108
|
}
|
|
@@ -115,8 +121,8 @@ const CoCreateRender = {
|
|
|
115
121
|
template.renderedKeys = new Map()
|
|
116
122
|
|
|
117
123
|
if (isRenderObject && type) {
|
|
118
|
-
let Data =
|
|
119
|
-
let array = self.
|
|
124
|
+
let Data = getValueFromObject(arrayData, type);
|
|
125
|
+
let array = self.renderObject(Data, renderKey, exclude)
|
|
120
126
|
for (let item of array) {
|
|
121
127
|
if (!template.renderedKeys.has(item[renderKey].key)){
|
|
122
128
|
template.renderedKeys.set(item[renderKey].key, '')
|
|
@@ -155,18 +161,20 @@ const CoCreateRender = {
|
|
|
155
161
|
}
|
|
156
162
|
},
|
|
157
163
|
|
|
158
|
-
|
|
164
|
+
renderObject: function(data, renderKey, exclude) {
|
|
159
165
|
let array = []
|
|
160
166
|
if (!data)
|
|
161
167
|
return array
|
|
162
168
|
for (const [key, value] of Object.entries(data)) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
169
|
+
if (!exclude.includes(key)) {
|
|
170
|
+
let type = 'string';
|
|
171
|
+
if (typeof(value) == "object")
|
|
172
|
+
if (Array.isArray(value))
|
|
173
|
+
type = 'array'
|
|
174
|
+
else
|
|
175
|
+
type = 'object'
|
|
176
|
+
array.push({[renderKey]: {key, value, type}})
|
|
177
|
+
}
|
|
170
178
|
}
|
|
171
179
|
return array
|
|
172
180
|
},
|
|
@@ -194,9 +202,6 @@ const CoCreateRender = {
|
|
|
194
202
|
}
|
|
195
203
|
cloneEl.setAttribute('render-clone', '');
|
|
196
204
|
|
|
197
|
-
if (template.dataOriginal)
|
|
198
|
-
cloneEl.dataOriginal = template.dataOriginal
|
|
199
|
-
|
|
200
205
|
return cloneEl;
|
|
201
206
|
},
|
|
202
207
|
|
|
@@ -207,12 +212,6 @@ const CoCreateRender = {
|
|
|
207
212
|
let isRenderKey
|
|
208
213
|
if (data.renderKey)
|
|
209
214
|
isRenderKey = true
|
|
210
|
-
|
|
211
|
-
// if (data.document._id)
|
|
212
|
-
// this.document_id = data.document._id;
|
|
213
|
-
|
|
214
|
-
// if (data.collection)
|
|
215
|
-
// this.collection = data.collection;
|
|
216
215
|
|
|
217
216
|
const that = this;
|
|
218
217
|
Array.from(els).forEach(el => {
|
|
@@ -284,11 +283,6 @@ const CoCreateRender = {
|
|
|
284
283
|
if ((el.tagName == 'TEMPLATE' || el.hasAttribute('template') || el.classList.contains('template')) && !el.hasAttribute('template_id')) {
|
|
285
284
|
that.render(el, data);
|
|
286
285
|
}
|
|
287
|
-
// if (el.hasAttribute('render-array') || el.hasAttribute('render-object')) {
|
|
288
|
-
// if (!el.dataOriginal) {
|
|
289
|
-
// that.render(el, data);
|
|
290
|
-
// }
|
|
291
|
-
// }
|
|
292
286
|
|
|
293
287
|
}
|
|
294
288
|
|
|
@@ -349,26 +343,16 @@ const CoCreateRender = {
|
|
|
349
343
|
node['renderMap'].set(node, {placeholder, renderArray, renderKey})
|
|
350
344
|
},
|
|
351
345
|
|
|
352
|
-
dataOriginal: {},
|
|
353
346
|
data: function({selector, data, elements}) {
|
|
354
|
-
this.dataOriginal = {...data};
|
|
355
|
-
delete this.dataOriginal.data
|
|
356
|
-
|
|
357
347
|
if (selector) {
|
|
358
348
|
let template = queryDocumentSelector(selector);
|
|
359
349
|
if (!template) return;
|
|
360
|
-
// if (template.tagNmae === 'TEMPLATE')
|
|
361
|
-
// template = template.childNodes;
|
|
362
|
-
template.dataOriginal = {...data}
|
|
363
350
|
if (template.tagName == 'TEMPLATE' || template.hasAttribute('template') || template.classList.contains('template')) {
|
|
364
351
|
this.render(template, data);
|
|
365
352
|
}
|
|
366
353
|
else
|
|
367
354
|
this.setValue([template], data);
|
|
368
355
|
} else if (elements) {
|
|
369
|
-
for (let element of elements)
|
|
370
|
-
element.dataOriginal = {...this.dataOriginal};
|
|
371
|
-
|
|
372
356
|
if (elements.length == 1 && (elements[0].tagName == 'TEMPLATE' || elements[0].hasAttribute('template') || elements[0].classList.contains('template'))){
|
|
373
357
|
this.render(elements[0], data);
|
|
374
358
|
}
|
|
@@ -419,13 +403,11 @@ observer.init({
|
|
|
419
403
|
let data;
|
|
420
404
|
el = el.parentElement
|
|
421
405
|
if (el) {
|
|
422
|
-
if (el.dataOriginal)
|
|
423
|
-
renderData.set(el.dataOriginal, '')
|
|
424
406
|
if (el.hasAttribute('render-clone'))
|
|
425
407
|
data = el.renderData
|
|
426
|
-
if (data)
|
|
408
|
+
if (data) {
|
|
427
409
|
renderData.set(data, '')
|
|
428
|
-
|
|
410
|
+
}
|
|
429
411
|
let parentKey = el.getAttribute('parentKey')
|
|
430
412
|
if (parentKey && parentKey != null) {
|
|
431
413
|
if (/^\d+$/.test(parentKey))
|
|
@@ -469,9 +451,6 @@ observer.init({
|
|
|
469
451
|
obj = {...obj, ...data}
|
|
470
452
|
}
|
|
471
453
|
|
|
472
|
-
// if (!obj['document_id'] && obj.data._id)
|
|
473
|
-
// obj['document_id'] = obj.data._id
|
|
474
|
-
|
|
475
454
|
CoCreateRender.data({
|
|
476
455
|
elements: [element],
|
|
477
456
|
data: obj
|