@qwik-custom-elements/adapter-stencil 1.0.0 → 1.0.3
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/README.md +2 -3
- package/dist/bundle-graph.json +1 -1
- package/dist/client/client-setup.d.ts +1 -1
- package/dist/client/index.qwik.mjs +178 -0
- package/dist/client/stencil-csr.d.ts +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.qwik.mjs +225 -185
- package/dist/q-manifest.json +24 -336
- package/dist/qwikloader-BOWbeQFD.js +101 -0
- package/dist/ssr/index.qwik.mjs +346 -0
- package/dist/ssr/stencil-ssr.d.ts +40 -7
- package/dist/ssr/stencil-ssr.d.ts.map +1 -1
- package/dist/ssr/styles-core.d.ts +2 -2
- package/package.json +51 -14
- package/dist/client/client-setup.test.d.ts +0 -2
- package/dist/client/client-setup.test.d.ts.map +0 -1
- package/dist/client/index.cjs +0 -1
- package/dist/client/index.js +0 -6
- package/dist/client/stencil-csr-props.test.d.ts +0 -2
- package/dist/client/stencil-csr-props.test.d.ts.map +0 -1
- package/dist/client-setup-C_qW_ZSR.cjs +0 -1
- package/dist/client-setup-D-ffVtNL.js +0 -53
- package/dist/client-setup.ts_createStencilClientSetup_runSetup_6wDTmOSdSbc-CPKK-h2J.js +0 -11
- package/dist/client-setup.ts_createStencilClientSetup_runSetup_6wDTmOSdSbc-Dz0z3zer.cjs +0 -1
- package/dist/core.min-Qm7Mxv6F.js +0 -1846
- package/dist/core.min-vJ4M2jcU.cjs +0 -2
- package/dist/index.qwik.cjs +0 -8
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/preloader-Bietv0BS.js +0 -118
- package/dist/preloader-Cqc--uBU.cjs +0 -1
- package/dist/qwikloader-C01zMTOC.js +0 -102
- package/dist/qwikloader-vFGnpgvG.cjs +0 -2
- package/dist/ssr/element-props-utils.test.d.ts +0 -2
- package/dist/ssr/element-props-utils.test.d.ts.map +0 -1
- package/dist/ssr/index.cjs +0 -1
- package/dist/ssr/index.js +0 -29
- package/dist/ssr/styles-core.test.d.ts +0 -2
- package/dist/ssr/styles-core.test.d.ts.map +0 -1
- package/dist/stencil-csr-B1U9s3VQ.js +0 -24
- package/dist/stencil-csr-D6zt1Am9.cjs +0 -1
- package/dist/stencil-csr.tsx_createStencilCSRComponent_component_pD3ekIZcUT0-ChAZ0hL3.js +0 -37
- package/dist/stencil-csr.tsx_createStencilCSRComponent_component_pD3ekIZcUT0-cGN__hqm.cjs +0 -1
- package/dist/stencil-csr.tsx_createStencilCSRComponent_component_useVisibleTask_1_dqWPXf9eNnk-BYiBxXW-.js +0 -34
- package/dist/stencil-csr.tsx_createStencilCSRComponent_component_useVisibleTask_1_dqWPXf9eNnk-sFN0uMI_.cjs +0 -1
- package/dist/stencil-csr.tsx_createStencilCSRComponent_component_useVisibleTask_y00qkhhKua8-BSsN2V78.cjs +0 -1
- package/dist/stencil-csr.tsx_createStencilCSRComponent_component_useVisibleTask_y00qkhhKua8-CF00O7hf.js +0 -19
- package/dist/stencil-ssr-BHjT94rd.js +0 -118
- package/dist/stencil-ssr-UlYtcG0-.cjs +0 -1
- package/dist/stencil-ssr.tsx_createStencilSSRBridgeComponent_component_IlVdOHKZfN0-46y8eTjO.cjs +0 -1
- package/dist/stencil-ssr.tsx_createStencilSSRBridgeComponent_component_IlVdOHKZfN0-BfqXBofh.js +0 -42
- package/dist/stencil-ssr.tsx_createStencilSSRBridgeComponent_component_useOnDocument_bvALMlewx7Q-DA73DRke.cjs +0 -1
- package/dist/stencil-ssr.tsx_createStencilSSRBridgeComponent_component_useOnDocument_bvALMlewx7Q-DdcskN1z.js +0 -10
- package/dist/stencil-ssr.tsx_createStencilSSRBridgeComponent_component_useTask_1_aXg7AuatGTc-61dSP-JG.cjs +0 -1
- package/dist/stencil-ssr.tsx_createStencilSSRBridgeComponent_component_useTask_1_aXg7AuatGTc-Byrz3fUp.js +0 -34
- package/dist/stencil-ssr.tsx_createStencilSSRBridgeComponent_component_useTask_IH8I3eLdwI0-BtIygb8E.js +0 -12
- package/dist/stencil-ssr.tsx_createStencilSSRBridgeComponent_component_useTask_IH8I3eLdwI0-DNQBT8Vc.cjs +0 -1
package/dist/index.qwik.mjs
CHANGED
|
@@ -1,154 +1,178 @@
|
|
|
1
|
-
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const metadata = {
|
|
2
4
|
adapterId: "stencil",
|
|
3
5
|
supportedSourceTypes: [
|
|
4
6
|
"CEM",
|
|
5
7
|
"PACKAGE_NAME"
|
|
6
8
|
],
|
|
7
|
-
supportsSsrProbe:
|
|
9
|
+
supportsSsrProbe: true,
|
|
8
10
|
ssrRuntimeSubpath: "./ssr"
|
|
9
11
|
};
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
13
|
-
|
|
12
|
+
function buildMissingCemHint({ packageRoot }) {
|
|
13
|
+
const collectionManifestPath = path.join(packageRoot, "dist", "collection", "collection-manifest.json");
|
|
14
|
+
if (!existsSync(collectionManifestPath)) return null;
|
|
15
|
+
return " This looks like a Stencil package. To fix this, ask the library author to add the `docs-custom-elements-manifest` output target to their `stencil.config.ts`: `{ type: 'docs-custom-elements-manifest', file: 'custom-elements.json' }`. Alternatively, set source.cemPath to the path of a manually generated CEM file.";
|
|
14
16
|
}
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
function validateProject({ source, adapterOptions }) {
|
|
18
|
+
const runtime = isRecord(adapterOptions?.runtime) ? adapterOptions.runtime : void 0;
|
|
19
|
+
const loaderImport = validateOptionalRuntimeOverride(runtime, "loaderImport", "QCE_STENCIL_RUNTIME_LOADER_OVERRIDE_INVALID", `Stencil ${source.type} projects must provide a non-empty adapterOptions.runtime.loaderImport override when the override is set.`);
|
|
20
|
+
validateOptionalRuntimeOverride(runtime, "hydrateImport", "QCE_STENCIL_RUNTIME_HYDRATE_OVERRIDE_INVALID", `Stencil ${source.type} projects must provide a non-empty adapterOptions.runtime.hydrateImport override when the override is set.`);
|
|
21
|
+
if (source.type !== "CEM") return;
|
|
22
|
+
if (loaderImport == null) throw createValidationError("QCE_STENCIL_RUNTIME_LOADER_REQUIRED", "Stencil CEM projects must provide adapterOptions.runtime.loaderImport.");
|
|
23
|
+
}
|
|
24
|
+
function resolveRuntimeImports({ projectId, runtimeResolution, source, adapterOptions }) {
|
|
25
|
+
const runtime = isRecord(adapterOptions?.runtime) ? adapterOptions.runtime : void 0;
|
|
26
|
+
const loaderImport = validateOptionalRuntimeOverride(runtime, "loaderImport", "QCE_STENCIL_RUNTIME_LOADER_OVERRIDE_INVALID", `Stencil ${source.type} projects must provide a non-empty adapterOptions.runtime.loaderImport override when the override is set.`);
|
|
27
|
+
const hydrateImport = validateOptionalRuntimeOverride(runtime, "hydrateImport", "QCE_STENCIL_RUNTIME_HYDRATE_OVERRIDE_INVALID", `Stencil ${source.type} projects must provide a non-empty adapterOptions.runtime.hydrateImport override when the override is set.`);
|
|
28
|
+
if (source.type === "CEM") {
|
|
29
|
+
if (loaderImport == null) throw createValidationError("QCE_STENCIL_RUNTIME_LOADER_REQUIRED", "Stencil CEM projects must provide adapterOptions.runtime.loaderImport.");
|
|
19
30
|
return {
|
|
20
|
-
loaderImport
|
|
21
|
-
hydrateImport
|
|
31
|
+
loaderImport,
|
|
32
|
+
hydrateImport
|
|
22
33
|
};
|
|
23
34
|
}
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
const packageRoot = resolvePackageRootForProject(source.packageName, runtimeResolution);
|
|
36
|
+
const resolvedLoaderImport = resolveRequiredPackageRuntimeImport({
|
|
37
|
+
projectId,
|
|
38
|
+
packageName: source.packageName,
|
|
39
|
+
packageRoot,
|
|
40
|
+
runtimeResolution,
|
|
41
|
+
specifier: loaderImport ?? `${source.packageName}/loader`,
|
|
30
42
|
field: "loader"
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
});
|
|
44
|
+
const observedErrorCodes = [];
|
|
45
|
+
const resolvedHydrateImport = resolveOptionalPackageRuntimeImport({
|
|
46
|
+
packageName: source.packageName,
|
|
47
|
+
packageRoot,
|
|
48
|
+
runtimeResolution,
|
|
49
|
+
specifier: hydrateImport ?? `${source.packageName}/hydrate`,
|
|
36
50
|
field: "hydrate",
|
|
37
|
-
observedErrorCodes
|
|
38
|
-
})
|
|
39
|
-
|
|
51
|
+
observedErrorCodes
|
|
52
|
+
});
|
|
53
|
+
const runtimeImports = {
|
|
54
|
+
loaderImport: resolvedLoaderImport
|
|
40
55
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
56
|
+
if (resolvedHydrateImport != null) runtimeImports.hydrateImport = resolvedHydrateImport;
|
|
57
|
+
if (observedErrorCodes.length === 0) return runtimeImports;
|
|
58
|
+
return {
|
|
59
|
+
runtimeImports,
|
|
60
|
+
observedErrorCodes,
|
|
61
|
+
clientOnlyMode: true
|
|
45
62
|
};
|
|
46
63
|
}
|
|
47
|
-
async function
|
|
48
|
-
if (!
|
|
49
|
-
available:
|
|
64
|
+
async function probeSSR({ runtimeImports } = {}) {
|
|
65
|
+
if (!isNonEmptyString(runtimeImports?.loaderImport)) return {
|
|
66
|
+
available: false
|
|
50
67
|
};
|
|
51
|
-
if (!
|
|
52
|
-
available:
|
|
68
|
+
if (!isNonEmptyString(runtimeImports?.hydrateImport)) return {
|
|
69
|
+
available: false
|
|
53
70
|
};
|
|
54
71
|
try {
|
|
72
|
+
const hydrateRuntimeModule = await import(
|
|
73
|
+
/* @vite-ignore */
|
|
74
|
+
runtimeImports.hydrateImport
|
|
75
|
+
);
|
|
55
76
|
return {
|
|
56
|
-
available: typeof
|
|
57
|
-
/* @vite-ignore */
|
|
58
|
-
e.hydrateImport
|
|
59
|
-
)).renderToString == "function"
|
|
77
|
+
available: typeof hydrateRuntimeModule.renderToString === "function"
|
|
60
78
|
};
|
|
61
79
|
} catch {
|
|
62
80
|
return {
|
|
63
|
-
available:
|
|
81
|
+
available: false
|
|
64
82
|
};
|
|
65
83
|
}
|
|
66
84
|
}
|
|
67
|
-
async function
|
|
68
|
-
if (!
|
|
69
|
-
let
|
|
85
|
+
async function augmentComponentDefinitions({ componentDefinitions, runtimeImports }) {
|
|
86
|
+
if (!isNonEmptyString(runtimeImports?.hydrateImport)) return componentDefinitions;
|
|
87
|
+
let renderToString;
|
|
70
88
|
try {
|
|
71
|
-
const
|
|
89
|
+
const mod = await import(
|
|
72
90
|
/* @vite-ignore */
|
|
73
|
-
|
|
91
|
+
runtimeImports.hydrateImport
|
|
74
92
|
);
|
|
75
|
-
typeof
|
|
93
|
+
if (typeof mod.renderToString === "function") renderToString = mod.renderToString;
|
|
76
94
|
} catch {
|
|
77
95
|
}
|
|
78
|
-
if (
|
|
79
|
-
const
|
|
80
|
-
for (const
|
|
81
|
-
const
|
|
82
|
-
|
|
96
|
+
if (renderToString == null) return componentDefinitions;
|
|
97
|
+
const augmented = [];
|
|
98
|
+
for (const def of componentDefinitions) {
|
|
99
|
+
const probedNames = await probeComponentNamedSlots(renderToString, def.tagName);
|
|
100
|
+
const existingNames = new Set(def.slots.map((s) => s.name));
|
|
101
|
+
const newSlots = probedNames.filter((name) => !existingNames.has(name)).map((name) => ({
|
|
102
|
+
name
|
|
83
103
|
}));
|
|
84
|
-
|
|
85
|
-
...
|
|
104
|
+
augmented.push({
|
|
105
|
+
...def,
|
|
86
106
|
slots: [
|
|
87
|
-
...
|
|
88
|
-
...
|
|
107
|
+
...def.slots,
|
|
108
|
+
...newSlots
|
|
89
109
|
]
|
|
90
110
|
});
|
|
91
111
|
}
|
|
92
|
-
return
|
|
112
|
+
return augmented;
|
|
93
113
|
}
|
|
94
|
-
async function
|
|
114
|
+
async function probeComponentNamedSlots(renderToString, tagName) {
|
|
95
115
|
try {
|
|
96
|
-
const
|
|
97
|
-
return
|
|
116
|
+
const result = await renderToString(`<${tagName}></${tagName}>`);
|
|
117
|
+
return extractNamedSlotNames(result.html ?? "");
|
|
98
118
|
} catch {
|
|
99
119
|
return [];
|
|
100
120
|
}
|
|
101
121
|
}
|
|
102
|
-
function
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
122
|
+
function extractNamedSlotNames(html) {
|
|
123
|
+
const re = /<!--s\.(?:\d+\.){4}(.*?)-->/g;
|
|
124
|
+
const names = [];
|
|
125
|
+
for (const match of html.matchAll(re)) {
|
|
126
|
+
const name = match[1];
|
|
127
|
+
if (name.length > 0 && !names.includes(name)) names.push(name);
|
|
107
128
|
}
|
|
108
|
-
return
|
|
129
|
+
return names;
|
|
109
130
|
}
|
|
110
|
-
function
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
113
|
-
const
|
|
131
|
+
function createGeneratedOutput({ projectId, libraryName, componentDefinitions, runtimeImports, ssrAvailable: _ssrAvailable }) {
|
|
132
|
+
const loaderImport = typeof runtimeImports?.loaderImport === "string" && runtimeImports.loaderImport.trim() !== "" ? runtimeImports.loaderImport : void 0;
|
|
133
|
+
if (loaderImport == null) return [];
|
|
134
|
+
const hydrateImport = typeof runtimeImports?.hydrateImport === "string" && runtimeImports.hydrateImport.trim() !== "" ? runtimeImports.hydrateImport : void 0;
|
|
135
|
+
const hasHydrateRuntime = hydrateImport != null;
|
|
136
|
+
const componentTags = (componentDefinitions ?? []).map((componentDefinition) => componentDefinition.tagName);
|
|
137
|
+
const plannedWrites = [
|
|
114
138
|
{
|
|
115
139
|
relativePath: "index.ts",
|
|
116
|
-
content:
|
|
140
|
+
content: renderGeneratedIndex(projectId, componentTags)
|
|
117
141
|
},
|
|
118
142
|
{
|
|
119
143
|
relativePath: "runtime.ts",
|
|
120
|
-
content:
|
|
144
|
+
content: renderRuntimeBarrelModule(projectId, hasHydrateRuntime)
|
|
121
145
|
},
|
|
122
146
|
{
|
|
123
147
|
relativePath: "runtime-csr.generated.ts",
|
|
124
|
-
content:
|
|
148
|
+
content: renderClientRuntimeModule(projectId, loaderImport, libraryName)
|
|
125
149
|
}
|
|
126
150
|
];
|
|
127
|
-
|
|
151
|
+
if (hydrateImport != null) plannedWrites.push({
|
|
128
152
|
relativePath: "runtime-ssr.generated.ts",
|
|
129
|
-
content:
|
|
153
|
+
content: renderServerRuntimeModule(projectId, hydrateImport, libraryName)
|
|
130
154
|
});
|
|
131
|
-
for (const
|
|
132
|
-
relativePath: `${
|
|
133
|
-
content:
|
|
155
|
+
for (const componentDefinition of componentDefinitions ?? []) plannedWrites.push({
|
|
156
|
+
relativePath: `${componentDefinition.tagName}.tsx`,
|
|
157
|
+
content: renderStencilComponentWrapper(projectId, componentDefinition, hasHydrateRuntime, libraryName)
|
|
134
158
|
});
|
|
135
|
-
return
|
|
159
|
+
return plannedWrites;
|
|
136
160
|
}
|
|
137
|
-
function
|
|
138
|
-
return typeof
|
|
161
|
+
function isRecord(value) {
|
|
162
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
139
163
|
}
|
|
140
|
-
function
|
|
141
|
-
return typeof
|
|
164
|
+
function isNonEmptyString(value) {
|
|
165
|
+
return typeof value === "string" && value.trim() !== "";
|
|
142
166
|
}
|
|
143
|
-
function
|
|
144
|
-
const
|
|
167
|
+
function renderClientRuntimeModule(projectId, loaderImport, libraryName) {
|
|
168
|
+
const csrBridgeName = toBridgeComponentName(libraryName, "CSR", "GeneratedStencilCSRComponent");
|
|
145
169
|
return [
|
|
146
|
-
`// Generated by @qwik-custom-elements/core. Project: ${
|
|
170
|
+
`// Generated by @qwik-custom-elements/core. Project: ${projectId ?? "unknown"}.`,
|
|
147
171
|
"// Do not edit this file directly. Use a manual extension layer.",
|
|
148
172
|
"",
|
|
149
173
|
"import { $ } from '@builder.io/qwik';",
|
|
150
174
|
"import { createStencilCSRComponent, createStencilClientSetup } from '@qwik-custom-elements/adapter-stencil/client';",
|
|
151
|
-
`import { defineCustomElements as runtimeDefineCustomElements } from '${
|
|
175
|
+
`import { defineCustomElements as runtimeDefineCustomElements } from '${loaderImport}';`,
|
|
152
176
|
"",
|
|
153
177
|
"export const defineCustomElements = async (): Promise<void> => {",
|
|
154
178
|
" await Promise.resolve(runtimeDefineCustomElements());",
|
|
@@ -157,40 +181,38 @@ function w(e, t, n) {
|
|
|
157
181
|
"export const defineCustomElementsQrl = $(defineCustomElements);",
|
|
158
182
|
"export const useStencilClientSetup =",
|
|
159
183
|
" createStencilClientSetup(defineCustomElementsQrl);",
|
|
160
|
-
`export const ${
|
|
184
|
+
`export const ${csrBridgeName} = createStencilCSRComponent();`,
|
|
161
185
|
""
|
|
162
|
-
].join(
|
|
163
|
-
`);
|
|
186
|
+
].join("\n");
|
|
164
187
|
}
|
|
165
|
-
function
|
|
166
|
-
const
|
|
188
|
+
function renderGeneratedIndex(projectId, componentTags) {
|
|
189
|
+
const exportLines = componentTags.map((componentTag) => `export { ${toWrapperName(componentTag)} } from './${componentTag}';`);
|
|
167
190
|
return [
|
|
168
|
-
`// Generated by @qwik-custom-elements/core. Project: ${
|
|
191
|
+
`// Generated by @qwik-custom-elements/core. Project: ${projectId ?? "unknown"}.`,
|
|
169
192
|
"// Do not edit this file directly. Use a manual extension layer.",
|
|
170
193
|
"",
|
|
171
|
-
`export const generatedComponentTags = ${JSON.stringify(
|
|
172
|
-
...
|
|
194
|
+
`export const generatedComponentTags = ${JSON.stringify(componentTags)} as const;`,
|
|
195
|
+
...exportLines,
|
|
173
196
|
""
|
|
174
|
-
].join(
|
|
175
|
-
`);
|
|
197
|
+
].join("\n");
|
|
176
198
|
}
|
|
177
|
-
function
|
|
178
|
-
const
|
|
199
|
+
function renderRuntimeBarrelModule(projectId, hasHydrateRuntime) {
|
|
200
|
+
const exportLines = [
|
|
179
201
|
"export * from './runtime-csr.generated';"
|
|
180
202
|
];
|
|
181
|
-
|
|
182
|
-
|
|
203
|
+
if (hasHydrateRuntime) exportLines.push("export * from './runtime-ssr.generated';");
|
|
204
|
+
return [
|
|
205
|
+
`// Generated by @qwik-custom-elements/core. Project: ${projectId ?? "unknown"}.`,
|
|
183
206
|
"// Do not edit this file directly. Use a manual extension layer.",
|
|
184
207
|
"",
|
|
185
|
-
...
|
|
208
|
+
...exportLines,
|
|
186
209
|
""
|
|
187
|
-
].join(
|
|
188
|
-
`);
|
|
210
|
+
].join("\n");
|
|
189
211
|
}
|
|
190
|
-
function
|
|
191
|
-
const
|
|
212
|
+
function renderServerRuntimeModule(projectId, hydrateImport, libraryName) {
|
|
213
|
+
const ssrBridgeName = toBridgeComponentName(libraryName, "SSR", "GeneratedStencilComponent");
|
|
192
214
|
return [
|
|
193
|
-
`// Generated by @qwik-custom-elements/core. Project: ${
|
|
215
|
+
`// Generated by @qwik-custom-elements/core. Project: ${projectId ?? "unknown"}.`,
|
|
194
216
|
"// Do not edit this file directly. Use a manual extension layer.",
|
|
195
217
|
"",
|
|
196
218
|
"import { $ } from '@builder.io/qwik';",
|
|
@@ -199,40 +221,50 @@ function L(e, t, n) {
|
|
|
199
221
|
" type StencilRenderToString,",
|
|
200
222
|
"} from '@qwik-custom-elements/adapter-stencil/ssr';",
|
|
201
223
|
"",
|
|
202
|
-
`const
|
|
224
|
+
`const hydrateRuntimeImport = ${JSON.stringify(hydrateImport.split("/"))}.join('/');`,
|
|
203
225
|
"",
|
|
204
226
|
"export const renderToString: StencilRenderToString = async (input, options) => {",
|
|
205
227
|
" const { renderToString: runtimeRenderToString } = await import(",
|
|
206
|
-
"
|
|
207
|
-
"
|
|
228
|
+
" /* @vite-ignore */",
|
|
229
|
+
" hydrateRuntimeImport",
|
|
208
230
|
" );",
|
|
209
231
|
" return runtimeRenderToString(input, options);",
|
|
210
232
|
"};",
|
|
211
233
|
"",
|
|
212
234
|
"export const generatedStencilRenderToStringQrl = $(renderToString);",
|
|
213
|
-
|
|
235
|
+
"",
|
|
236
|
+
`export const ${ssrBridgeName} = createStencilSSRBridgeComponent(`,
|
|
214
237
|
" generatedStencilRenderToStringQrl,",
|
|
215
238
|
");",
|
|
216
239
|
""
|
|
217
|
-
].join(
|
|
218
|
-
`);
|
|
240
|
+
].join("\n");
|
|
219
241
|
}
|
|
220
|
-
function
|
|
221
|
-
const
|
|
242
|
+
function renderStencilComponentWrapper(projectId, componentDefinition, ssrAvailable, libraryName) {
|
|
243
|
+
const wrapperName = toWrapperName(componentDefinition.tagName);
|
|
244
|
+
const propsTypeName = `${wrapperName}Props`;
|
|
245
|
+
const generatedStencilComponentName = ssrAvailable ? toBridgeComponentName(libraryName, "SSR", "GeneratedStencilComponent") : toBridgeComponentName(libraryName, "CSR", "GeneratedStencilCSRComponent");
|
|
246
|
+
const slotLines = [
|
|
222
247
|
" <Slot />",
|
|
223
|
-
...
|
|
224
|
-
<Slot name=${JSON.stringify(
|
|
248
|
+
...componentDefinition.slots.map((slot) => ` <span q:slot=${JSON.stringify(slot.name)} style={{ display: 'contents' }}>
|
|
249
|
+
<Slot name=${JSON.stringify(slot.name)} />
|
|
225
250
|
</span>`)
|
|
226
|
-
]
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
251
|
+
];
|
|
252
|
+
const slotListToken = componentDefinition.slots.length > 0 ? JSON.stringify(componentDefinition.slots.map((slot) => slot.name)) : "undefined";
|
|
253
|
+
const propLines = componentDefinition.props.map((prop) => {
|
|
254
|
+
const key = isValidIdentifier(prop.name) ? prop.name : `'${prop.name}'`;
|
|
255
|
+
const optionalToken = prop.required ? "" : "?";
|
|
256
|
+
return ` ${key}${optionalToken}: ${prop.type};`;
|
|
257
|
+
});
|
|
258
|
+
const eventPropLines = componentDefinition.events.map((event) => {
|
|
259
|
+
return ` ${toEventPropName(event.name)}?: QRL<(event: ${event.type}) => void>;`;
|
|
260
|
+
});
|
|
261
|
+
propLines.push(...eventPropLines, " [key: string]: unknown;");
|
|
262
|
+
const importLines = [
|
|
232
263
|
"import { Slot, component$ } from '@builder.io/qwik';"
|
|
233
264
|
];
|
|
234
|
-
|
|
235
|
-
|
|
265
|
+
if (componentDefinition.events.length > 0) importLines.push("import type { QRL } from '@builder.io/qwik';");
|
|
266
|
+
importLines.push(`import { ${generatedStencilComponentName} } from './runtime';`);
|
|
267
|
+
const splitPropsLines = [
|
|
236
268
|
" const isEventBindingKey = (key: string) =>",
|
|
237
269
|
" /^on[A-Z].*\\$$/.test(key) || key.includes(':');",
|
|
238
270
|
" const eventProps: Record<string, unknown> = {};",
|
|
@@ -250,9 +282,10 @@ function O(e, t, n, r) {
|
|
|
250
282
|
"",
|
|
251
283
|
" elementProps[key] = value;",
|
|
252
284
|
" }"
|
|
253
|
-
]
|
|
285
|
+
];
|
|
286
|
+
const mappedEventLines = componentDefinition.events.length > 0 ? [
|
|
254
287
|
"",
|
|
255
|
-
` const mappedEventPropKeys = new Set(${JSON.stringify(
|
|
288
|
+
` const mappedEventPropKeys = new Set(${JSON.stringify(componentDefinition.events.map((event) => toEventPropName(event.name)))});`,
|
|
256
289
|
" const passthroughEventProps = Object.fromEntries(",
|
|
257
290
|
" Object.entries(eventProps).filter(",
|
|
258
291
|
" ([key]) => !mappedEventPropKeys.has(key),",
|
|
@@ -260,105 +293,112 @@ function O(e, t, n, r) {
|
|
|
260
293
|
" );",
|
|
261
294
|
"",
|
|
262
295
|
" const events: Record<string, QRL<(...args: any[]) => void>> = {};",
|
|
263
|
-
...
|
|
296
|
+
...componentDefinition.events.map((event) => ` if (props.${toEventPropName(event.name)}) { events['${event.name}'] = props.${toEventPropName(event.name)}; }`),
|
|
264
297
|
" const mappedEvents = Object.keys(events).length > 0 ? events : undefined;"
|
|
265
298
|
] : [
|
|
266
299
|
"",
|
|
267
300
|
" const passthroughEventProps = eventProps;",
|
|
268
301
|
" const mappedEvents = undefined;"
|
|
269
|
-
]
|
|
270
|
-
|
|
271
|
-
|
|
302
|
+
];
|
|
303
|
+
const bodyLines = [
|
|
304
|
+
...splitPropsLines,
|
|
305
|
+
...mappedEventLines,
|
|
272
306
|
"",
|
|
273
307
|
" return (",
|
|
274
|
-
` <${
|
|
275
|
-
` tagName=${JSON.stringify(
|
|
308
|
+
` <${generatedStencilComponentName}`,
|
|
309
|
+
` tagName=${JSON.stringify(componentDefinition.tagName)}`,
|
|
276
310
|
" props={elementProps}",
|
|
277
311
|
" events={mappedEvents}",
|
|
278
|
-
` slots={${
|
|
312
|
+
` slots={${slotListToken}}`,
|
|
279
313
|
" {...passthroughEventProps}",
|
|
280
314
|
" >",
|
|
281
|
-
...
|
|
282
|
-
` </${
|
|
315
|
+
...slotLines,
|
|
316
|
+
` </${generatedStencilComponentName}>`,
|
|
283
317
|
" );"
|
|
284
318
|
];
|
|
285
319
|
return [
|
|
286
|
-
`// Generated by @qwik-custom-elements/core. Project: ${
|
|
320
|
+
`// Generated by @qwik-custom-elements/core. Project: ${projectId ?? "unknown"}.`,
|
|
287
321
|
"// Do not edit this file directly. Use a manual extension layer.",
|
|
288
322
|
"",
|
|
289
|
-
...
|
|
323
|
+
...importLines,
|
|
290
324
|
"",
|
|
291
|
-
`export interface ${
|
|
292
|
-
...
|
|
325
|
+
`export interface ${propsTypeName} {`,
|
|
326
|
+
...propLines,
|
|
293
327
|
"}",
|
|
294
328
|
"",
|
|
295
|
-
`export const ${
|
|
296
|
-
...
|
|
329
|
+
`export const ${wrapperName} = component$<${propsTypeName}>((props) => {`,
|
|
330
|
+
...bodyLines,
|
|
297
331
|
"});",
|
|
298
332
|
""
|
|
299
|
-
].join(
|
|
300
|
-
`);
|
|
333
|
+
].join("\n");
|
|
301
334
|
}
|
|
302
|
-
function
|
|
303
|
-
|
|
335
|
+
function toWrapperName(componentTag) {
|
|
336
|
+
const parts = componentTag.split("-").filter((part) => part.length > 0);
|
|
337
|
+
const normalizedName = parts.map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
|
|
338
|
+
return `Qwik${normalizedName}`;
|
|
304
339
|
}
|
|
305
|
-
function
|
|
306
|
-
return
|
|
340
|
+
function toPascalCase(name) {
|
|
341
|
+
return name.split(/[-_]/).filter((p) => p.length > 0).map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
|
|
307
342
|
}
|
|
308
|
-
function
|
|
309
|
-
|
|
343
|
+
function toBridgeComponentName(libraryName, mode, fallback) {
|
|
344
|
+
if (!libraryName || libraryName.trim().length === 0) return fallback;
|
|
345
|
+
return `${toPascalCase(libraryName)}${mode}BridgeComponent`;
|
|
310
346
|
}
|
|
311
|
-
function
|
|
312
|
-
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(
|
|
347
|
+
function isValidIdentifier(name) {
|
|
348
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
|
|
313
349
|
}
|
|
314
|
-
function
|
|
315
|
-
|
|
350
|
+
function toEventPropName(eventName) {
|
|
351
|
+
const normalizedName = eventName.split(/[^A-Za-z0-9]+/).filter((part) => part.length > 0).map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`).join("");
|
|
352
|
+
return `on${normalizedName}$`;
|
|
316
353
|
}
|
|
317
|
-
function
|
|
318
|
-
return
|
|
354
|
+
function resolvePackageRootForProject(packageName, runtimeResolution) {
|
|
355
|
+
return runtimeResolution?.resolveSourcePackageRoot?.(packageName ?? "");
|
|
319
356
|
}
|
|
320
|
-
function
|
|
321
|
-
const { projectId
|
|
357
|
+
function resolveRequiredPackageRuntimeImport(params) {
|
|
358
|
+
const { projectId, packageName, packageRoot, runtimeResolution, specifier, field } = params;
|
|
322
359
|
try {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
360
|
+
runtimeResolution?.resolveImportSpecifier?.(specifier, packageRoot);
|
|
361
|
+
return specifier;
|
|
362
|
+
} catch (error) {
|
|
363
|
+
throw createValidationError(getRuntimeResolutionErrorCode(field), createProjectAwareMessage(projectId, `Could not resolve Stencil ${field} runtime import "${specifier}" for source package "${packageName}": ${toErrorMessage(error)}`));
|
|
326
364
|
}
|
|
327
365
|
}
|
|
328
|
-
function
|
|
329
|
-
const { packageRoot
|
|
366
|
+
function resolveOptionalPackageRuntimeImport(params) {
|
|
367
|
+
const { packageRoot, runtimeResolution, specifier, field, observedErrorCodes } = params;
|
|
330
368
|
try {
|
|
331
|
-
|
|
369
|
+
runtimeResolution?.resolveImportSpecifier?.(specifier, packageRoot);
|
|
370
|
+
return specifier;
|
|
332
371
|
} catch {
|
|
333
|
-
|
|
334
|
-
return;
|
|
372
|
+
observedErrorCodes.push(getRuntimeResolutionErrorCode(field));
|
|
373
|
+
return void 0;
|
|
335
374
|
}
|
|
336
375
|
}
|
|
337
|
-
function
|
|
338
|
-
return
|
|
376
|
+
function getRuntimeResolutionErrorCode(field) {
|
|
377
|
+
return field === "loader" ? "QCE_STENCIL_RUNTIME_LOADER_RESOLVE_FAILED" : "QCE_STENCIL_RUNTIME_HYDRATE_RESOLVE_FAILED";
|
|
339
378
|
}
|
|
340
|
-
function
|
|
341
|
-
return
|
|
379
|
+
function createProjectAwareMessage(projectId, message) {
|
|
380
|
+
return projectId == null ? message : `Project "${projectId}": ${message}`;
|
|
342
381
|
}
|
|
343
|
-
function
|
|
344
|
-
return
|
|
382
|
+
function toErrorMessage(error) {
|
|
383
|
+
return error instanceof Error ? error.message : String(error);
|
|
345
384
|
}
|
|
346
|
-
function
|
|
347
|
-
if (
|
|
348
|
-
const
|
|
349
|
-
if (typeof
|
|
350
|
-
throw
|
|
385
|
+
function validateOptionalRuntimeOverride(runtime, field, code, message) {
|
|
386
|
+
if (runtime == null || !(field in runtime)) return void 0;
|
|
387
|
+
const value = runtime[field];
|
|
388
|
+
if (typeof value === "string" && value.trim() !== "") return value;
|
|
389
|
+
throw createValidationError(code, message);
|
|
351
390
|
}
|
|
352
|
-
function
|
|
353
|
-
return Object.assign(new Error(
|
|
354
|
-
code
|
|
391
|
+
function createValidationError(code, message) {
|
|
392
|
+
return Object.assign(new Error(message), {
|
|
393
|
+
code
|
|
355
394
|
});
|
|
356
395
|
}
|
|
357
396
|
export {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
397
|
+
augmentComponentDefinitions,
|
|
398
|
+
buildMissingCemHint,
|
|
399
|
+
createGeneratedOutput,
|
|
400
|
+
metadata,
|
|
401
|
+
probeSSR,
|
|
402
|
+
resolveRuntimeImports,
|
|
403
|
+
validateProject
|
|
364
404
|
};
|