@cocreate/render 1.8.1 → 1.8.4
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 +22 -0
- package/demo/render.array.html +2 -1
- package/docs/index.html +1 -1
- package/package.json +4 -4
- package/src/index.js +15 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## [1.8.4](https://github.com/CoCreate-app/CoCreate-render/compare/v1.8.3...v1.8.4) (2022-06-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* update templates to use placeholder ([9299cce](https://github.com/CoCreate-app/CoCreate-render/commit/9299ccef3864ffe087044a3614aa35799e89f31c))
|
|
7
|
+
|
|
8
|
+
## [1.8.3](https://github.com/CoCreate-app/CoCreate-render/compare/v1.8.2...v1.8.3) (2022-06-18)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* bump dependencies ([a9db63c](https://github.com/CoCreate-app/CoCreate-render/commit/a9db63c1c00c5df943151e122ffef310c2aa17d7))
|
|
14
|
+
|
|
15
|
+
## [1.8.2](https://github.com/CoCreate-app/CoCreate-render/compare/v1.8.1...v1.8.2) (2022-06-12)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* update dependencies ([ee5da83](https://github.com/CoCreate-app/CoCreate-render/commit/ee5da83168821d569463913953fb1359fbd8e02a))
|
|
21
|
+
* update docs css document_id ([c4b7eca](https://github.com/CoCreate-app/CoCreate-render/commit/c4b7eca6ae528a04062d2a5858461b59285d0543))
|
|
22
|
+
|
|
1
23
|
## [1.8.1](https://github.com/CoCreate-app/CoCreate-render/compare/v1.8.0...v1.8.1) (2022-05-23)
|
|
2
24
|
|
|
3
25
|
|
package/demo/render.array.html
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
<body>
|
|
12
12
|
|
|
13
13
|
<body>
|
|
14
|
-
<
|
|
14
|
+
<filter template_id="domains" filter-name="_id" filter-value="5ff747727005da1c272740ab"></filter>
|
|
15
|
+
<cc-options fetch-collection="organizations" fetch-name="domains" template_id="domains" class="overflow:auto">
|
|
15
16
|
<cc-option class="template display:flex" template_id="domains" value="{{domains}}">
|
|
16
17
|
<h4>{{domains}}</h4>
|
|
17
18
|
</cc-option>
|
package/docs/index.html
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
<!-- CoCreate CSS -->
|
|
16
16
|
<link rel="stylesheet" href="https://cdn.cocreate.app/latest/CoCreate.min.css" type="text/css" />
|
|
17
|
-
<link rel="stylesheet" href="/docs/index.css" collection="files" document_id="
|
|
17
|
+
<link rel="stylesheet" href="/docs/index.css" collection="files" document_id="60888216117c640e7596303f" name="src" type="text/css" save="true" />
|
|
18
18
|
</head>
|
|
19
19
|
|
|
20
20
|
<body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/render",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.4",
|
|
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,8 +61,8 @@
|
|
|
61
61
|
"webpack-log": "^3.0.1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@cocreate/actions": "^1.4.
|
|
65
|
-
"@cocreate/api": "^1.3.
|
|
66
|
-
"@cocreate/docs": "^1.3.
|
|
64
|
+
"@cocreate/actions": "^1.4.3",
|
|
65
|
+
"@cocreate/api": "^1.3.3",
|
|
66
|
+
"@cocreate/docs": "^1.3.3"
|
|
67
67
|
}
|
|
68
68
|
}
|
package/src/index.js
CHANGED
|
@@ -48,7 +48,7 @@ const CoCreateRender = {
|
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
|
|
51
|
-
__replaceValue: function(data, inputValue) {
|
|
51
|
+
__replaceValue: function(data, inputValue, renderKey) {
|
|
52
52
|
let isPass = false;
|
|
53
53
|
let self = this;
|
|
54
54
|
let resultValue = null;
|
|
@@ -71,6 +71,9 @@ const CoCreateRender = {
|
|
|
71
71
|
isPass = true;
|
|
72
72
|
inputValue = inputValue.replace(attr, value);
|
|
73
73
|
}
|
|
74
|
+
if (!isPass && renderKey && attr.includes(`{{${renderKey}.`)) {
|
|
75
|
+
resultValue = '';
|
|
76
|
+
}
|
|
74
77
|
});
|
|
75
78
|
|
|
76
79
|
if (isPass) {
|
|
@@ -82,7 +85,7 @@ const CoCreateRender = {
|
|
|
82
85
|
|
|
83
86
|
render: function(template, data) {
|
|
84
87
|
let type = template.getAttribute('render-array') || "data";
|
|
85
|
-
const
|
|
88
|
+
const renderKey = template.getAttribute('render-key') || type;
|
|
86
89
|
const self = this;
|
|
87
90
|
|
|
88
91
|
// const arrayData = this.__getValueFromObject(data, type);
|
|
@@ -118,7 +121,7 @@ const CoCreateRender = {
|
|
|
118
121
|
if (!arrayData) {
|
|
119
122
|
let cloneEl = this.cloneEl(template);
|
|
120
123
|
cloneEl.classList.add('cloned');
|
|
121
|
-
self.setValue([cloneEl], data);
|
|
124
|
+
self.setValue([cloneEl], data, renderKey);
|
|
122
125
|
template.insertAdjacentHTML('beforebegin', cloneEl.outerHTML);
|
|
123
126
|
}
|
|
124
127
|
|
|
@@ -126,9 +129,9 @@ const CoCreateRender = {
|
|
|
126
129
|
arrayData.forEach((item) => {
|
|
127
130
|
let cloneEl = this.cloneEl(template);
|
|
128
131
|
cloneEl.classList.add('clone_' + type);
|
|
129
|
-
let r_data = self.__createObject(item,
|
|
132
|
+
let r_data = self.__createObject(item, renderKey);
|
|
130
133
|
|
|
131
|
-
self.setValue([cloneEl], r_data);
|
|
134
|
+
self.setValue([cloneEl], r_data, renderKey);
|
|
132
135
|
template.insertAdjacentHTML('beforebegin', cloneEl.outerHTML);
|
|
133
136
|
});
|
|
134
137
|
}
|
|
@@ -143,7 +146,7 @@ const CoCreateRender = {
|
|
|
143
146
|
return cloneEl;
|
|
144
147
|
},
|
|
145
148
|
|
|
146
|
-
setValue:function(els, data,
|
|
149
|
+
setValue:function(els, data, renderKey){
|
|
147
150
|
if (!data) return;
|
|
148
151
|
const that = this;
|
|
149
152
|
Array.from(els).forEach(el => {
|
|
@@ -151,15 +154,15 @@ const CoCreateRender = {
|
|
|
151
154
|
Array.from(el.attributes).forEach(attr=>{
|
|
152
155
|
let attr_name = attr.name.toLowerCase();
|
|
153
156
|
let attrValue = attr.value;
|
|
154
|
-
attrValue = that.__replaceValue(data, attrValue);
|
|
157
|
+
attrValue = that.__replaceValue(data, attrValue, renderKey);
|
|
155
158
|
|
|
156
|
-
if (attrValue) {
|
|
159
|
+
if (attrValue || attrValue == "") {
|
|
157
160
|
el.setAttribute(attr_name, attrValue);
|
|
158
161
|
}
|
|
159
162
|
});
|
|
160
163
|
|
|
161
164
|
if(el.childNodes.length > 0) {
|
|
162
|
-
that.setValue(el.childNodes, data,
|
|
165
|
+
that.setValue(el.childNodes, data, renderKey);
|
|
163
166
|
}
|
|
164
167
|
if (el.classList.contains('template')) {
|
|
165
168
|
that.render(el, data);
|
|
@@ -168,8 +171,8 @@ const CoCreateRender = {
|
|
|
168
171
|
|
|
169
172
|
if (el.nodeType == 3) {
|
|
170
173
|
let textContent = el.textContent;
|
|
171
|
-
let text = that.__replaceValue(data, textContent);
|
|
172
|
-
if (text) {
|
|
174
|
+
let text = that.__replaceValue(data, textContent, renderKey);
|
|
175
|
+
if (text || text == "") {
|
|
173
176
|
const newNode = document.createElement('div');
|
|
174
177
|
newNode.innerHTML = text;
|
|
175
178
|
el.replaceWith(...newNode.childNodes)
|
|
@@ -187,7 +190,7 @@ const CoCreateRender = {
|
|
|
187
190
|
this.render(template, data);
|
|
188
191
|
}
|
|
189
192
|
else
|
|
190
|
-
this.setValue([template], data
|
|
193
|
+
this.setValue([template], data);
|
|
191
194
|
} else if (elements) {
|
|
192
195
|
this.setValue(elements, data);
|
|
193
196
|
}
|