@webtides/element-js 1.0.0-alpha.11 → 1.0.0-alpha.13

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": "@webtides/element-js",
3
- "version": "1.0.0-alpha.11",
3
+ "version": "1.0.0-alpha.13",
4
4
  "module": "index.js",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -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
- return `
66
- <!--template-part-->
67
- ${template}
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
  /**
@@ -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
- // TODO: ensure that SSRed and CSRed templates have the same amount of whitespace text nodes
157
- template.innerHTML = string.trimStart().trimEnd();
156
+ template.innerHTML = string;
158
157
  return template.content;
159
158
  };
160
159
 
@@ -53,7 +53,11 @@ class GlobalStylesStore extends Store {
53
53
  if (styleSheet.ownerNode.tagName === 'STYLE') {
54
54
  cssStyleSheet.replaceSync(styleSheet.ownerNode.textContent);
55
55
  } else if (styleSheet.ownerNode.tagName === 'LINK') {
56
- Array.from(styleSheet.cssRules).map((rule) => cssStyleSheet.insertRule(rule.cssText));
56
+ try {
57
+ Array.from(styleSheet?.cssRules ?? []).map((rule) => cssStyleSheet.insertRule(rule.cssText));
58
+ } catch (e) {
59
+ console.error('GlobalStylesStore: cannot read cssRules. Maybe add crossorigin="anonymous" to your style link?', e);
60
+ }
57
61
  }
58
62
  }
59
63
  cssStyleSheets.push(cssStyleSheet);