@cocreate/state 1.24.7 → 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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
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
+
1
8
  ## [1.24.7](https://github.com/CoCreate-app/CoCreate-state/compare/v1.24.6...v1.24.7) (2026-02-04)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/state",
3
- "version": "1.24.7",
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("[state_id]");
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
- '[state_id]:not([state-onstoragechange="false"])'
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("[state_to]");
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("state_id");
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("state_to")) elements.push(element);
134
- let nestedElements = element.querySelectorAll("[state_to]");
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("state_to") && !elements.includes(current)) {
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("state_to");
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
- if (attribute.value == "$uid")
192
- Object.assign(attributeValues, {
193
- [`${attribute.name.substring(5)}`]: uid.generate(6)
194
- });
195
- else if (attribute.name == "state-value" && !attribute.value)
196
- Object.assign(attributeValues, {
197
- value: await element.getValue()
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-value") &&
208
- element.getvalue
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(`[state_id="${state_to}"]`);
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("[state_id]");
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: "[state_id]",
235
+ selector: "[state-id]",
261
236
  callback: function (mutation) {
262
237
  initElement(mutation.target);
263
238
  }