Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 1.31
  • master
  • 1.10.0
  • 1.30.1
  • 1.31.0
  • 1.8.0
  • 1.9.0
  • 3.100.0
  • 3.100.1
  • 3.100.10
  • 3.100.11
  • 3.100.12
  • 3.100.13
  • 3.100.14
  • 3.100.15
  • 3.100.16
  • 3.100.17
  • 3.100.18
  • 3.100.19
  • 3.100.2
  • 3.100.20
  • 3.100.3
  • 3.100.4
  • 3.100.5
  • 3.100.6
  • 3.100.7
  • 3.100.8
  • 3.100.9
  • 3.101.0
  • 3.101.1
  • 3.101.2
  • 3.101.3
  • 3.102.0
  • 3.102.1
  • 3.102.2
  • 3.102.3
  • 3.102.4
  • 3.102.5
  • 3.102.6
  • 3.103.0
  • 3.103.1
  • 3.104.0
  • 3.104.1
  • 3.105.0
  • 3.105.1
  • 3.105.2
  • 3.106.0
  • 3.106.1
  • 3.107.0
  • 3.108.0
  • 3.108.1
  • 3.108.2
  • 3.108.3
  • 3.108.4
  • 3.108.5
  • 3.109.0
  • 3.110.0
  • 3.110.1
  • 3.110.2
  • 3.110.3
  • 3.110.4
  • 3.111.0
  • 3.112.0
  • 3.112.1
  • 3.112.2
  • 3.112.3
  • 3.112.4
  • 3.113.0
  • 3.114.0
  • 3.114.1
  • 3.114.2
  • 3.114.3
  • 3.114.4
  • 3.114.5
  • 3.114.6
  • 3.114.7
  • 3.115.0
  • 3.115.1
  • 3.115.2
  • 3.115.3
  • 3.115.4
  • 3.116.0
  • 3.116.1
  • 3.117.0
  • 3.117.1
  • 3.117.2
  • 3.117.3
  • 3.118.0
  • 3.118.1
  • 3.119.0
  • 3.120.0
  • 3.121.0
  • 3.51.5
  • 3.52.0
  • 3.52.1
  • 3.53.0
  • 3.54.0
  • 3.55.0
  • 3.55.1
  • 3.55.2
  • 3.55.3
  • 3.55.4
102 results

Target

Select target project
  • oss/libraries/javascript/monster
1 result
Select Git revision
  • 1.31
  • master
  • 1.10.0
  • 1.30.1
  • 1.31.0
  • 1.8.0
  • 1.9.0
  • 3.100.0
  • 3.100.1
  • 3.100.10
  • 3.100.11
  • 3.100.12
  • 3.100.13
  • 3.100.14
  • 3.100.15
  • 3.100.16
  • 3.100.17
  • 3.100.18
  • 3.100.19
  • 3.100.2
  • 3.100.20
  • 3.100.3
  • 3.100.4
  • 3.100.5
  • 3.100.6
  • 3.100.7
  • 3.100.8
  • 3.100.9
  • 3.101.0
  • 3.101.1
  • 3.101.2
  • 3.101.3
  • 3.102.0
  • 3.102.1
  • 3.102.2
  • 3.102.3
  • 3.102.4
  • 3.102.5
  • 3.102.6
  • 3.103.0
  • 3.103.1
  • 3.104.0
  • 3.104.1
  • 3.105.0
  • 3.105.1
  • 3.105.2
  • 3.106.0
  • 3.106.1
  • 3.107.0
  • 3.108.0
  • 3.108.1
  • 3.108.2
  • 3.108.3
  • 3.108.4
  • 3.108.5
  • 3.109.0
  • 3.110.0
  • 3.110.1
  • 3.110.2
  • 3.110.3
  • 3.110.4
  • 3.111.0
  • 3.112.0
  • 3.112.1
  • 3.112.2
  • 3.112.3
  • 3.112.4
  • 3.113.0
  • 3.114.0
  • 3.114.1
  • 3.114.2
  • 3.114.3
  • 3.114.4
  • 3.114.5
  • 3.114.6
  • 3.114.7
  • 3.115.0
  • 3.115.1
  • 3.115.2
  • 3.115.3
  • 3.115.4
  • 3.116.0
  • 3.116.1
  • 3.117.0
  • 3.117.1
  • 3.117.2
  • 3.117.3
  • 3.118.0
  • 3.118.1
  • 3.119.0
  • 3.120.0
  • 3.121.0
  • 3.51.5
  • 3.52.0
  • 3.52.1
  • 3.53.0
  • 3.54.0
  • 3.55.0
  • 3.55.1
  • 3.55.2
  • 3.55.3
  • 3.55.4
