@cocreate/state 1.24.6 → 1.24.8
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/.github/workflows/automated.yml +5 -6
- package/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/src/index.js +22 -47
|
@@ -22,13 +22,13 @@ jobs:
|
|
|
22
22
|
runs-on: ubuntu-latest
|
|
23
23
|
steps:
|
|
24
24
|
- name: Checkout
|
|
25
|
-
uses: actions/checkout@
|
|
25
|
+
uses: actions/checkout@v4
|
|
26
26
|
- name: Setup Node.js
|
|
27
|
-
uses: actions/setup-node@
|
|
27
|
+
uses: actions/setup-node@v4
|
|
28
28
|
with:
|
|
29
|
-
node-version:
|
|
29
|
+
node-version: 22 # Required for the latest semantic-release plugins
|
|
30
30
|
- name: Semantic Release
|
|
31
|
-
uses: cycjimmy/semantic-release-action@
|
|
31
|
+
uses: cycjimmy/semantic-release-action@v4 # Update to v4 for better Node 20+ support
|
|
32
32
|
id: semantic
|
|
33
33
|
with:
|
|
34
34
|
extra_plugins: |
|
|
@@ -36,9 +36,8 @@ jobs:
|
|
|
36
36
|
@semantic-release/git
|
|
37
37
|
@semantic-release/github
|
|
38
38
|
env:
|
|
39
|
-
GITHUB_TOKEN: "${{ secrets.
|
|
39
|
+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" # Use the built-in token if possible
|
|
40
40
|
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
|
|
41
41
|
outputs:
|
|
42
42
|
new_release_published: "${{ steps.semantic.outputs.new_release_published }}"
|
|
43
43
|
new_release_version: "${{ steps.semantic.outputs.new_release_version }}"
|
|
44
|
-
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.24.8](https://github.com/CoCreate-app/CoCreate-state/compare/v1.24.7...v1.24.8) (2026-02-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* update attribute selectors from "state_id" to "state-id" for consistency ([90c0bd9](https://github.com/CoCreate-app/CoCreate-state/commit/90c0bd9fee44553b04a3b94075c65b86173a7401))
|
|
7
|
+
|
|
8
|
+
## [1.24.7](https://github.com/CoCreate-app/CoCreate-state/compare/v1.24.6...v1.24.7) (2026-02-04)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update worklow ([7efc914](https://github.com/CoCreate-app/CoCreate-state/commit/7efc914ab3fec6225d2259e9aecbaa4a051e524f))
|
|
14
|
+
|
|
1
15
|
## [1.24.6](https://github.com/CoCreate-app/CoCreate-state/compare/v1.24.5...v1.24.6) (2025-11-16)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/state",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.8",
|
|
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",
|
package/src/index.js
CHANGED
|
@@ -5,18 +5,18 @@ import uid from "@cocreate/uuid";
|
|
|
5
5
|
import localStorage from "@cocreate/local-storage";
|
|
6
6
|
|
|
7
7
|
function init() {
|
|
8
|
-
let elements = document.querySelectorAll("[
|
|
8
|
+
let elements = document.querySelectorAll("[state-id]");
|
|
9
9
|
initElements(elements);
|
|
10
10
|
window.addEventListener("storage", function (e) {
|
|
11
11
|
if (e.key == "state") {
|
|
12
12
|
elements = document.querySelectorAll(
|
|
13
|
-
'[
|
|
13
|
+
'[state-id]:not([state-onstoragechange="false"])'
|
|
14
14
|
);
|
|
15
15
|
initElements(elements);
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
document.addEventListener("click", function (e) {
|
|
19
|
-
const target = e.target.closest("[
|
|
19
|
+
const target = e.target.closest("[state-to]");
|
|
20
20
|
if (target) {
|
|
21
21
|
if (target.closest('[actions*="state"]')) return;
|
|
22
22
|
stateAttributes(target);
|
|
@@ -29,7 +29,7 @@ function initElements(elements) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function initElement(element) {
|
|
32
|
-
let state_id = element.getAttribute("
|
|
32
|
+
let state_id = element.getAttribute("state-id");
|
|
33
33
|
if (!state_id) return;
|
|
34
34
|
|
|
35
35
|
let statedAttributes = localStorage.getItem("state");
|
|
@@ -61,27 +61,6 @@ function _setAttributeValues(el, attrValues) {
|
|
|
61
61
|
|
|
62
62
|
for (const key of Object.keys(attrValues)) {
|
|
63
63
|
_setAttributeValue(el, key, attrValues[key], isOverwrite);
|
|
64
|
-
_setAttributeValue(el, `state-${key}`, attrValues[key], isOverwrite);
|
|
65
|
-
if (key == "array" || key == "object" || key == "name") {
|
|
66
|
-
_setAttributeValue(
|
|
67
|
-
el,
|
|
68
|
-
`fetch-${key}`,
|
|
69
|
-
attrValues[key],
|
|
70
|
-
isOverwrite
|
|
71
|
-
);
|
|
72
|
-
_setAttributeValue(
|
|
73
|
-
el,
|
|
74
|
-
`state-fetch-${key}`,
|
|
75
|
-
attrValues[key],
|
|
76
|
-
isOverwrite
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
if (key == "template") {
|
|
80
|
-
_setAttributeValue(el, "template_id", attrValues[key], isOverwrite);
|
|
81
|
-
}
|
|
82
|
-
if (key == "template_id") {
|
|
83
|
-
_setAttributeValue(el, "template", attrValues[key], isOverwrite);
|
|
84
|
-
}
|
|
85
64
|
}
|
|
86
65
|
}
|
|
87
66
|
|
|
@@ -130,12 +109,12 @@ async function stateAttributes(element) {
|
|
|
130
109
|
// if (form) {
|
|
131
110
|
// elements = form.querySelectorAll("[state_to]");
|
|
132
111
|
// } else {
|
|
133
|
-
if (element.hasAttribute("
|
|
134
|
-
let nestedElements = element.querySelectorAll("[
|
|
112
|
+
if (element.hasAttribute("state-to")) elements.push(element);
|
|
113
|
+
let nestedElements = element.querySelectorAll("[state-to]");
|
|
135
114
|
elements.push(...nestedElements);
|
|
136
115
|
let current = element;
|
|
137
116
|
while (current) {
|
|
138
|
-
if (current.hasAttribute("
|
|
117
|
+
if (current.hasAttribute("state-to") && !elements.includes(current)) {
|
|
139
118
|
elements.push(current);
|
|
140
119
|
}
|
|
141
120
|
current = current.parentElement;
|
|
@@ -158,7 +137,7 @@ async function stateAttributes(element) {
|
|
|
158
137
|
break;
|
|
159
138
|
}
|
|
160
139
|
|
|
161
|
-
let state_to = elements[i].getAttribute("
|
|
140
|
+
let state_to = elements[i].getAttribute("state-to");
|
|
162
141
|
Object.assign(statedAttributes, { [`${state_to}`]: attrValues });
|
|
163
142
|
_getStateId(attrValues, state_to);
|
|
164
143
|
}
|
|
@@ -187,25 +166,21 @@ async function _getAttributeValues(element) {
|
|
|
187
166
|
let attributeValues = {};
|
|
188
167
|
let attributes = element.attributes;
|
|
189
168
|
for (let attribute of attributes) {
|
|
190
|
-
if (attribute.name.startsWith("state
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
else
|
|
200
|
-
Object.assign(attributeValues, {
|
|
201
|
-
[`${attribute.name.substring(6)}`]: attribute.value
|
|
202
|
-
});
|
|
169
|
+
if (attribute.name.startsWith("state.")) {
|
|
170
|
+
const key = attribute.name.slice(6);
|
|
171
|
+
if (attribute.value == "$uid") {
|
|
172
|
+
Object.assign(attributeValues, { [key]: uid.generate(6) });
|
|
173
|
+
} else if (key === "value" && !attribute.value) {
|
|
174
|
+
Object.assign(attributeValues, { value: await element.getValue() });
|
|
175
|
+
} else {
|
|
176
|
+
Object.assign(attributeValues, { [key]: attribute.value });
|
|
177
|
+
}
|
|
203
178
|
}
|
|
204
179
|
}
|
|
205
180
|
if (
|
|
206
181
|
element.value !== undefined &&
|
|
207
|
-
!element.hasAttribute("state
|
|
208
|
-
element.
|
|
182
|
+
!element.hasAttribute("state.value") &&
|
|
183
|
+
element.getValue
|
|
209
184
|
)
|
|
210
185
|
Object.assign(attributeValues, { value: await element.getValue() });
|
|
211
186
|
|
|
@@ -213,7 +188,7 @@ async function _getAttributeValues(element) {
|
|
|
213
188
|
}
|
|
214
189
|
|
|
215
190
|
function _getStateId(attrValues, state_to) {
|
|
216
|
-
const elements = document.querySelectorAll(`[
|
|
191
|
+
const elements = document.querySelectorAll(`[state-id="${state_to}"]`);
|
|
217
192
|
for (let element of elements) _setAttributeValues(element, attrValues);
|
|
218
193
|
}
|
|
219
194
|
|
|
@@ -239,7 +214,7 @@ window.addEventListener("popstate", function (event) {
|
|
|
239
214
|
if (event.state) {
|
|
240
215
|
if (event.state.statedAttributes) {
|
|
241
216
|
localStorage.setItem("state", event.state.statedAttributes);
|
|
242
|
-
let elements = document.querySelectorAll("[
|
|
217
|
+
let elements = document.querySelectorAll("[state-id]");
|
|
243
218
|
initElements(elements);
|
|
244
219
|
}
|
|
245
220
|
|
|
@@ -257,7 +232,7 @@ window.addEventListener("popstate", function (event) {
|
|
|
257
232
|
Observer.init({
|
|
258
233
|
name: "CoCreateState",
|
|
259
234
|
types: ["addedNodes"],
|
|
260
|
-
selector: "[
|
|
235
|
+
selector: "[state-id]",
|
|
261
236
|
callback: function (mutation) {
|
|
262
237
|
initElement(mutation.target);
|
|
263
238
|
}
|