@schukai/monster 3.38.1 → 3.39.0
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -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
|
|
package/source/types/version.mjs
CHANGED
@@ -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
|
-
|
11
|
-
|
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 = {
|
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
|
});
|
package/test/cases/monster.mjs
CHANGED