@cocreate/render 1.11.0 → 1.12.2

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 CHANGED
@@ -1,3 +1,29 @@
1
+ ## [1.12.2](https://github.com/CoCreate-app/CoCreate-render/compare/v1.12.1...v1.12.2) (2022-08-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * renderKey action does not work with renderMap. added isRenderKey to skip renderMap as temp solution ([7e90de8](https://github.com/CoCreate-app/CoCreate-render/commit/7e90de81b596154d3ab0b36e7326dfb8e67e6684))
7
+
8
+ ## [1.12.1](https://github.com/CoCreate-app/CoCreate-render/compare/v1.12.0...v1.12.1) (2022-07-31)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * moved the of loop that adds dataOriginal to inside if elements ([a1db516](https://github.com/CoCreate-app/CoCreate-render/commit/a1db516d6c4739581ab59db5ab5e746e8f409985))
14
+
15
+ # [1.12.0](https://github.com/CoCreate-app/CoCreate-render/compare/v1.11.0...v1.12.0) (2022-07-29)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * replace attribute value if new and old value are not equal ([3dc25d8](https://github.com/CoCreate-app/CoCreate-render/commit/3dc25d884510a6ad14455b232d9068eb5e1302a8))
21
+
22
+
23
+ ### Features
24
+
25
+ * if oldValues same as new value will not update text, html or attributes ([9cfe3f0](https://github.com/CoCreate-app/CoCreate-render/commit/9cfe3f017e706a5a7211449c294158d60fa2098c))
26
+
1
27
  # [1.11.0](https://github.com/CoCreate-app/CoCreate-render/compare/v1.10.0...v1.11.0) (2022-07-25)
2
28
 
3
29
 
@@ -19,7 +19,7 @@
19
19
  </cc-options>
20
20
 
21
21
  <div class="template" template_id="abc1">
22
- <div class="template" render-array="data.current" render-key="current_org" value="{{current_org.name}}">
22
+ <div class="template" render-array="data[0].current" render-key="current_org" value="{{current_org.name}}">
23
23
  <h3>{{current_org.name}}</h3>
24
24
  </div>
25
25
  </div>
@@ -16,7 +16,7 @@
16
16
  <div class="template" render-object="" render-key="one">
17
17
  <h5>{{one.key}}: {{one.value}}</h5>
18
18
  </div>
19
- <div class="template" render-array="data.current_org" render-key="current_org" value="{{current_org}}">
19
+ <div class="template" render-array="data[0].current_org" render-key="current_org" value="{{current_org}}">
20
20
  <h3>{{current_org}}</h3>
21
21
  </div>
22
22
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/render",
3
- "version": "1.11.0",
3
+ "version": "1.12.2",
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",
package/src/index.js CHANGED
@@ -197,6 +197,10 @@ const CoCreateRender = {
197
197
 
198
198
  setValue: function(els, data, renderArray, renderKey){
199
199
  if (!data) return;
200
+ let isRenderKey
201
+ if (data.renderKey)
202
+ isRenderKey = true
203
+
200
204
  const that = this;
201
205
  Array.from(els).forEach(el => {
202
206
  let updateData;
@@ -205,18 +209,19 @@ const CoCreateRender = {
205
209
  if (el.hasAttribute('render-clone')) {
206
210
  el.renderData = {...data}
207
211
  }
208
- if (el.renderMap) {
212
+ if (el.renderMap && !isRenderKey) {
209
213
  let placeholder = el.renderMap.get(el)
210
214
  if (placeholder){
215
+ let valueType = el.getAttribute('value-type')
211
216
  renderKey = placeholder.renderKey
212
217
  renderArray = placeholder.renderArray
213
- if (renderArray)
214
- updateData = data[renderArray][0]
218
+ if (renderArray && Array.isArray(data[renderArray]))
219
+ updateData = data[renderArray][0]
215
220
  if (renderKey)
216
- updateData = {[renderKey]: updateData}
221
+ updateData = {[renderKey]: updateData}
217
222
  let textContent = placeholder.placeholder
218
223
  let text = that.__replaceValue(updateData, textContent, renderKey, valueType);
219
- if (text)
224
+ if (text && text != el.renderedValue)
220
225
  el.innerHTML = placeholder.placeholder
221
226
  }
222
227
  }
@@ -224,24 +229,26 @@ const CoCreateRender = {
224
229
  Array.from(el.attributes).forEach(attr=>{
225
230
  let attr_name = attr.name.toLowerCase();
226
231
  let attrValue = attr.value;
227
-
228
232
  let placeholder
229
233
  if (attr.renderMap)
230
234
  placeholder = attr.renderMap.get(attr)
231
235
  else
232
236
  that.renderMap(attr, attr.value, renderArray, renderKey)
233
237
 
234
- if(placeholder){
238
+ if(placeholder && !isRenderKey){
235
239
  let updateData = data;
236
- attrValue = placeholder.placeholder;
240
+ // let oldValue = attrValue
241
+ let temp = placeholder.placeholder;
237
242
  renderKey = placeholder.renderKey
238
243
  renderArray = placeholder.renderArray
239
- if (renderArray)
244
+ if (renderArray && Array.isArray(data[renderArray]))
240
245
  updateData = data[renderArray][0]
241
246
  if (renderKey)
242
247
  updateData = {[renderKey]: updateData}
243
248
 
244
- attrValue = that.__replaceValue(updateData, attrValue, renderKey);
249
+ attrValue = that.__replaceValue(updateData, temp, renderKey);
250
+ if (attrValue == attr.value)
251
+ attrValue = undefined
245
252
  }
246
253
  else
247
254
  attrValue = that.__replaceValue(data, attrValue, renderKey);
@@ -259,7 +266,13 @@ const CoCreateRender = {
259
266
  }
260
267
  if (el.classList.contains('template') && !el.hasAttribute('template_id')) {
261
268
  that.render(el, data);
262
- }
269
+ }
270
+ // if (el.hasAttribute('render-array') || el.hasAttribute('render-object')) {
271
+ // if (!el.dataOriginal) {
272
+ // that.render(el, data);
273
+ // }
274
+ // }
275
+
263
276
  }
264
277
 
265
278
  if (el.nodeType == 3) {
@@ -268,35 +281,41 @@ const CoCreateRender = {
268
281
  let textContent, placeholder, text;
269
282
  if (el.renderMap)
270
283
  placeholder = el.renderMap.get(el)
271
- if (placeholder) {
284
+ if (placeholder && !isRenderKey) {
272
285
  let updateData = data;
273
286
  textContent = placeholder.placeholder
274
287
  renderKey = placeholder.renderKey
275
288
  renderArray = placeholder.renderArray
276
- if (renderArray)
289
+ if (renderArray && Array.isArray(data[renderArray]))
277
290
  updateData = data[renderArray][0]
278
291
  if (renderKey)
279
292
  updateData = {[renderKey]: updateData}
280
293
  text = that.__replaceValue(updateData, textContent, renderKey, valueType);
281
294
  }
282
- if (!text) {
295
+ if (!placeholder && !text) {
283
296
  textContent = el.textContent;
284
- that.renderMap(el, textContent, renderArray, renderKey)
297
+ if (!el.renderMap)
298
+ that.renderMap(el, textContent, renderArray, renderKey)
285
299
  text = that.__replaceValue(data, textContent, renderKey, valueType);
286
300
  }
287
301
 
288
302
  if (text || text == "") {
289
- if (valueType == 'text' || valueType == 'string'){
290
- el.textContent = text;
291
- } else {
292
- const newNode = document.createElement('div');
293
- newNode.innerHTML = text;
294
- let parentElement = el.parentElement
295
- if (!parentElement.renderMap) {
296
- that.renderMap(parentElement, textContent, renderArray, renderKey)
297
- } else if (!parentElement['renderMap'].has(parentElement))
298
- that.renderMap(parentElement, textContent, renderArray, renderKey)
299
- el.replaceWith(...newNode.childNodes)
303
+ if (text != el.renderedValue) {
304
+ el.renderedValue = text
305
+ if (valueType == 'text' || valueType == 'string'){
306
+ el.renderedValue = text
307
+ el.textContent = text;
308
+ } else {
309
+ const newNode = document.createElement('div');
310
+ newNode.innerHTML = text;
311
+ let parentElement = el.parentElement
312
+ parentElement.renderedValue = text
313
+ if (!parentElement.renderMap) {
314
+ that.renderMap(parentElement, textContent, renderArray, renderKey)
315
+ } else if (!parentElement['renderMap'].has(parentElement))
316
+ that.renderMap(parentElement, textContent, renderArray, renderKey)
317
+ el.replaceWith(...newNode.childNodes)
318
+ }
300
319
  }
301
320
  }
302
321
  }
@@ -314,12 +333,8 @@ const CoCreateRender = {
314
333
  dataOriginal: {},
315
334
  data: function({selector, data, elements}) {
316
335
  this.dataOriginal = {...data};
317
- this.dataString = {...data};
318
336
  delete this.dataOriginal.data
319
337
 
320
- for (let element of elements)
321
- element.dataOriginal = {...this.dataOriginal};
322
-
323
338
  if (selector) {
324
339
  let template = queryDocumentSelector(selector);
325
340
  if (!template) return;
@@ -330,6 +345,9 @@ const CoCreateRender = {
330
345
  else
331
346
  this.setValue([template], data);
332
347
  } else if (elements) {
348
+ for (let element of elements)
349
+ element.dataOriginal = {...this.dataOriginal};
350
+
333
351
  if (elements.length == 1 && elements[0].classList.contains('template')){
334
352
  this.render(elements[0], data);
335
353
  }