@schukai/monster 3.38.1 → 3.39.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.38.1",
3
+ "version": "3.39.0",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -7,6 +7,7 @@
7
7
 
8
8
  import {Pathfinder} from '../../data/pathfinder.mjs';
9
9
  import {isFunction} from '../../types/is.mjs';
10
+ import {attributeObserverSymbol} from "../customelement.mjs";
10
11
 
11
12
  export {initOptionsFromAttributes};
12
13
 
@@ -74,6 +75,30 @@ function initOptionsFromAttributes(element, options, mapping = {}, prefix = 'dat
74
75
  }
75
76
 
76
77
  finder.setVia(optionName, value);
78
+
79
+ // if element has an attribute observer, then register the attribute observer
80
+ if (element?.[attributeObserverSymbol]) {
81
+ element[attributeObserverSymbol][name] = (newValue, oldValue) => {
82
+
83
+ if (newValue === oldValue) return;
84
+
85
+ let changedValue = newValue;
86
+
87
+ if (typeOfOptionValue === 'boolean') {
88
+ changedValue = changedValue === 'true';
89
+ } else if (typeOfOptionValue === 'number') {
90
+ changedValue = Number(changedValue);
91
+ } else if (typeOfOptionValue === 'string') {
92
+ changedValue = String(changedValue);
93
+ } else if (typeOfOptionValue === 'object') {
94
+ changedValue = JSON.parse(changedValue);
95
+ }
96
+
97
+ finder.setVia(optionName, changedValue);
98
+ }
99
+ }
100
+
101
+
77
102
  }
78
103
  })
79
104
 
@@ -142,7 +142,7 @@ function getMonsterVersion() {
142
142
  }
143
143
 
144
144
  /** don't touch, replaced by make with package.json version */
145
- monsterVersion = new Version("3.38.1");
145
+ monsterVersion = new Version("3.39.0");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -1,18 +1,23 @@
1
1
  import {expect} from "chai"
2
2
 
3
- import {initOptionsFromAttributes} from "../../../../..//application/source/dom/util/init-options-from-attributes.mjs";
4
3
  import {initJSDOM} from "../../../util/jsdom.mjs";
5
4
 
6
5
  describe('initOptionsFromAttributes', () => {
7
6
  let element;
8
7
  let options;
9
-
10
- before(async function () {
11
- await initJSDOM();
12
- })
8
+ let initOptionsFromAttributes;
9
+
10
+ before( function (done) {
11
+ initJSDOM().then(() => {
12
+ import("../../../../..//application/source/dom/util/init-options-from-attributes.mjs").then((m) => {
13
+ initOptionsFromAttributes = m['initOptionsFromAttributes'];
14
+ done();
15
+ })
16
+ })
17
+ });
13
18
 
14
19
  beforeEach(() => {
15
- options = { url: "", key: { subkey: "", caseSensitive: true } };
20
+ options = {url: "", key: {subkey: "", caseSensitive: true}};
16
21
  element = document.createElement('div');
17
22
  });
18
23
 
@@ -150,13 +155,13 @@ describe('initOptionsFromAttributes', () => {
150
155
  const result = initOptionsFromAttributes(element, options, mapping);
151
156
 
152
157
  expect(result.url).to.equal('');
153
- });
154
-
158
+ });
159
+
155
160
  it('should apply case sensitive mapping', () => {
156
161
  element.setAttribute('data-monster-option-key-caseSensitive', 'false');
157
162
  const result = initOptionsFromAttributes(element, options);
158
163
 
159
164
  expect(result.key.caseSensitive).to.equal(false);
160
- });
161
-
165
+ });
166
+
162
167
  });
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.38.1")
10
+ monsterVersion = new Version("3.39.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13