@webtides/element-js 1.1.0 → 1.1.2
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 +13 -0
- package/package.json +1 -1
- package/src/BaseElement.js +2 -1
- package/src/dom-parts/NodePart.js +1 -1
- package/src/dom-parts/render.js +4 -1
- package/src/util/GlobalStylesStore.js +9 -2
- package/src/util/Store.js +2 -1
- package/src/util/crypto.js +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -16,6 +16,19 @@ to [Semantic Versioning](http://semver.org/).
|
|
|
16
16
|
<!-- ### Removed -->
|
|
17
17
|
<!-- ### Fixed -->
|
|
18
18
|
|
|
19
|
+
## [1.1.2] - 2024-10-30
|
|
20
|
+
|
|
21
|
+
### FIXED
|
|
22
|
+
|
|
23
|
+
- Fixed rerendering of templates that were initially null, prevent runtime errors
|
|
24
|
+
|
|
25
|
+
## [1.1.1] - 2024-09-16
|
|
26
|
+
|
|
27
|
+
### FIXED
|
|
28
|
+
|
|
29
|
+
- Fixed base url and css rules order in adopted style sheets.
|
|
30
|
+
- Fixed randomUUID not being available in unsecure hosts (like localhost) by adding a helper function
|
|
31
|
+
|
|
19
32
|
## [1.1.0] - 2024-06-24
|
|
20
33
|
|
|
21
34
|
### Added
|
package/package.json
CHANGED
package/src/BaseElement.js
CHANGED
|
@@ -2,6 +2,7 @@ import { parseAttribute, isNaN, dashToCamel, camelToDash, isObjectLike } from '.
|
|
|
2
2
|
import { getAllElementChildren, getClosestParentCustomElementNode, isOfSameNodeType } from './util/DOMHelper.js';
|
|
3
3
|
import { Store } from './util/Store.js';
|
|
4
4
|
import { serializeState, deserializeState, hasSerializedState } from './util/SerializeStateHelper.js';
|
|
5
|
+
import { randomUUID } from './util/crypto.js';
|
|
5
6
|
export { defineElement } from './util/defineElement.js';
|
|
6
7
|
export { toString } from './util/toString.js';
|
|
7
8
|
|
|
@@ -97,7 +98,7 @@ class BaseElement extends HTMLElement {
|
|
|
97
98
|
this._serializationKey = this.getAttribute('ejs:key');
|
|
98
99
|
deserializeState(this);
|
|
99
100
|
} else {
|
|
100
|
-
this._serializationKey =
|
|
101
|
+
this._serializationKey = randomUUID();
|
|
101
102
|
if (globalThis.elementJsConfig?.serializeState) {
|
|
102
103
|
this.setAttribute('ejs:key', this._serializationKey);
|
|
103
104
|
}
|
|
@@ -18,7 +18,7 @@ export class NodePart extends Part {
|
|
|
18
18
|
constructor(node, initialValue) {
|
|
19
19
|
if (!isObjectLike(initialValue) && !initialValue.directiveClass) {
|
|
20
20
|
throw new Error(
|
|
21
|
-
|
|
21
|
+
`NodePart: value "${initialValue}" is not a wrapped directive function. You must wrap you custom directive class with the defineDirective function.`,
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
24
|
super();
|
package/src/dom-parts/render.js
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
* @param {Element} domNode
|
|
5
5
|
*/
|
|
6
6
|
const render = (template, domNode) => {
|
|
7
|
-
if (
|
|
7
|
+
if (!template) {
|
|
8
|
+
// empty template was returned
|
|
9
|
+
domNode.innerHTML = '';
|
|
10
|
+
} else if (typeof template === 'string') {
|
|
8
11
|
// just a plain string (or literal)
|
|
9
12
|
domNode.innerHTML = template;
|
|
10
13
|
} else {
|
|
@@ -49,12 +49,19 @@ class GlobalStylesStore extends Store {
|
|
|
49
49
|
// TODO: this will always be null as we never set anything to the cache...
|
|
50
50
|
let cssStyleSheet = this.globalStyleSheetsCache.get(styleSheet.ownerNode);
|
|
51
51
|
if (!cssStyleSheet) {
|
|
52
|
-
cssStyleSheet = new CSSStyleSheet();
|
|
53
52
|
if (styleSheet.ownerNode.tagName === 'STYLE') {
|
|
53
|
+
cssStyleSheet = new CSSStyleSheet({ media: styleSheet.media, disabled: styleSheet.disabled });
|
|
54
54
|
cssStyleSheet.replaceSync(styleSheet.ownerNode.textContent);
|
|
55
55
|
} else if (styleSheet.ownerNode.tagName === 'LINK') {
|
|
56
|
+
cssStyleSheet = new CSSStyleSheet({
|
|
57
|
+
baseURL: styleSheet.href,
|
|
58
|
+
media: styleSheet.media,
|
|
59
|
+
disabled: styleSheet.disabled,
|
|
60
|
+
});
|
|
56
61
|
try {
|
|
57
|
-
Array.from(styleSheet?.cssRules ?? []).map((rule) =>
|
|
62
|
+
Array.from(styleSheet?.cssRules ?? []).map((rule, index) =>
|
|
63
|
+
cssStyleSheet.insertRule(rule.cssText, index),
|
|
64
|
+
);
|
|
58
65
|
} catch (e) {
|
|
59
66
|
console.error(
|
|
60
67
|
'GlobalStylesStore: cannot read cssRules. Maybe add crossorigin="anonymous" to your style link?',
|
package/src/util/Store.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
serializableObjectsCache,
|
|
7
7
|
} from './SerializeStateHelper.js';
|
|
8
8
|
import { BaseElement } from '../BaseElement.js';
|
|
9
|
+
import { randomUUID } from './crypto.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Options object for the Store
|
|
@@ -36,7 +37,7 @@ export class Store {
|
|
|
36
37
|
if (options?.key) {
|
|
37
38
|
this._serializationKey = options?.key;
|
|
38
39
|
} else {
|
|
39
|
-
this._serializationKey =
|
|
40
|
+
this._serializationKey = randomUUID();
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
if (options?.serializedState) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper function to use the crypto.randomUUID() as it will fail in none secure hosts (e.g. localhost)
|
|
3
|
+
* @return {`${string}-${string}-${string}-${string}-${string}`|*}
|
|
4
|
+
*/
|
|
5
|
+
export function randomUUID() {
|
|
6
|
+
if (!('randomUUID' in globalThis.crypto)) {
|
|
7
|
+
// https://stackoverflow.com/a/2117523/2800218
|
|
8
|
+
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
|
|
9
|
+
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16),
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
return globalThis.crypto.randomUUID();
|
|
13
|
+
}
|