@cocreate/render 1.8.4 → 1.9.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 +8 -0
- package/demo/render.array.html +4 -3
- package/demo/render.object.html +2 -2
- package/package.json +3 -2
- package/src/index.js +17 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# [1.9.0](https://github.com/CoCreate-app/CoCreate-render/compare/v1.8.4...v1.9.0) (2022-07-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* added @cocreate/utils queryDocumentSelector to return an element from ann irframe or parent of iframe ([b9bb90f](https://github.com/CoCreate-app/CoCreate-render/commit/b9bb90f9ab72fc24fc71e64a37bcfee73a0c0c9c))
|
|
7
|
+
* support for value-type attribute to define if render will be a string, text, innerHTML. Defaults to innerHTML ([a14fcc2](https://github.com/CoCreate-app/CoCreate-render/commit/a14fcc2ff886df7207c537cca67c3343be2da997))
|
|
8
|
+
|
|
1
9
|
## [1.8.4](https://github.com/CoCreate-app/CoCreate-render/compare/v1.8.3...v1.8.4) (2022-06-19)
|
|
2
10
|
|
|
3
11
|
|
package/demo/render.array.html
CHANGED
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
</cc-options>
|
|
20
20
|
|
|
21
21
|
<div class="template" template_id="abc1">
|
|
22
|
-
<div class="template" render-array="data.
|
|
23
|
-
<h3>{{current_org}}</h3>
|
|
22
|
+
<div class="template" render-array="data.current" render-key="current_org" value="{{current_org.name}}">
|
|
23
|
+
<h3>{{current_org.name}}</h3>
|
|
24
24
|
</div>
|
|
25
25
|
</div>
|
|
26
26
|
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
collection : 'dededede',
|
|
35
35
|
data: [{
|
|
36
36
|
_id : '123kijfhgfkel45',
|
|
37
|
-
current_org: ['test1', 'test2', 'test31', 'test3']
|
|
37
|
+
current_org: ['test1', 'test2', 'test31', 'test3'],
|
|
38
|
+
current: [{name: 'test1w'}, {name: 'test2'}, {name: 'test31'}, {name: 'test3'}]
|
|
38
39
|
}]
|
|
39
40
|
}
|
|
40
41
|
|
package/demo/render.object.html
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
<body>
|
|
12
12
|
|
|
13
13
|
<div class="template" template_id="abc1">
|
|
14
|
-
<div>{{data}}</div>
|
|
15
|
-
<h1> {{data.collection}} {{data._id}}</h1>
|
|
14
|
+
<!-- <div>{{data}}</div>
|
|
15
|
+
<h1> {{data.collection}} {{data._id}}</h1> -->
|
|
16
16
|
<div class="template" render-object="" render-key="one">
|
|
17
17
|
<h5>{{one.key}}: {{one.value}}</h5>
|
|
18
18
|
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/render",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.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",
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@cocreate/actions": "^1.4.3",
|
|
65
65
|
"@cocreate/api": "^1.3.3",
|
|
66
|
-
"@cocreate/docs": "^1.3.3"
|
|
66
|
+
"@cocreate/docs": "^1.3.3",
|
|
67
|
+
"@cocreate/utils": "^1.8.1"
|
|
67
68
|
}
|
|
68
69
|
}
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/*globals CustomEvent*/
|
|
2
2
|
import action from '@cocreate/actions';
|
|
3
|
+
import { queryDocumentSelector } from '@cocreate/utils';
|
|
3
4
|
// import api from '@cocreate/api';
|
|
4
5
|
|
|
5
6
|
const CoCreateRender = {
|
|
@@ -161,6 +162,13 @@ const CoCreateRender = {
|
|
|
161
162
|
}
|
|
162
163
|
});
|
|
163
164
|
|
|
165
|
+
// if (el.classList.contains('template')) {
|
|
166
|
+
// that.render(el, data);
|
|
167
|
+
// }
|
|
168
|
+
// if(el.childNodes.length > 0) {
|
|
169
|
+
// that.setValue(el.childNodes, data, renderKey);
|
|
170
|
+
// }
|
|
171
|
+
|
|
164
172
|
if(el.childNodes.length > 0) {
|
|
165
173
|
that.setValue(el.childNodes, data, renderKey);
|
|
166
174
|
}
|
|
@@ -170,12 +178,17 @@ const CoCreateRender = {
|
|
|
170
178
|
}
|
|
171
179
|
|
|
172
180
|
if (el.nodeType == 3) {
|
|
181
|
+
let valueType = el.parentElement.getAttribute('value-type')
|
|
173
182
|
let textContent = el.textContent;
|
|
174
183
|
let text = that.__replaceValue(data, textContent, renderKey);
|
|
175
184
|
if (text || text == "") {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
185
|
+
if (valueType == 'text' || valueType == 'string'){
|
|
186
|
+
el.textContent = text;
|
|
187
|
+
} else {
|
|
188
|
+
const newNode = document.createElement('div');
|
|
189
|
+
newNode.innerHTML = text;
|
|
190
|
+
el.replaceWith(...newNode.childNodes)
|
|
191
|
+
}
|
|
179
192
|
}
|
|
180
193
|
}
|
|
181
194
|
|
|
@@ -184,7 +197,7 @@ const CoCreateRender = {
|
|
|
184
197
|
|
|
185
198
|
data: function({selector, data, elements}) {
|
|
186
199
|
if (selector) {
|
|
187
|
-
let template =
|
|
200
|
+
let template = queryDocumentSelector(selector);
|
|
188
201
|
if (!template) return;
|
|
189
202
|
if (template.classList.contains('template')) {
|
|
190
203
|
this.render(template, data);
|