@cocreate/elements 1.27.0 → 1.28.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 +21 -0
- package/docs/index.html +10 -12
- package/package.json +8 -8
- package/src/form.js +10 -5
- package/src/index.js +70 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
# [1.28.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.27.1...v1.28.0) (2023-11-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* conditions to update elements from broadcasted incoming data ([756b798](https://github.com/CoCreate-app/CoCreate-elements/commit/756b7984b6e46a6d03214a88fca130e4df02aaef))
|
|
7
|
+
* pass attributes renamed to state ([83c741e](https://github.com/CoCreate-app/CoCreate-elements/commit/83c741e6cdd88635957ff3d16193a4e95f8999d5))
|
|
8
|
+
* update nav, edit button and css path ([ac50546](https://github.com/CoCreate-app/CoCreate-elements/commit/ac50546b7deccd3adbb2a6b224b02a3b35cec671))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* upgrade dependencies for latest features and fixes ([baebd69](https://github.com/CoCreate-app/CoCreate-elements/commit/baebd69e9db0831a1060d8e03d96bb3f123d8c3e))
|
|
14
|
+
|
|
15
|
+
## [1.27.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.27.0...v1.27.1) (2023-11-22)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* condistions for matching elements and updating ([d7e7a39](https://github.com/CoCreate-app/CoCreate-elements/commit/d7e7a3920f9ccb1693b17f177a2734e3926a7e35))
|
|
21
|
+
|
|
1
22
|
# [1.27.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.26.4...v1.27.0) (2023-11-19)
|
|
2
23
|
|
|
3
24
|
|
package/docs/index.html
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
href="https://cocreate.app/images/favicon.ico" />
|
|
26
26
|
<link
|
|
27
27
|
rel="stylesheet"
|
|
28
|
-
href="
|
|
28
|
+
href="../index.css"
|
|
29
29
|
array="files"
|
|
30
30
|
object="60888216117c640e7596303f"
|
|
31
31
|
key="src"
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
</head>
|
|
36
36
|
|
|
37
37
|
<body>
|
|
38
|
+
<!-- Navbar -->
|
|
38
39
|
<nav
|
|
39
|
-
class="
|
|
40
|
+
class="width:100% display:flex align-items:center background:transparent padding-top:10px padding-bottom:10px"
|
|
40
41
|
content_id="content"
|
|
41
|
-
scroll="sticky-nav,
|
|
42
|
-
scroll-up="
|
|
43
|
-
scroll-down="
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
key="src"></nav>
|
|
42
|
+
scroll="sticky-nav,"
|
|
43
|
+
scroll-up="5"
|
|
44
|
+
scroll-down="5"
|
|
45
|
+
path="../"
|
|
46
|
+
src="../components/navbar.html"></nav>
|
|
47
47
|
<sidenav
|
|
48
48
|
id="menuL"
|
|
49
49
|
class="position:fixed top:0px left:0px overflow:hidden background:whitesmoke height:100vh width:0px width:300px@xl"
|
|
@@ -354,10 +354,8 @@
|
|
|
354
354
|
<button
|
|
355
355
|
href="https://github.com/CoCreate-app/CoCreate-elements/tree/master/docs/index.html?message=docs%3A%20describe%20your%20change..."
|
|
356
356
|
target="_blank"
|
|
357
|
-
class="position:fixed bottom:15px right:15px
|
|
358
|
-
<i
|
|
359
|
-
class="height:20px fill:#505050"
|
|
360
|
-
src="/assets/svg/pencil-alt.svg"></i>
|
|
357
|
+
class="display:flex justify-content:center align-items:center position:fixed bottom:15px right:15px height:50px width:50px border-radius:50% box-shadow:0px_2px_10px_0px_rgba(0,_0,_0,_0.4)">
|
|
358
|
+
<i class="height:20px" src="../assets/svg/pencil-alt.svg"></i>
|
|
361
359
|
</button>
|
|
362
360
|
</main>
|
|
363
361
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
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.
|
|
62
|
-
"@cocreate/crud-client": "^1.
|
|
63
|
-
"@cocreate/element-prototype": "^1.
|
|
64
|
-
"@cocreate/filter": "^1.
|
|
65
|
-
"@cocreate/observer": "^1.
|
|
66
|
-
"@cocreate/render": "^1.
|
|
67
|
-
"@cocreate/utils": "^1.
|
|
61
|
+
"@cocreate/actions": "^1.13.0",
|
|
62
|
+
"@cocreate/crud-client": "^1.30.0",
|
|
63
|
+
"@cocreate/element-prototype": "^1.14.1",
|
|
64
|
+
"@cocreate/filter": "^1.26.0",
|
|
65
|
+
"@cocreate/observer": "^1.13.0",
|
|
66
|
+
"@cocreate/render": "^1.34.0",
|
|
67
|
+
"@cocreate/utils": "^1.28.0"
|
|
68
68
|
}
|
|
69
69
|
}
|
package/src/form.js
CHANGED
|
@@ -3,14 +3,19 @@ import { getAttributeNames, ObjectId } from '@cocreate/utils';
|
|
|
3
3
|
import Action from '@cocreate/actions';
|
|
4
4
|
import '@cocreate/element-prototype';
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
|
|
8
|
+
* Initializes form elements. If no parameter is provided, or null is passed, it queries and initializes all form elements.
|
|
9
|
+
* It can also initialize a single form element or an array of form elements.
|
|
10
|
+
*
|
|
11
|
+
* @param {(Element|Element[]|null)} [elements] - Optional. A single form element, an array of form elements, or null.
|
|
12
|
+
* - If null or omitted, the function queries and initializes all form elements.
|
|
13
|
+
* - If a single form element is provided, it initializes that element.
|
|
14
|
+
* - If an array of form elements is provided, each element in the array is initialized.
|
|
15
|
+
*/
|
|
9
16
|
function init(elements) {
|
|
10
|
-
// Returns an array of elements.
|
|
11
17
|
if (!elements)
|
|
12
18
|
elements = document.querySelectorAll('form');
|
|
13
|
-
// If elements is an array of elements returns an array of elements.
|
|
14
19
|
else if (!Array.isArray(elements))
|
|
15
20
|
elements = [elements]
|
|
16
21
|
for (let element of elements) {
|
|
@@ -79,7 +84,7 @@ function disableAutoFill(element) {
|
|
|
79
84
|
}
|
|
80
85
|
|
|
81
86
|
/**
|
|
82
|
-
* @param
|
|
87
|
+
* @param form
|
|
83
88
|
*/
|
|
84
89
|
function reset(form) {
|
|
85
90
|
let formElements = new Map();
|
package/src/index.js
CHANGED
|
@@ -38,6 +38,20 @@ const keys = new Map();
|
|
|
38
38
|
const forms = new Map();
|
|
39
39
|
const debounce = new Map();
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Initializes elements with specific CRUD attributes. If no parameter is provided, it queries and initializes all elements
|
|
43
|
+
* that have certain CRUD-related attributes. It can also initialize a single element or an array of elements.
|
|
44
|
+
*
|
|
45
|
+
* Attributes used for initialization are:
|
|
46
|
+
* - storage: Specifies the storage mechanism.
|
|
47
|
+
* - database: Indicates the database to interact with.
|
|
48
|
+
* - array: Defines the array to be used.
|
|
49
|
+
* - render-json: Determines how JSON data is rendered.
|
|
50
|
+
*
|
|
51
|
+
* @param {(Element|Element[])} [elements] - Optional. A single element or an array of elements to initialize.
|
|
52
|
+
* If omitted, the function queries and initializes all elements containing
|
|
53
|
+
* any of these CRUD attributes: "storage", "database", "array", "render-json".
|
|
54
|
+
*/
|
|
41
55
|
async function init(element) {
|
|
42
56
|
if (element && !(element instanceof HTMLCollection) && !Array.isArray(element))
|
|
43
57
|
element = [element]
|
|
@@ -324,7 +338,8 @@ async function filterData(element, data, type, key) {
|
|
|
324
338
|
Data.push(...doc[key])
|
|
325
339
|
else
|
|
326
340
|
Data.push(doc[key])
|
|
327
|
-
}
|
|
341
|
+
} else
|
|
342
|
+
return
|
|
328
343
|
}
|
|
329
344
|
// if (Data.length === 1) {
|
|
330
345
|
// data = { [key]: Data[0] }
|
|
@@ -486,6 +501,7 @@ function getDataElements(data) {
|
|
|
486
501
|
return element
|
|
487
502
|
}
|
|
488
503
|
|
|
504
|
+
// TODO: Correctly check for matches
|
|
489
505
|
function getDataKeys(data) {
|
|
490
506
|
const matchingKeyStrings = [];
|
|
491
507
|
const targetKeys = ["type", "storage", "database", "array", "index", "object", '$filter'];
|
|
@@ -494,7 +510,7 @@ function getDataKeys(data) {
|
|
|
494
510
|
let hasMatch = true;
|
|
495
511
|
|
|
496
512
|
for (const key of targetKeys) {
|
|
497
|
-
if (!data.$filter &&
|
|
513
|
+
if (!data.$filter && key === '$filter' && sortedKey.data.hasOwnProperty(key))
|
|
498
514
|
hasMatch = true
|
|
499
515
|
else if (data.hasOwnProperty(key)) {
|
|
500
516
|
if (!sortedKey.data.hasOwnProperty(key)) {
|
|
@@ -503,17 +519,32 @@ function getDataKeys(data) {
|
|
|
503
519
|
}
|
|
504
520
|
if (Array.isArray(sortedKey.data[key]) && Array.isArray(data[key])) {
|
|
505
521
|
// if key is object check _id
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
522
|
+
if (key === 'object' && sortedKey.data.$filter)
|
|
523
|
+
hasMatch = true
|
|
524
|
+
else {
|
|
525
|
+
const matches = sortedKey.data[key].some(value => {
|
|
526
|
+
if (key === 'object') {
|
|
527
|
+
return data[key].some(obj => {
|
|
528
|
+
if (data.array.includes('users'))
|
|
529
|
+
console.log('users')
|
|
530
|
+
if (data.array.includes('questions'))
|
|
531
|
+
console.log('questions')
|
|
532
|
+
|
|
533
|
+
return obj._id === value._id
|
|
534
|
+
});
|
|
535
|
+
} else {
|
|
536
|
+
return data[key].includes(value)
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
if (!matches) {
|
|
541
|
+
hasMatch = false;
|
|
542
|
+
break;
|
|
511
543
|
}
|
|
512
|
-
|
|
513
|
-
if (!matches) {
|
|
514
|
-
hasMatch = false;
|
|
515
|
-
break;
|
|
544
|
+
|
|
516
545
|
}
|
|
546
|
+
|
|
547
|
+
|
|
517
548
|
} else if (sortedKey.data[key] !== data[key]) {
|
|
518
549
|
hasMatch = false;
|
|
519
550
|
break;
|
|
@@ -787,51 +818,51 @@ function setTypeValue(element, data) {
|
|
|
787
818
|
setData(Array.from(elements.keys()), data)
|
|
788
819
|
|
|
789
820
|
|
|
790
|
-
// const
|
|
821
|
+
// const state_ids = new Map();
|
|
791
822
|
|
|
792
|
-
// let
|
|
793
|
-
// if (
|
|
794
|
-
// // Set
|
|
823
|
+
// let state_id = form.getAttribute('state_id');
|
|
824
|
+
// if (state_id) {
|
|
825
|
+
// // Set state_ids to state_ids if array is not set
|
|
795
826
|
// if (form.getAttribute('array') == array)
|
|
796
|
-
//
|
|
827
|
+
// state_ids.set(state_id, '');
|
|
797
828
|
// }
|
|
798
829
|
|
|
799
830
|
// let objectId = el.getAttribute('object');
|
|
800
831
|
// let key = el.getAttribute('key')
|
|
801
|
-
// // set object and
|
|
832
|
+
// // set object and state_id attributes to the object id if the object id is pending
|
|
802
833
|
// if (key && (objectId == '' || objectId == 'pending')) {
|
|
803
834
|
// el.setAttribute('object', id);
|
|
804
835
|
// // Set the id attribute of the element
|
|
805
836
|
// if (key == '_id')
|
|
806
837
|
// el.setValue(id)
|
|
807
|
-
// let
|
|
808
|
-
// // Set the
|
|
809
|
-
// if (
|
|
810
|
-
//
|
|
838
|
+
// let state_id = el.getAttribute('state_id');
|
|
839
|
+
// // Set the state id to the state_ids.
|
|
840
|
+
// if (state_id) {
|
|
841
|
+
// state_ids.set(state_id, '');
|
|
811
842
|
// }
|
|
812
843
|
|
|
813
|
-
// if (el.hasAttribute('
|
|
814
|
-
// let
|
|
815
|
-
// // Set the
|
|
816
|
-
// if (
|
|
817
|
-
// el.setAttribute('
|
|
818
|
-
// let
|
|
819
|
-
// // Set the
|
|
820
|
-
// if (
|
|
821
|
-
//
|
|
844
|
+
// if (el.hasAttribute('state-object')) {
|
|
845
|
+
// let stateObjectId = el.getAttribute('state-object');
|
|
846
|
+
// // Set the state object id if not set.
|
|
847
|
+
// if (stateObjectId == '') {
|
|
848
|
+
// el.setAttribute('state-object', id);
|
|
849
|
+
// let state_id = el.getAttribute('state_id');
|
|
850
|
+
// // Set the state id to the state_ids.
|
|
851
|
+
// if (state_id) {
|
|
852
|
+
// state_ids.set(state_id, '');
|
|
822
853
|
// }
|
|
823
854
|
// }
|
|
824
855
|
// }
|
|
825
856
|
|
|
826
|
-
// // Set the object attribute of all
|
|
827
|
-
// if (
|
|
828
|
-
// for (let key of
|
|
829
|
-
// let
|
|
830
|
-
// for (let
|
|
831
|
-
// // if (
|
|
832
|
-
// // Set the object id attribute to the
|
|
833
|
-
// if (
|
|
834
|
-
//
|
|
857
|
+
// // Set the object attribute of all state_ids to the object attribute of all state_ids
|
|
858
|
+
// if (state_ids.size > 0) {
|
|
859
|
+
// for (let key of state_ids.keys()) {
|
|
860
|
+
// let stateEls = document.querySelectorAll(`[state_id="${key}"]`)
|
|
861
|
+
// for (let stateEl of stateEls) {
|
|
862
|
+
// // if (stateEl.getAttribute('array') == array){
|
|
863
|
+
// // Set the object id attribute to the stateEl s object if it is not set.
|
|
864
|
+
// if (stateEl.getAttribute('object') == '') {
|
|
865
|
+
// stateEl.setAttribute('object', id);
|
|
835
866
|
// }
|
|
836
867
|
// // }
|
|
837
868
|
// }
|