wc-compiler 0.8.0 → 0.9.1
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/dist/wcc.dist.cjs +31 -23
- package/package.json +1 -1
- package/src/wcc.js +27 -19
package/dist/wcc.dist.cjs
CHANGED
|
@@ -83,7 +83,7 @@ class Document extends Node$1 {
|
|
|
83
83
|
return new HTMLTemplateElement();
|
|
84
84
|
|
|
85
85
|
default:
|
|
86
|
-
return new HTMLElement
|
|
86
|
+
return new HTMLElement();
|
|
87
87
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -95,7 +95,7 @@ class Document extends Node$1 {
|
|
|
95
95
|
|
|
96
96
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
|
|
97
97
|
// EventTarget <- Node <- Element <- HTMLElement
|
|
98
|
-
class HTMLElement
|
|
98
|
+
class HTMLElement extends Element {
|
|
99
99
|
attachShadow(options) {
|
|
100
100
|
this.shadowRoot = new ShadowRoot(options);
|
|
101
101
|
|
|
@@ -126,7 +126,7 @@ class ShadowRoot extends DocumentFragment {
|
|
|
126
126
|
|
|
127
127
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement
|
|
128
128
|
// EventTarget <- Node <- Element <- HTMLElement <- HTMLTemplateElement
|
|
129
|
-
class HTMLTemplateElement extends HTMLElement
|
|
129
|
+
class HTMLTemplateElement extends HTMLElement {
|
|
130
130
|
constructor() {
|
|
131
131
|
super();
|
|
132
132
|
this.content = new DocumentFragment();
|
|
@@ -168,7 +168,7 @@ class CustomElementsRegistry {
|
|
|
168
168
|
globalThis.addEventListener = noop;
|
|
169
169
|
globalThis.document = new Document();
|
|
170
170
|
globalThis.customElements = new CustomElementsRegistry();
|
|
171
|
-
globalThis.HTMLElement = HTMLElement
|
|
171
|
+
globalThis.HTMLElement = HTMLElement;
|
|
172
172
|
|
|
173
173
|
// Reserved word lists for various dialects of the language
|
|
174
174
|
|
|
@@ -28098,7 +28098,7 @@ async function getTagName(moduleURL) {
|
|
|
28098
28098
|
return tagName;
|
|
28099
28099
|
}
|
|
28100
28100
|
|
|
28101
|
-
async function initializeCustomElement(elementURL, tagName, attrs = [], definitions = [], isEntry) {
|
|
28101
|
+
async function initializeCustomElement(elementURL, tagName, attrs = [], definitions = [], isEntry, props = {}) {
|
|
28102
28102
|
if (!tagName) {
|
|
28103
28103
|
const depth = isEntry ? 1 : 0;
|
|
28104
28104
|
registerDependencies(elementURL, definitions, depth);
|
|
@@ -28110,7 +28110,11 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
|
|
|
28110
28110
|
? customElements.get(tagName)
|
|
28111
28111
|
: (await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(pathname)).default;
|
|
28112
28112
|
const dataLoader = (await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(pathname)).getData;
|
|
28113
|
-
const data =
|
|
28113
|
+
const data = props
|
|
28114
|
+
? props
|
|
28115
|
+
: dataLoader
|
|
28116
|
+
? await dataLoader(props)
|
|
28117
|
+
: {};
|
|
28114
28118
|
|
|
28115
28119
|
if (element) {
|
|
28116
28120
|
const elementInstance = new element(data); // eslint-disable-line new-cap
|
|
@@ -28126,29 +28130,33 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
|
|
|
28126
28130
|
await elementInstance.connectedCallback();
|
|
28127
28131
|
|
|
28128
28132
|
return elementInstance;
|
|
28129
|
-
} else {
|
|
28130
|
-
console.debug('No custom element class found for this file');
|
|
28131
|
-
return new HTMLElement();
|
|
28132
28133
|
}
|
|
28133
28134
|
}
|
|
28134
28135
|
|
|
28135
|
-
async function renderToString(elementURL, wrappingEntryTag = true) {
|
|
28136
|
+
async function renderToString(elementURL, wrappingEntryTag = true, props = {}) {
|
|
28136
28137
|
const definitions = [];
|
|
28137
28138
|
const elementTagName = wrappingEntryTag && await getTagName(elementURL);
|
|
28138
28139
|
const isEntry = !!elementTagName;
|
|
28139
|
-
const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry);
|
|
28140
|
-
|
|
28141
|
-
|
|
28142
|
-
|
|
28143
|
-
|
|
28144
|
-
|
|
28145
|
-
|
|
28146
|
-
|
|
28147
|
-
|
|
28148
|
-
|
|
28149
|
-
|
|
28150
|
-
`
|
|
28151
|
-
|
|
28140
|
+
const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry, props);
|
|
28141
|
+
let html;
|
|
28142
|
+
|
|
28143
|
+
// in case the entry point isn't valid
|
|
28144
|
+
if (elementInstance) {
|
|
28145
|
+
const elementHtml = elementInstance.shadowRoot
|
|
28146
|
+
? elementInstance.getInnerHTML({ includeShadowRoots: true })
|
|
28147
|
+
: elementInstance.innerHTML;
|
|
28148
|
+
const elementTree = getParse(elementHtml)(elementHtml);
|
|
28149
|
+
const finalTree = await renderComponentRoots(elementTree, definitions);
|
|
28150
|
+
|
|
28151
|
+
html = wrappingEntryTag && elementTagName ? `
|
|
28152
|
+
<${elementTagName}>
|
|
28153
|
+
${serialize(finalTree)}
|
|
28154
|
+
</${elementTagName}>
|
|
28155
|
+
`
|
|
28156
|
+
: serialize(finalTree);
|
|
28157
|
+
} else {
|
|
28158
|
+
console.warn('WARNING: No custom element class found for this entry point.');
|
|
28159
|
+
}
|
|
28152
28160
|
|
|
28153
28161
|
return {
|
|
28154
28162
|
html,
|
package/package.json
CHANGED
package/src/wcc.js
CHANGED
|
@@ -126,7 +126,7 @@ async function getTagName(moduleURL) {
|
|
|
126
126
|
return tagName;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
async function initializeCustomElement(elementURL, tagName, attrs = [], definitions = [], isEntry) {
|
|
129
|
+
async function initializeCustomElement(elementURL, tagName, attrs = [], definitions = [], isEntry, props = {}) {
|
|
130
130
|
if (!tagName) {
|
|
131
131
|
const depth = isEntry ? 1 : 0;
|
|
132
132
|
registerDependencies(elementURL, definitions, depth);
|
|
@@ -138,7 +138,11 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
|
|
|
138
138
|
? customElements.get(tagName)
|
|
139
139
|
: (await import(pathname)).default;
|
|
140
140
|
const dataLoader = (await import(pathname)).getData;
|
|
141
|
-
const data =
|
|
141
|
+
const data = props
|
|
142
|
+
? props
|
|
143
|
+
: dataLoader
|
|
144
|
+
? await dataLoader(props)
|
|
145
|
+
: {};
|
|
142
146
|
|
|
143
147
|
if (element) {
|
|
144
148
|
const elementInstance = new element(data); // eslint-disable-line new-cap
|
|
@@ -154,29 +158,33 @@ async function initializeCustomElement(elementURL, tagName, attrs = [], definiti
|
|
|
154
158
|
await elementInstance.connectedCallback();
|
|
155
159
|
|
|
156
160
|
return elementInstance;
|
|
157
|
-
} else {
|
|
158
|
-
console.debug('No custom element class found for this file');
|
|
159
|
-
return new HTMLElement();
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
|
|
163
|
-
async function renderToString(elementURL, wrappingEntryTag = true) {
|
|
164
|
+
async function renderToString(elementURL, wrappingEntryTag = true, props = {}) {
|
|
164
165
|
const definitions = [];
|
|
165
166
|
const elementTagName = wrappingEntryTag && await getTagName(elementURL);
|
|
166
167
|
const isEntry = !!elementTagName;
|
|
167
|
-
const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
`
|
|
179
|
-
|
|
168
|
+
const elementInstance = await initializeCustomElement(elementURL, undefined, undefined, definitions, isEntry, props);
|
|
169
|
+
let html;
|
|
170
|
+
|
|
171
|
+
// in case the entry point isn't valid
|
|
172
|
+
if (elementInstance) {
|
|
173
|
+
const elementHtml = elementInstance.shadowRoot
|
|
174
|
+
? elementInstance.getInnerHTML({ includeShadowRoots: true })
|
|
175
|
+
: elementInstance.innerHTML;
|
|
176
|
+
const elementTree = getParse(elementHtml)(elementHtml);
|
|
177
|
+
const finalTree = await renderComponentRoots(elementTree, definitions);
|
|
178
|
+
|
|
179
|
+
html = wrappingEntryTag && elementTagName ? `
|
|
180
|
+
<${elementTagName}>
|
|
181
|
+
${serialize(finalTree)}
|
|
182
|
+
</${elementTagName}>
|
|
183
|
+
`
|
|
184
|
+
: serialize(finalTree);
|
|
185
|
+
} else {
|
|
186
|
+
console.warn('WARNING: No custom element class found for this entry point.');
|
|
187
|
+
}
|
|
180
188
|
|
|
181
189
|
return {
|
|
182
190
|
html,
|