@cocreate/state 1.25.0 → 1.25.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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.25.1](https://github.com/CoCreate-app/CoCreate-state/compare/v1.25.0...v1.25.1) (2026-03-05)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * support adding classes via state attributes ([dfa50d2](https://github.com/CoCreate-app/CoCreate-state/commit/dfa50d29ac8b5c15ef384dfebd67dc8faad816f8))
7
+
1
8
  # [1.25.0](https://github.com/CoCreate-app/CoCreate-state/compare/v1.24.9...v1.25.0) (2026-02-28)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/state",
3
- "version": "1.25.0",
3
+ "version": "1.25.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",
package/src/index.js CHANGED
@@ -81,17 +81,20 @@ function _setAttributeValues(el, attrValues) {
81
81
  async function _setAttributeValue(element, attribute, value, isOverwrite) {
82
82
  // TODO: if (value !== undefined)???
83
83
  if (!element.getAttribute(attribute) || isOverwrite) {
84
- if (attribute == "value") {
85
- if (element.value == "" || (element.value && isOverwrite))
86
- element.value = value;
87
- else if (
88
- isOverwrite ||
89
- (element.hasAttribute("value") && !(await element.getValue()))
90
- )
91
- element.setValue(value);
92
- } else if (element.hasAttribute(attribute) && (value || value === "")) {
93
- element.setAttribute(attribute, value);
94
- } else if (attribute.startsWith("$")) {
84
+ if (attribute == "value") {
85
+ if (element.value == "" || (element.value && isOverwrite))
86
+ element.value = value;
87
+ else if (
88
+ isOverwrite ||
89
+ (element.hasAttribute("value") && !(await element.getValue()))
90
+ )
91
+ element.setValue(value);
92
+ } else if (attribute === "class" && value) {
93
+ const classes = String(value).split(/\s+/).filter(Boolean);
94
+ if (classes.length) element.classList.add(...classes);
95
+ } else if (element.hasAttribute(attribute) && (value || value === "")) {
96
+ element.setAttribute(attribute, value);
97
+ } else if (attribute.startsWith("$")) {
95
98
  // Handle using operators.js
96
99
  const prop = attribute.substring(1);
97
100
  if (element[prop]) {
@@ -272,4 +275,4 @@ Action.init({
272
275
 
273
276
  init();
274
277
 
275
- export default { initElements, initElement, stateAttributes };
278
+ export default { initElements, initElement, stateAttributes };