@cocreate/render 1.3.22 → 1.4.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 +28 -0
- package/package.json +4 -4
- package/src/index.js +25 -47
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-render/compare/v1.3.25...v1.4.0) (2021-12-31)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* added renderKey function ([dbe7190](https://github.com/CoCreate-app/CoCreate-render/commit/dbe7190e9f358ba8e85f510d326fd31bf03e40a5))
|
|
7
|
+
|
|
8
|
+
## [1.3.25](https://github.com/CoCreate-app/CoCreate-render/compare/v1.3.24...v1.3.25) (2021-12-15)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update dependencies ([ae84466](https://github.com/CoCreate-app/CoCreate-render/commit/ae84466f0b74b208c7455a8deabab79146e3ef34))
|
|
14
|
+
|
|
15
|
+
## [1.3.24](https://github.com/CoCreate-app/CoCreate-render/compare/v1.3.23...v1.3.24) (2021-12-14)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* update dependencies ([8d71aff](https://github.com/CoCreate-app/CoCreate-render/commit/8d71aff411db90ed2feb7231a62a7d36b64c082e))
|
|
21
|
+
|
|
22
|
+
## [1.3.23](https://github.com/CoCreate-app/CoCreate-render/compare/v1.3.22...v1.3.23) (2021-11-27)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* actions import typo ([d041be1](https://github.com/CoCreate-app/CoCreate-render/commit/d041be131927e24da6ed0bcc22ce4ccafcdad289))
|
|
28
|
+
|
|
1
29
|
## [1.3.22](https://github.com/CoCreate-app/CoCreate-render/compare/v1.3.21...v1.3.22) (2021-11-27)
|
|
2
30
|
|
|
3
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/render",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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,8 +61,8 @@
|
|
|
61
61
|
"webpack-log": "^3.0.1"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@cocreate/actions": "^1.3.
|
|
65
|
-
"@cocreate/api": "^1.2.
|
|
66
|
-
"@cocreate/docs": "^1.2.
|
|
64
|
+
"@cocreate/actions": "^1.3.25",
|
|
65
|
+
"@cocreate/api": "^1.2.18",
|
|
66
|
+
"@cocreate/docs": "^1.2.62"
|
|
67
67
|
}
|
|
68
68
|
}
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*globals CustomEvent*/
|
|
2
|
-
import action from '@cocreate/
|
|
3
|
-
|
|
2
|
+
import action from '@cocreate/actions';
|
|
3
|
+
// import CoCreateApi from '@cocreate/api';
|
|
4
4
|
|
|
5
5
|
const CoCreateRender = {
|
|
6
6
|
|
|
@@ -114,41 +114,19 @@ const CoCreateRender = {
|
|
|
114
114
|
return cloneEl;
|
|
115
115
|
},
|
|
116
116
|
|
|
117
|
-
setValue:function(els, data,
|
|
117
|
+
setValue:function(els, data, template){
|
|
118
118
|
if (!data) return;
|
|
119
119
|
const that = this;
|
|
120
120
|
Array.from(els).forEach(el => {
|
|
121
|
-
|
|
122
|
-
// let passId = e.getAttribute('pass_id');
|
|
123
|
-
// if (passTo && passId != passTo) {
|
|
124
|
-
// return;
|
|
125
|
-
// }
|
|
126
121
|
// if (el.classList.contains('template')) {
|
|
127
122
|
// el = this.cloneEl(el);
|
|
128
123
|
// }
|
|
129
124
|
Array.from(el.attributes).forEach(attr=>{
|
|
130
125
|
let attr_name = attr.name.toLowerCase();
|
|
131
|
-
// let isPass = false;
|
|
132
126
|
let attrValue = attr.value;
|
|
133
127
|
attrValue = that.__replaceValue(data, attrValue);
|
|
134
128
|
|
|
135
129
|
if (attrValue) {
|
|
136
|
-
// if(attr_name == 'value'){
|
|
137
|
-
// let tag = e.tagName.toLowerCase();
|
|
138
|
-
// switch (tag) {
|
|
139
|
-
// case 'input':
|
|
140
|
-
// e.setAttribute(attr_name, attrValue);
|
|
141
|
-
// break;
|
|
142
|
-
// case 'textarea':
|
|
143
|
-
// e.setAttribute(attr_name, attrValue);
|
|
144
|
-
// e.textContent = attrValue;
|
|
145
|
-
// break;
|
|
146
|
-
// default:
|
|
147
|
-
// if (e.children.length === 0) {
|
|
148
|
-
// e.innerHTML = attrValue;
|
|
149
|
-
// }
|
|
150
|
-
// }
|
|
151
|
-
// }
|
|
152
130
|
el.setAttribute(attr_name, attrValue);
|
|
153
131
|
}
|
|
154
132
|
});
|
|
@@ -162,7 +140,7 @@ const CoCreateRender = {
|
|
|
162
140
|
}
|
|
163
141
|
|
|
164
142
|
if(el.children.length > 0) {
|
|
165
|
-
that.setValue(el.children, data,
|
|
143
|
+
that.setValue(el.children, data, template);
|
|
166
144
|
}
|
|
167
145
|
if (el.classList.contains('template')) {
|
|
168
146
|
that.render(el, data);
|
|
@@ -171,7 +149,7 @@ const CoCreateRender = {
|
|
|
171
149
|
});
|
|
172
150
|
},
|
|
173
151
|
|
|
174
|
-
data: function({selector, data, elements
|
|
152
|
+
data: function({selector, data, elements}) {
|
|
175
153
|
if (selector) {
|
|
176
154
|
let template = document.querySelector(selector)
|
|
177
155
|
if (!template) return;
|
|
@@ -179,9 +157,9 @@ const CoCreateRender = {
|
|
|
179
157
|
this.render(template, data)
|
|
180
158
|
}
|
|
181
159
|
else
|
|
182
|
-
this.setValue([template], data,
|
|
160
|
+
this.setValue([template], data, template);
|
|
183
161
|
} else if (elements) {
|
|
184
|
-
this.setValue(elements, data
|
|
162
|
+
this.setValue(elements, data);
|
|
185
163
|
}
|
|
186
164
|
|
|
187
165
|
}
|
|
@@ -204,26 +182,26 @@ action.init({
|
|
|
204
182
|
});
|
|
205
183
|
|
|
206
184
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
185
|
+
function renderKey(element) {
|
|
186
|
+
const form = element.closest("form") || document;
|
|
187
|
+
let data = CoCreate.api.getFormData('key', 'renderKey', form);
|
|
210
188
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
189
|
+
CoCreateRender.data({
|
|
190
|
+
selector: "[template_id='renderKey']",
|
|
191
|
+
data: {renderKey: data}
|
|
192
|
+
});
|
|
215
193
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
194
|
+
document.dispatchEvent(new CustomEvent('renderKey', {
|
|
195
|
+
detail: { data }
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
220
198
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
199
|
+
action.init({
|
|
200
|
+
action: "renderKey",
|
|
201
|
+
endEvent: "renderKey",
|
|
202
|
+
callback: (btn, data) => {
|
|
203
|
+
renderKey(btn);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
228
206
|
|
|
229
207
|
export default CoCreateRender;
|