102 results
Show changes
Commits on Source (5)
<a name="v3.38.1"></a>
## [v3.38.1] - 2023-04-03
### Bug Fixes
- case senstive options work now
### Changes
- doc
<a name="v3.38.0"></a> <a name="v3.38.0"></a>
## [v3.38.0] - 2023-04-03 ## [v3.38.0] - 2023-04-03
### Add Features ### Add Features
...@@ -536,6 +545,7 @@ ...@@ -536,6 +545,7 @@
<a name="1.8.0"></a> <a name="1.8.0"></a>
## 1.8.0 - 2021-08-15 ## 1.8.0 - 2021-08-15
[v3.38.1]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.38.0...v3.38.1
[v3.38.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.37.0...v3.38.0 [v3.38.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.37.0...v3.38.0
[v3.37.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.36.0...v3.37.0 [v3.37.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.36.0...v3.37.0
[v3.36.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.35.4...v3.36.0 [v3.36.0]: https://gitlab.schukai.com/oss/libraries/javascript/monster/compare/v3.35.4...v3.36.0
......
{ {
"name": "@schukai/monster", "name": "@schukai/monster",
"version": "3.37.0", "version": "3.38.0",
"description": "Monster is a simple library for creating fast, robust and lightweight websites.", "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
"keywords": [ "keywords": [
"framework", "framework",
......
...@@ -30,6 +30,7 @@ import { addObjectWithUpdaterToElement } from "./updater.mjs"; ...@@ -30,6 +30,7 @@ import { addObjectWithUpdaterToElement } from "./updater.mjs";
import { instanceSymbol } from "../constants.mjs"; import { instanceSymbol } from "../constants.mjs";
import { getDocumentTranslations, Translations } from "../i18n/translations.mjs"; import { getDocumentTranslations, Translations } from "../i18n/translations.mjs";
import { getSlottedElements } from "./slotted.mjs"; import { getSlottedElements } from "./slotted.mjs";
import {initOptionsFromAttributes} from "./util/init-options-from-attributes.mjs";
export { export {
CustomElement, CustomElement,
...@@ -197,8 +198,9 @@ class CustomElement extends HTMLElement { ...@@ -197,8 +198,9 @@ class CustomElement extends HTMLElement {
*/ */
constructor() { constructor() {
super(); super();
this[internalSymbol] = new ProxyObserver({ this[internalSymbol] = new ProxyObserver({
options: extend({}, this.defaults), options: initOptionsFromAttributes(this, extend({}, this.defaults)),
}); });
this[attributeObserverSymbol] = {}; this[attributeObserverSymbol] = {};
initOptionObserver.call(this); initOptionObserver.call(this);
......
...@@ -31,6 +31,7 @@ export {initOptionsFromAttributes }; ...@@ -31,6 +31,7 @@ export {initOptionsFromAttributes };
* // e.g. <div data-monster-option-bar-baz="foo"></div> * // e.g. <div data-monster-option-bar-baz="foo"></div>
* } * }
* *
* @since 3.38.0
* @param {HTMLElement} element - The DOM element to be used as the source of the attributes. * @param {HTMLElement} element - The DOM element to be used as the source of the attributes.
* @param {Object} options - The options object to be initialized. * @param {Object} options - The options object to be initialized.
* @param {Object} mapping - A mapping between the attribute value and the property value. * @param {Object} mapping - A mapping between the attribute value and the property value.
...@@ -42,6 +43,8 @@ function initOptionsFromAttributes(element, options, mapping={},prefix = 'data-m ...@@ -42,6 +43,8 @@ function initOptionsFromAttributes(element, options, mapping={},prefix = 'data-m
if (!(element instanceof HTMLElement)) return options; if (!(element instanceof HTMLElement)) return options;
if (!element.hasAttributes()) return options; if (!element.hasAttributes()) return options;
const keyMap = extractKeys(options);
const finder = new Pathfinder(options); const finder = new Pathfinder(options);
element.getAttributeNames().forEach((name) => { element.getAttributeNames().forEach((name) => {
...@@ -50,7 +53,7 @@ function initOptionsFromAttributes(element, options, mapping={},prefix = 'data-m ...@@ -50,7 +53,7 @@ function initOptionsFromAttributes(element, options, mapping={},prefix = 'data-m
// check if the attribute name is a valid option. // check if the attribute name is a valid option.
// the mapping between the attribute is simple. The dash is replaced by a dot. // the mapping between the attribute is simple. The dash is replaced by a dot.
// e.g. data-monster-url => url // e.g. data-monster-url => url
const optionName = name.replace(prefix, '').replace(/-/g, '.'); const optionName = keyMap.get(name.substring(prefix.length).toLowerCase());
if (!finder.exists(optionName)) return; if (!finder.exists(optionName)) return;
if (element.hasAttribute(name)) { if (element.hasAttribute(name)) {
...@@ -76,3 +79,34 @@ function initOptionsFromAttributes(element, options, mapping={},prefix = 'data-m ...@@ -76,3 +79,34 @@ function initOptionsFromAttributes(element, options, mapping={},prefix = 'data-m
return options; return options;
} }
/**
* Extracts the keys from the given object and returns a map with the keys and values.
*
* @private
* @param {object} obj
* @param {string} keyPrefix
* @param {string} keySeparator
* @param {string} valueSeparator
* @returns {Map<any, any>}
*/
function extractKeys(obj, keyPrefix = '', keySeparator = '-', valueSeparator = '.') {
const resultMap = new Map();
function helper(currentObj, currentKeyPrefix, currentValuePrefix) {
for (const key in currentObj) {
if (typeof currentObj[key] === 'object' && !Array.isArray(currentObj[key])) {
const newKeyPrefix = currentKeyPrefix ? currentKeyPrefix + keySeparator + key.toLowerCase() : key.toLowerCase();
const newValuePrefix = currentValuePrefix ? currentValuePrefix + valueSeparator + key : key;
helper(currentObj[key], newKeyPrefix, newValuePrefix);
} else {
const finalKey = currentKeyPrefix ? currentKeyPrefix + keySeparator + key.toLowerCase() : key.toLowerCase();
const finalValue = currentValuePrefix ? currentValuePrefix + valueSeparator + key : key;
resultMap.set(finalKey, finalValue);
}
}
}
helper(obj, keyPrefix, keyPrefix);
return resultMap;
}
...@@ -142,7 +142,7 @@ function getMonsterVersion() { ...@@ -142,7 +142,7 @@ function getMonsterVersion() {
} }
/** don't touch, replaced by make with package.json version */ /** don't touch, replaced by make with package.json version */
monsterVersion = new Version("3.37.0"); monsterVersion = new Version("3.38.0");
return monsterVersion; return monsterVersion;
} }
{ {
"name": "monster", "name": "monster",
"version": "3.37.0", "version": "3.38.0",
"description": "monster", "description": "monster",
"repository": { "repository": {
"type": "git", "type": "git",
......
...@@ -12,13 +12,13 @@ describe('initOptionsFromAttributes', () => { ...@@ -12,13 +12,13 @@ describe('initOptionsFromAttributes', () => {
}) })
beforeEach(() => { beforeEach(() => {
options = { url: "", key: { subkey: "" } }; options = { url: "", key: { subkey: "", caseSensitive: true } };
element = document.createElement('div'); element = document.createElement('div');
}); });
it('should initialize options with matching attributes', () => { it('should initialize options with matching attributes', () => {
element.setAttribute('data-monster-option-url', 'https://example.com'); element.setAttribute('data-monster-option-url', 'https://example.com');
element.setAttribute('data-monster-option-key.subkey', 'test'); element.setAttribute('data-monster-option-key-subkey', 'test');
const result = initOptionsFromAttributes(element, options); const result = initOptionsFromAttributes(element, options);
...@@ -73,7 +73,7 @@ describe('initOptionsFromAttributes', () => { ...@@ -73,7 +73,7 @@ describe('initOptionsFromAttributes', () => {
it('should apply multiple mappings', () => { it('should apply multiple mappings', () => {
element.setAttribute('data-monster-option-url', 'example'); element.setAttribute('data-monster-option-url', 'example');
element.setAttribute('data-monster-option-key.subkey', '123'); element.setAttribute('data-monster-option-key-subkey', '123');
const mapping = { const mapping = {
'url': (value) => 'https://' + value + '.com', 'url': (value) => 'https://' + value + '.com',
'key.subkey': (value) => parseInt(value, 10) * 2 'key.subkey': (value) => parseInt(value, 10) * 2
...@@ -108,7 +108,7 @@ describe('initOptionsFromAttributes', () => { ...@@ -108,7 +108,7 @@ describe('initOptionsFromAttributes', () => {
it('should apply mapping only to specified attributes', () => { it('should apply mapping only to specified attributes', () => {
element.setAttribute('data-monster-option-url', 'example'); element.setAttribute('data-monster-option-url', 'example');
element.setAttribute('data-monster-option-key.subkey', '123'); element.setAttribute('data-monster-option-key-subkey', '123');
const mapping = { const mapping = {
'url': (value) => 'https://' + value + '.com' 'url': (value) => 'https://' + value + '.com'
}; };
...@@ -152,4 +152,11 @@ describe('initOptionsFromAttributes', () => { ...@@ -152,4 +152,11 @@ describe('initOptionsFromAttributes', () => {
expect(result.url).to.equal(''); expect(result.url).to.equal('');
}); });
it('should apply case sensitive mapping', () => {
element.setAttribute('data-monster-option-key-caseSensitive', 'false');
const result = initOptionsFromAttributes(element, options);
expect(result.key.caseSensitive).to.equal(false);
});
}); });
...@@ -7,7 +7,7 @@ describe('Monster', function () { ...@@ -7,7 +7,7 @@ describe('Monster', function () {
let monsterVersion let monsterVersion
/** don´t touch, replaced by make with package.json version */ /** don´t touch, replaced by make with package.json version */
monsterVersion = new Version("3.37.0") monsterVersion = new Version("3.38.0")
let m = getMonsterVersion(); let m = getMonsterVersion();
......
{"version":"3.38.0"} {"version":"3.38.1"}