@cocreate/state 1.22.0 → 1.22.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 +8 -0
- package/package.json +7 -7
- package/src/index.js +30 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [1.22.1](https://github.com/CoCreate-app/CoCreate-state/compare/v1.22.0...v1.22.1) (2024-04-29)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* bump cocreate dependencies ([3972fe5](https://github.com/CoCreate-app/CoCreate-state/commit/3972fe5147f4e95b04df3188c3520ead5fd40a95))
|
|
7
|
+
* state management ([13177bd](https://github.com/CoCreate-app/CoCreate-state/commit/13177bdf44ff2d3248e6ccce1b2c74222727d0c6))
|
|
8
|
+
|
|
1
9
|
# [1.22.0](https://github.com/CoCreate-app/CoCreate-state/compare/v1.21.0...v1.22.0) (2024-04-29)
|
|
2
10
|
|
|
3
11
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/state",
|
|
3
|
-
"version": "1.22.
|
|
3
|
+
"version": "1.22.1",
|
|
4
4
|
"description": "Data attributes which can be used for components in CoCreate framework combined as a group of attributes that dynamically change attributes & fetch custom data.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"state",
|
|
@@ -58,11 +58,11 @@
|
|
|
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/local-storage": "^1.
|
|
65
|
-
"@cocreate/observer": "^1.
|
|
66
|
-
"@cocreate/uuid": "^1.
|
|
61
|
+
"@cocreate/actions": "^1.18.1",
|
|
62
|
+
"@cocreate/crud-client": "^1.33.8",
|
|
63
|
+
"@cocreate/element-prototype": "^1.22.2",
|
|
64
|
+
"@cocreate/local-storage": "^1.14.3",
|
|
65
|
+
"@cocreate/observer": "^1.16.0",
|
|
66
|
+
"@cocreate/uuid": "^1.11.1"
|
|
67
67
|
}
|
|
68
68
|
}
|
package/src/index.js
CHANGED
|
@@ -55,25 +55,17 @@ function _setAttributeValues(el, attrValues) {
|
|
|
55
55
|
delete attrValues['overwrite']
|
|
56
56
|
|
|
57
57
|
for (const key of Object.keys(attrValues)) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
_setAttributeValue(el,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
_setAttributeValue(el, `state-fetch-${key}`, attrValues[key], isOverwrite);
|
|
70
|
-
}
|
|
71
|
-
if (key == 'template') {
|
|
72
|
-
_setAttributeValue(el, 'template_id', attrValues[key], isOverwrite);
|
|
73
|
-
}
|
|
74
|
-
if (key == 'template_id') {
|
|
75
|
-
_setAttributeValue(el, 'template', attrValues[key], isOverwrite);
|
|
76
|
-
}
|
|
58
|
+
_setAttributeValue(el, key, attrValues[key], isOverwrite);
|
|
59
|
+
_setAttributeValue(el, `state-${key}`, attrValues[key], isOverwrite);
|
|
60
|
+
if (key == 'array' || key == 'object' || key == 'name') {
|
|
61
|
+
_setAttributeValue(el, `fetch-${key}`, attrValues[key], isOverwrite);
|
|
62
|
+
_setAttributeValue(el, `state-fetch-${key}`, attrValues[key], isOverwrite);
|
|
63
|
+
}
|
|
64
|
+
if (key == 'template') {
|
|
65
|
+
_setAttributeValue(el, 'template_id', attrValues[key], isOverwrite);
|
|
66
|
+
}
|
|
67
|
+
if (key == 'template_id') {
|
|
68
|
+
_setAttributeValue(el, 'template', attrValues[key], isOverwrite);
|
|
77
69
|
}
|
|
78
70
|
}
|
|
79
71
|
}
|
|
@@ -105,26 +97,33 @@ async function stateAttributes(element) {
|
|
|
105
97
|
elements.push(...nestedElements)
|
|
106
98
|
}
|
|
107
99
|
|
|
108
|
-
let
|
|
100
|
+
let changeState = false
|
|
109
101
|
for (let i = 0; i < elements.length; i++) {
|
|
110
102
|
let attrValues = await _getAttributeValues(elements[i]);
|
|
111
|
-
if (attrValues.src === '$back' || attrValues.
|
|
112
|
-
|
|
103
|
+
if (attrValues.src === '$back' || attrValues.href === '$back') {
|
|
104
|
+
changeState = true
|
|
105
|
+
window.history.back();
|
|
106
|
+
break;
|
|
107
|
+
} else if (attrValues.src === '$forward' || attrValues.href === '$forward') {
|
|
108
|
+
changeState = true
|
|
109
|
+
window.history.forward();
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
113
|
let state_to = elements[i].getAttribute('state_to');
|
|
114
114
|
Object.assign(statedAttributes, { [`${state_to}`]: attrValues });
|
|
115
115
|
_getStateId(attrValues, state_to);
|
|
116
116
|
}
|
|
117
117
|
statedAttributes = JSON.stringify(statedAttributes)
|
|
118
|
-
|
|
118
|
+
let href = element.closest('href')
|
|
119
|
+
if (!changeState && !href) {
|
|
119
120
|
// TODO: Handle $title when adding statedAttributes
|
|
120
121
|
let title = element.getAttribute('title') || document.title || '';
|
|
121
|
-
|
|
122
122
|
history.pushState({ statedAttributes, title, url: location.href }, title, location.href);
|
|
123
|
-
} else {
|
|
124
|
-
console.log('pushState: ', pushState)
|
|
125
123
|
}
|
|
126
124
|
|
|
127
|
-
|
|
125
|
+
if (!changeState)
|
|
126
|
+
localStorage.setItem('statedAttributes', statedAttributes);
|
|
128
127
|
|
|
129
128
|
document.dispatchEvent(new CustomEvent('stateEnd', {
|
|
130
129
|
detail: {}
|
|
@@ -158,9 +157,12 @@ function _getStateId(attrValues, state_to) {
|
|
|
158
157
|
}
|
|
159
158
|
|
|
160
159
|
window.onload = function () {
|
|
161
|
-
if (!history.
|
|
160
|
+
if (!history.length) {
|
|
162
161
|
const statedAttributes = localStorage.getItem('statedAttributes') || '';
|
|
163
162
|
history.replaceState({ statedAttributes, url: location.href, title: document.title }, document.title, location.href);
|
|
163
|
+
} else if (!history.state || history.state.url !== location.href) {
|
|
164
|
+
const statedAttributes = localStorage.getItem('statedAttributes') || '';
|
|
165
|
+
history.pushState({ statedAttributes, url: location.href, title: document.title }, document.title, location.href);
|
|
164
166
|
}
|
|
165
167
|
};
|
|
166
168
|
|