@cocreate/elements 1.25.2 → 1.26.1
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 +24 -0
- package/demo/index.html +3 -3
- package/docs/index.html +2 -2
- package/package.json +8 -8
- package/src/fetchSrc.js +20 -17
- package/src/index.js +57 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
## [1.26.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.26.0...v1.26.1) (2023-11-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* meta name typo ([8e53dbe](https://github.com/CoCreate-app/CoCreate-elements/commit/8e53dbedf631f30ebb143837ff3c8ee9919cad8d))
|
|
7
|
+
* update crud methods ([09d988a](https://github.com/CoCreate-app/CoCreate-elements/commit/09d988aa0497622f131102966b94e9817fa7a495))
|
|
8
|
+
|
|
9
|
+
# [1.26.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.25.2...v1.26.0) (2023-11-03)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* favicon.ico path ([16da6e6](https://github.com/CoCreate-app/CoCreate-elements/commit/16da6e69bc2ee467694631f09e7efd2696e28aec))
|
|
15
|
+
* init new elements only ([1228c4c](https://github.com/CoCreate-app/CoCreate-elements/commit/1228c4cfd3a2c4a0a4274191efd6be36a267951e))
|
|
16
|
+
* map elements to prevent duplicate reads ([81c3101](https://github.com/CoCreate-app/CoCreate-elements/commit/81c31018a62555ccfa02e973b667ed8ee59fa584))
|
|
17
|
+
* update dependencies to the lates versions ([82c04cf](https://github.com/CoCreate-app/CoCreate-elements/commit/82c04cf2996090be0caee092de95d1080953c4b1))
|
|
18
|
+
* update method to use object.update etc ([575d800](https://github.com/CoCreate-app/CoCreate-elements/commit/575d80021bd6e0e169e7da7a3e9f4139b1277333))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* get attribute path and replace {{path}} ([c48878b](https://github.com/CoCreate-app/CoCreate-elements/commit/c48878b7c8467ba70314846d3d22cb90c9195f34))
|
|
24
|
+
|
|
1
25
|
## [1.25.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.25.1...v1.25.2) (2023-10-25)
|
|
2
26
|
|
|
3
27
|
|
package/demo/index.html
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
<!-- CoCreate Favicon -->
|
|
6
6
|
<link
|
|
7
7
|
rel="icon"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
type="image/png"
|
|
9
|
+
sizes="32x32"
|
|
10
|
+
href="../assets/favicon.ico" />
|
|
11
11
|
<link rel="manifest" href="/manifest.webmanifest" />
|
|
12
12
|
</head>
|
|
13
13
|
<body class="padding:20px">
|
package/docs/index.html
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
7
7
|
<meta
|
|
8
|
-
|
|
8
|
+
name="description"
|
|
9
9
|
content="Fetch content into any html element by using attributes to query data stored in CoCreate headless CMS. If data is changed it will instantly reflect in html tags" />
|
|
10
10
|
<meta
|
|
11
|
-
|
|
11
|
+
name="keywords"
|
|
12
12
|
content="helper classes, utility classes, css framework, css library, inline style classes" />
|
|
13
13
|
<meta name="robots" content="index,follow" />
|
|
14
14
|
<meta
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.1",
|
|
4
4
|
"description": "Fetch content into any html element by using html5 attributes to query data stored in CoCreate headless CMS. If data is changed it will instantly reflect in html tags as changes are broadcasted in realtime",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"elements",
|
|
@@ -58,12 +58,12 @@
|
|
|
58
58
|
"webpack-log": "^3.0.1"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@cocreate/actions": "^1.12.
|
|
62
|
-
"@cocreate/crud-client": "^1.28.
|
|
63
|
-
"@cocreate/element-prototype": "^1.11.
|
|
64
|
-
"@cocreate/filter": "^1.23.
|
|
65
|
-
"@cocreate/observer": "^1.11.
|
|
66
|
-
"@cocreate/render": "^1.29.
|
|
67
|
-
"@cocreate/utils": "^1.26.
|
|
61
|
+
"@cocreate/actions": "^1.12.1",
|
|
62
|
+
"@cocreate/crud-client": "^1.28.12",
|
|
63
|
+
"@cocreate/element-prototype": "^1.11.8",
|
|
64
|
+
"@cocreate/filter": "^1.23.6",
|
|
65
|
+
"@cocreate/observer": "^1.11.7",
|
|
66
|
+
"@cocreate/render": "^1.29.1",
|
|
67
|
+
"@cocreate/utils": "^1.26.2"
|
|
68
68
|
}
|
|
69
69
|
}
|
package/src/fetchSrc.js
CHANGED
|
@@ -20,13 +20,16 @@ async function initElement(element) {
|
|
|
20
20
|
if (!src || /{{\s*([\w\W]+)\s*}}/g.test(src))
|
|
21
21
|
return;
|
|
22
22
|
let initialize = initializing.get(element)
|
|
23
|
-
if (!initialize || initialize.src != src){
|
|
24
|
-
initializing.set(element, {src});
|
|
23
|
+
if (!initialize || initialize.src != src) {
|
|
24
|
+
initializing.set(element, { src });
|
|
25
25
|
if (src) {
|
|
26
26
|
try {
|
|
27
|
-
let response = await fetch(src);
|
|
27
|
+
let response = await fetch(src);
|
|
28
28
|
let text = await response.text();
|
|
29
29
|
if (text) {
|
|
30
|
+
let path = element.getAttribute('path')
|
|
31
|
+
if (path)
|
|
32
|
+
text = text.replaceAll('{{path}}', path)
|
|
30
33
|
element.setValue(text);
|
|
31
34
|
initializing.delete(element)
|
|
32
35
|
}
|
|
@@ -34,26 +37,26 @@ async function initElement(element) {
|
|
|
34
37
|
console.log('FetchSrc error:' + err);
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
|
-
}
|
|
40
|
+
}
|
|
38
41
|
};
|
|
39
42
|
|
|
40
43
|
observer.init({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
name: 'CoCreateSrc',
|
|
45
|
+
observe: ['addedNodes'],
|
|
46
|
+
target: selector,
|
|
47
|
+
callback: function (mutation) {
|
|
48
|
+
initElement(mutation.target);
|
|
49
|
+
}
|
|
47
50
|
});
|
|
48
51
|
|
|
49
52
|
observer.init({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
name: 'CoCreateSrcAttributes',
|
|
54
|
+
observe: ['attributes'],
|
|
55
|
+
attributeName: ['src'],
|
|
56
|
+
target: selector,
|
|
57
|
+
callback: function (mutation) {
|
|
58
|
+
initElement(mutation.target);
|
|
59
|
+
}
|
|
57
60
|
});
|
|
58
61
|
|
|
59
62
|
init()
|
package/src/index.js
CHANGED
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
* you must obtain a commercial license from CoCreate LLC.
|
|
22
22
|
* For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
|
|
23
23
|
*/
|
|
24
|
-
/** */
|
|
25
24
|
|
|
26
25
|
import Observer from '@cocreate/observer';
|
|
27
26
|
import Actions from '@cocreate/actions';
|
|
@@ -36,9 +35,10 @@ import { reset } from './form'
|
|
|
36
35
|
const selector = "[storage], [database], [array], [render-json]";
|
|
37
36
|
const elements = new Map();
|
|
38
37
|
const keys = new Map();
|
|
39
|
-
const forms = new Map();
|
|
38
|
+
const forms = new Map();
|
|
40
39
|
const debounce = new Map();
|
|
41
40
|
|
|
41
|
+
/** */
|
|
42
42
|
async function init(element) {
|
|
43
43
|
if (element && !(element instanceof HTMLCollection) && !Array.isArray(element))
|
|
44
44
|
element = [element]
|
|
@@ -61,8 +61,8 @@ async function init(element) {
|
|
|
61
61
|
|
|
62
62
|
if (dataObjects && dataObjects.size > 0) {
|
|
63
63
|
for (let key of dataObjects.keys()) {
|
|
64
|
-
let {
|
|
65
|
-
read(Array.from(
|
|
64
|
+
let { data } = keys.get(key)
|
|
65
|
+
read(Array.from(element), data, { string: key });
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -91,7 +91,7 @@ async function initElement(el) {
|
|
|
91
91
|
// }
|
|
92
92
|
|
|
93
93
|
// let Data = JSON.parse(match[1]);
|
|
94
|
-
// Data.method = read
|
|
94
|
+
// Data.method = object.read
|
|
95
95
|
// CRUD.send(Data)
|
|
96
96
|
|
|
97
97
|
}
|
|
@@ -224,10 +224,21 @@ async function read(element, data, dataKey) {
|
|
|
224
224
|
if (!data)
|
|
225
225
|
data = { ...keys.get(dataKey).dataKey.object }
|
|
226
226
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
227
|
+
if (!(element instanceof HTMLCollection) && !Array.isArray(element))
|
|
228
|
+
element = [element]
|
|
229
|
+
|
|
230
|
+
let delay = debounce.get(dataKey.string)
|
|
231
|
+
if (!delay)
|
|
232
|
+
debounce.set(dataKey.string, delay = {})
|
|
233
|
+
|
|
234
|
+
if (!delay.elements)
|
|
235
|
+
delay.elements = new Map()
|
|
236
|
+
|
|
237
|
+
for (let el of element)
|
|
238
|
+
delay.elements.set(el, true)
|
|
239
|
+
|
|
240
|
+
clearTimeout(delay.timer);
|
|
241
|
+
delay.timer = setTimeout(function () {
|
|
231
242
|
// TODO: should server support string and string array for type object, methods create, read, delete
|
|
232
243
|
if (!data.$filter && data.type === 'object') {
|
|
233
244
|
if (!data.object)
|
|
@@ -241,13 +252,18 @@ async function read(element, data, dataKey) {
|
|
|
241
252
|
return
|
|
242
253
|
}
|
|
243
254
|
|
|
244
|
-
data.method =
|
|
255
|
+
data.method = data.type + '.read'
|
|
245
256
|
|
|
246
257
|
CRUD.send(data).then((data) => {
|
|
247
|
-
|
|
258
|
+
debounce.delete(dataKey.string)
|
|
259
|
+
let els = Array.from(delay.elements.keys())
|
|
260
|
+
clearTimeout(delay.timer);
|
|
261
|
+
delete delay.elements
|
|
262
|
+
delete delay.timer
|
|
263
|
+
|
|
264
|
+
setData(els, data);
|
|
248
265
|
})
|
|
249
266
|
}, 500);
|
|
250
|
-
debounce.set(dataKey.string, delayTimer)
|
|
251
267
|
}
|
|
252
268
|
|
|
253
269
|
async function setData(element, data) {
|
|
@@ -255,13 +271,12 @@ async function setData(element, data) {
|
|
|
255
271
|
element = getDataElements(data)
|
|
256
272
|
if (!element.length) return
|
|
257
273
|
}
|
|
258
|
-
|
|
259
274
|
if (!(element instanceof HTMLCollection) && !Array.isArray(element))
|
|
260
275
|
element = [element]
|
|
261
276
|
|
|
262
277
|
let type = data.type
|
|
263
278
|
if (!type && data.method) {
|
|
264
|
-
type = data.method.split('.')[
|
|
279
|
+
type = data.method.split('.')[0]
|
|
265
280
|
} else if (type == 'key')
|
|
266
281
|
type = 'object'
|
|
267
282
|
|
|
@@ -284,9 +299,9 @@ async function setData(element, data) {
|
|
|
284
299
|
if (key) {
|
|
285
300
|
if (!data[type].length) continue;
|
|
286
301
|
if (isRead == "false" || isCrdt == "true") continue;
|
|
287
|
-
if (isListen == "false" && !data.method.
|
|
302
|
+
if (isListen == "false" && !data.method.endsWith('.read')) continue;
|
|
288
303
|
}
|
|
289
|
-
// TODO: update
|
|
304
|
+
// TODO: object.update data returned from server will not include $operator
|
|
290
305
|
el.setValue(value);
|
|
291
306
|
}
|
|
292
307
|
}
|
|
@@ -294,7 +309,7 @@ async function setData(element, data) {
|
|
|
294
309
|
|
|
295
310
|
async function filterData(element, data, type, key) {
|
|
296
311
|
if (key) {
|
|
297
|
-
if (!data
|
|
312
|
+
if (!data || !type) return
|
|
298
313
|
if (Array.isArray(data[type])) {
|
|
299
314
|
let Data = []
|
|
300
315
|
for (let doc of data[type]) {
|
|
@@ -305,13 +320,16 @@ async function filterData(element, data, type, key) {
|
|
|
305
320
|
Data.push(doc[key])
|
|
306
321
|
}
|
|
307
322
|
}
|
|
308
|
-
|
|
323
|
+
if (Data.length === 1) {
|
|
324
|
+
data = { [key]: Data[0] }
|
|
325
|
+
} else
|
|
326
|
+
data = Data
|
|
309
327
|
} else {
|
|
310
328
|
data = { [key]: data[type][key] }
|
|
311
329
|
}
|
|
312
330
|
}
|
|
313
331
|
|
|
314
|
-
if (element.getFilter && data.method && !data.method.
|
|
332
|
+
if (element.getFilter && data.method && !data.method.endsWith('.read'))
|
|
315
333
|
await checkFilters(element, data, type)
|
|
316
334
|
else if (element.renderValue)
|
|
317
335
|
element.renderValue(data);
|
|
@@ -384,12 +402,12 @@ function checkIndex(element, data, Data, newData, type, filter) {
|
|
|
384
402
|
if (!data.$filter)
|
|
385
403
|
data.$filter = {}
|
|
386
404
|
|
|
387
|
-
if (data.method.
|
|
405
|
+
if (data.method.endsWith('.delete')) {
|
|
388
406
|
if (!index && index !== 0)
|
|
389
407
|
return
|
|
390
408
|
data.$filter.remove = true
|
|
391
409
|
} else {
|
|
392
|
-
if (data.method.
|
|
410
|
+
if (data.method.endsWith('.create')) {
|
|
393
411
|
if (index === -1) {
|
|
394
412
|
data.$filter.create = true
|
|
395
413
|
if (filter && filter.sort)
|
|
@@ -521,7 +539,7 @@ async function getData(form) {
|
|
|
521
539
|
|
|
522
540
|
// console.log(type, value, data)
|
|
523
541
|
if (!Data[Data.type] && Data.key) {
|
|
524
|
-
Data.method =
|
|
542
|
+
Data.method = Data.type + '.create'
|
|
525
543
|
if (Data.type === 'object') {
|
|
526
544
|
if (typeof Data.object === 'string')
|
|
527
545
|
Data.object = { _id: Data.object }
|
|
@@ -557,7 +575,7 @@ async function getData(form) {
|
|
|
557
575
|
else {
|
|
558
576
|
Data[Data.type][Data.key] = value
|
|
559
577
|
if (!Data[Data.type]._id)
|
|
560
|
-
Data.method =
|
|
578
|
+
Data.method = Data.type + '.create'
|
|
561
579
|
}
|
|
562
580
|
} else {
|
|
563
581
|
Data[Data.type] = { [Data[Data.type]]: value }
|
|
@@ -567,11 +585,11 @@ async function getData(form) {
|
|
|
567
585
|
if (!Data.key) return
|
|
568
586
|
delete Data.isUpdate
|
|
569
587
|
Data.updateKey = { [Data.key]: value }
|
|
570
|
-
Data.method =
|
|
588
|
+
Data.method = Data.type + '.update'
|
|
571
589
|
} else if (Data.isDelete || Data.isDelete === '') {
|
|
572
590
|
delete Data.isDelete
|
|
573
591
|
if (Data.type == 'object' && Data.key) {
|
|
574
|
-
Data.method =
|
|
592
|
+
Data.method = Data.type + '.update'
|
|
575
593
|
// TODO: Data.type can be a string _id or an array for string _id needs to be converted to object
|
|
576
594
|
if (typeof Data[Data.type] === 'string')
|
|
577
595
|
Data[Data.type] = { _id: Data[Data.type], [Data.key]: undefined }
|
|
@@ -580,16 +598,16 @@ async function getData(form) {
|
|
|
580
598
|
} else if (typeof Data[Data.type] === 'object')
|
|
581
599
|
Data[Data.type][Data.key] = undefined
|
|
582
600
|
} else {
|
|
583
|
-
Data.method =
|
|
601
|
+
Data.method = Data.type + '.delete'
|
|
584
602
|
}
|
|
585
603
|
} else if (Data.type !== 'object' && Data[Data.type] === '') {
|
|
586
604
|
// if (!Data.key)
|
|
587
|
-
// Data.method =
|
|
605
|
+
// Data.method = Data.type + '.read'
|
|
588
606
|
// else if (Data.key === 'name')
|
|
589
|
-
// Data.method =
|
|
607
|
+
// Data.method = Data.type + '.create'
|
|
590
608
|
} else if (Data.type !== 'object' && Data[Data.type]) {
|
|
591
609
|
// if (Data.key)
|
|
592
|
-
// Data.method =
|
|
610
|
+
// Data.method = Data.type + '.update'
|
|
593
611
|
}
|
|
594
612
|
|
|
595
613
|
}
|
|
@@ -672,34 +690,34 @@ async function save(element) {
|
|
|
672
690
|
if (data[i].type === 'object' && !data[i].method) {
|
|
673
691
|
if (typeof data[i].object === 'string') {
|
|
674
692
|
if (!data[i]._id)
|
|
675
|
-
data[i].method = 'create
|
|
693
|
+
data[i].method = 'object.create'
|
|
676
694
|
else {
|
|
677
|
-
data[i].method = 'update
|
|
695
|
+
data[i].method = 'object.update'
|
|
678
696
|
if (upsert)
|
|
679
697
|
data[i].upsert = true
|
|
680
698
|
}
|
|
681
699
|
} else if (Array.isArray(data[i].object)) {
|
|
682
700
|
if (!data[i].object[0]._id)
|
|
683
|
-
data[i].method = 'create
|
|
701
|
+
data[i].method = 'object.create'
|
|
684
702
|
else {
|
|
685
|
-
data[i].method = 'update
|
|
703
|
+
data[i].method = 'object.update'
|
|
686
704
|
if (upsert)
|
|
687
705
|
data[i].upsert = true
|
|
688
706
|
}
|
|
689
707
|
} else if (typeof data[i].object === 'object') {
|
|
690
708
|
if (!data[i].object._id)
|
|
691
|
-
data[i].method = 'create
|
|
709
|
+
data[i].method = 'object.create'
|
|
692
710
|
else {
|
|
693
|
-
data[i].method = 'update
|
|
711
|
+
data[i].method = 'object.update'
|
|
694
712
|
if (upsert)
|
|
695
713
|
data[i].upsert = true
|
|
696
714
|
}
|
|
697
715
|
}
|
|
698
716
|
}
|
|
699
717
|
|
|
700
|
-
if (data[i].method && data[i].method.
|
|
718
|
+
if (data[i].method && data[i].method.endsWith('.create')) {
|
|
701
719
|
element.setAttribute(data[i].type, 'pending');
|
|
702
|
-
} else if (data[i].method && data[i].method.
|
|
720
|
+
} else if (data[i].method && data[i].method.endsWith('.update') && data[i].type == 'object' && typeof value == 'string' && window.CoCreate.crdt && !'crdt') {
|
|
703
721
|
return window.CoCreate.crdt.replaceText({
|
|
704
722
|
array: data[i].array,
|
|
705
723
|
key: data[i].key,
|
|
@@ -713,7 +731,7 @@ async function save(element) {
|
|
|
713
731
|
|
|
714
732
|
Data.push(data[i])
|
|
715
733
|
|
|
716
|
-
if (data[i] && (data[i].method.
|
|
734
|
+
if (data[i] && (data[i].method.endsWith('.create') || data[i].type !== 'object' && data[i].method.endsWith('.update'))) {
|
|
717
735
|
setTypeValue(element, data[i])
|
|
718
736
|
} else if (data[i])
|
|
719
737
|
document.dispatchEvent(new CustomEvent('saved', {
|
|
@@ -1067,7 +1085,7 @@ Actions.init([
|
|
|
1067
1085
|
for (let i = 0; i < elements.length; i++) {
|
|
1068
1086
|
const data = getObject(elements[i]);
|
|
1069
1087
|
if (!data) return
|
|
1070
|
-
data.method =
|
|
1088
|
+
data.method = data.type + '.delete'
|
|
1071
1089
|
|
|
1072
1090
|
if (elements[i].renderValue) {
|
|
1073
1091
|
let selected = elements[i].querySelectorAll('.selected')
|