@webtides/element-js 1.0.0-alpha.11 → 1.0.0-alpha.12
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
package/src/TemplateElement.js
CHANGED
|
@@ -31,7 +31,7 @@ class TemplateElement extends StyledElement {
|
|
|
31
31
|
* This will attach a shadow DOM if the element is supposed to render in shadow DOM.
|
|
32
32
|
*/
|
|
33
33
|
connectedCallback() {
|
|
34
|
-
if (this._options.shadowRender) this.attachShadow({ mode: 'open' });
|
|
34
|
+
if (this._options.shadowRender && !this.shadowRoot) this.attachShadow({ mode: 'open' });
|
|
35
35
|
super.connectedCallback();
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -310,7 +310,7 @@ export class ChildNodePart extends Part {
|
|
|
310
310
|
} else if (Array.isArray(value)) {
|
|
311
311
|
let childNodePart = this.parts[index];
|
|
312
312
|
if (!childNodePart) {
|
|
313
|
-
// TODO: this seems not correct :(
|
|
313
|
+
// TODO: this seems not correct :( (maybe Template vs DOM Parts !?)
|
|
314
314
|
const templatePartCommentNodes = this.childNodes?.filter(
|
|
315
315
|
(node) => node && node.nodeType === COMMENT_NODE && node.data === 'template-part',
|
|
316
316
|
);
|
|
@@ -29,6 +29,7 @@ export const createTemplateString = (templateStrings, attributePlaceholders = ''
|
|
|
29
29
|
// find (match) all elements to identify their attributes
|
|
30
30
|
template = template.replace(elements, (_, name, attributesString, trailingSlash) => {
|
|
31
31
|
let elementTagWithAttributes = name + attributesString.replaceAll('\x01', attributePlaceholders).trimEnd();
|
|
32
|
+
// TODO the closing case is weird.
|
|
32
33
|
if (trailingSlash.length) elementTagWithAttributes += voidElements.test(name) ? ' /' : '></' + name;
|
|
33
34
|
// collect all attribute parts so that we can place matching comment nodes
|
|
34
35
|
const attributeParts = attributesString.replace(attributes, (attribute, name, valueWithQuotes, directive) => {
|
|
@@ -48,26 +49,23 @@ export const createTemplateString = (templateStrings, attributePlaceholders = ''
|
|
|
48
49
|
}
|
|
49
50
|
return parts.join('');
|
|
50
51
|
});
|
|
52
|
+
// TODO create test to check if lf are in place
|
|
51
53
|
return `
|
|
52
|
-
${attributesString.includes('\x01') ? attributeParts : ''}
|
|
53
|
-
<${elementTagWithAttributes}
|
|
54
|
-
|
|
54
|
+
${attributesString.includes('\x01') ? attributeParts : ''}\n
|
|
55
|
+
<${elementTagWithAttributes}>\n
|
|
56
|
+
`.trim();
|
|
55
57
|
});
|
|
56
58
|
// replace interpolation placeholders with our indexed markers
|
|
57
59
|
template = template.replace(partPositions, (partPosition) => {
|
|
58
60
|
if (partPosition === '\x01') {
|
|
59
61
|
return `<!--dom-part-${partIndex}--><!--/dom-part-${partIndex++}-->`;
|
|
60
|
-
}
|
|
61
|
-
if (partPosition === '\x02') {
|
|
62
|
+
} else if (partPosition === '\x02') {
|
|
62
63
|
return `dom-part-${partIndex++}`;
|
|
63
64
|
}
|
|
64
65
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
<!--/template-part-->
|
|
69
|
-
`;
|
|
70
|
-
// TODO: ^ this is actually important because of the whitespace
|
|
66
|
+
// TODO create test to check if lf are in place
|
|
67
|
+
// /n is important in the returns as we expect a certain order of text / comments an nodes
|
|
68
|
+
return `<!--template-part-->\n${template}\n<!--/template-part-->`.trim();
|
|
71
69
|
};
|
|
72
70
|
|
|
73
71
|
/**
|
package/src/util/DOMHelper.js
CHANGED
|
@@ -153,8 +153,7 @@ export const convertStringToHTML = (template) => {
|
|
|
153
153
|
*/
|
|
154
154
|
export const convertStringToTemplate = (string) => {
|
|
155
155
|
const template = globalThis.document?.createElement('template');
|
|
156
|
-
|
|
157
|
-
template.innerHTML = string.trimStart().trimEnd();
|
|
156
|
+
template.innerHTML = string;
|
|
158
157
|
return template.content;
|
|
159
158
|
};
|
|
160
159
|
|