@hubspot/cms-dev-server 0.15.10 → 0.15.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/dist/index.js +1 -1
- package/dist/internalSsr.js +3 -3
- package/dist/island-runtime.js +9 -3
- package/dist/run.js +96 -115
- package/dist/storybook-main/main.js +3 -3
- package/package.json +3 -3
- package/types/island-runtime.d.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -42,7 +42,7 @@ function resolveIslandPlugin(islandsSet) {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
45
|
+
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || ((id) => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
46
46
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
47
47
|
function clientIslandEntryPlugin() {
|
|
48
48
|
return {
|
package/dist/internalSsr.js
CHANGED
|
@@ -154,7 +154,7 @@ function resolveIslandToPlainModulePlugin(enabled = true) {
|
|
|
154
154
|
function resolveIslandToPlainModuleNoopPlugin() {
|
|
155
155
|
return resolveIslandToPlainModulePlugin(false);
|
|
156
156
|
}
|
|
157
|
-
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
157
|
+
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || ((id) => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
158
158
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
159
159
|
function clientIslandEntryPlugin() {
|
|
160
160
|
return {
|
|
@@ -187,7 +187,7 @@ function clientIslandEntryPlugin() {
|
|
|
187
187
|
}
|
|
188
188
|
};
|
|
189
189
|
}
|
|
190
|
-
var scriptTagToLogServerMessages = (messagesForBrowser, groupLabel) => {
|
|
190
|
+
var scriptTagToLogServerMessages = (messagesForBrowser, groupLabel, nonceAttribute) => {
|
|
191
191
|
if (!messagesForBrowser) {
|
|
192
192
|
return "";
|
|
193
193
|
}
|
|
@@ -211,7 +211,7 @@ var scriptTagToLogServerMessages = (messagesForBrowser, groupLabel) => {
|
|
|
211
211
|
groupEnd = ` console.groupEnd()
|
|
212
212
|
`;
|
|
213
213
|
}
|
|
214
|
-
return `<script>${groupStart}
|
|
214
|
+
return `<script ${nonceAttribute}>${groupStart}
|
|
215
215
|
${consoleLines.join("\n")}
|
|
216
216
|
${groupEnd}</script>
|
|
217
217
|
`;
|
package/dist/island-runtime.js
CHANGED
|
@@ -65,7 +65,9 @@ function finishHydratingRootAndScheduleNext(rootAndExtraInfo) {
|
|
|
65
65
|
}
|
|
66
66
|
function hydrateRoot(rootAndExtraInfo) {
|
|
67
67
|
const { rootEl, root, IslandModule, WrapperModule } = rootAndExtraInfo;
|
|
68
|
-
|
|
68
|
+
if (window.location.search.includes("hsDebug=")) {
|
|
69
|
+
console.log("Hydrating root", root.id, root.hydrateOn);
|
|
70
|
+
}
|
|
69
71
|
const postHydration = () => {
|
|
70
72
|
finishHydratingRootAndScheduleNext(rootAndExtraInfo);
|
|
71
73
|
};
|
|
@@ -157,7 +159,9 @@ function getLoadableModuleFor(root) {
|
|
|
157
159
|
function hydrateIslandRoots() {
|
|
158
160
|
if (rootsToProcess === void 0) {
|
|
159
161
|
rootsToProcess = typedWindow.__islands;
|
|
160
|
-
|
|
162
|
+
if (window.location.search.includes("hsDebug=")) {
|
|
163
|
+
console.log("Starting to hydrate", rootsToProcess);
|
|
164
|
+
}
|
|
161
165
|
if (shouldForceSeparateJsForAllIslands) {
|
|
162
166
|
console.log(" ... forcibly making every island refetch JS");
|
|
163
167
|
}
|
|
@@ -193,7 +197,9 @@ function setupIslandHydration() {
|
|
|
193
197
|
}
|
|
194
198
|
}
|
|
195
199
|
function unmountIsland(islandId) {
|
|
196
|
-
const islandToUnmount = rootsToProcess.find(
|
|
200
|
+
const islandToUnmount = rootsToProcess.find(
|
|
201
|
+
(island) => island.id === islandId
|
|
202
|
+
);
|
|
197
203
|
if (!islandToUnmount || !rootsById.get(islandId)) {
|
|
198
204
|
throw new Error(`No known island: ${islandId}`);
|
|
199
205
|
}
|
package/dist/run.js
CHANGED
|
@@ -198,7 +198,7 @@ function resolveIslandPlugin(islandsSet) {
|
|
|
198
198
|
}
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
|
-
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
201
|
+
var clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || ((id) => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
202
202
|
var virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
203
203
|
function clientIslandEntryPlugin() {
|
|
204
204
|
return {
|
|
@@ -231,7 +231,7 @@ function clientIslandEntryPlugin() {
|
|
|
231
231
|
}
|
|
232
232
|
};
|
|
233
233
|
}
|
|
234
|
-
var scriptTagToLogServerMessages = (messagesForBrowser, groupLabel) => {
|
|
234
|
+
var scriptTagToLogServerMessages = (messagesForBrowser, groupLabel, nonceAttribute) => {
|
|
235
235
|
if (!messagesForBrowser) {
|
|
236
236
|
return "";
|
|
237
237
|
}
|
|
@@ -255,7 +255,7 @@ var scriptTagToLogServerMessages = (messagesForBrowser, groupLabel) => {
|
|
|
255
255
|
groupEnd = ` console.groupEnd()
|
|
256
256
|
`;
|
|
257
257
|
}
|
|
258
|
-
return `<script>${groupStart}
|
|
258
|
+
return `<script ${nonceAttribute}>${groupStart}
|
|
259
259
|
${consoleLines.join("\n")}
|
|
260
260
|
${groupEnd}</script>
|
|
261
261
|
`;
|
|
@@ -1047,7 +1047,7 @@ function trackUsage(action) {
|
|
|
1047
1047
|
eventName: EVENT_NAME,
|
|
1048
1048
|
action,
|
|
1049
1049
|
nodeVersion: getNodeVersionData(),
|
|
1050
|
-
version: "0.15.
|
|
1050
|
+
version: "0.15.12",
|
|
1051
1051
|
os: getPlatform()
|
|
1052
1052
|
};
|
|
1053
1053
|
const uri = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -1150,9 +1150,10 @@ var partialRouteHandler = async (request2, response) => {
|
|
|
1150
1150
|
);
|
|
1151
1151
|
const html = htmlShell.replace(
|
|
1152
1152
|
"<!--headend-->",
|
|
1153
|
-
[
|
|
1154
|
-
|
|
1155
|
-
|
|
1153
|
+
[
|
|
1154
|
+
cssNeeded,
|
|
1155
|
+
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
1156
|
+
].join("\n")
|
|
1156
1157
|
).replace(`<!--ssr-outlet-->`, renderedHtml);
|
|
1157
1158
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
1158
1159
|
} catch (e) {
|
|
@@ -1366,9 +1367,7 @@ async function renderModule(viteServer, requestedModulePath, moduleProps, pageUr
|
|
|
1366
1367
|
throw new Error(`Module does not have a named meta export: ${foundPath}`);
|
|
1367
1368
|
}
|
|
1368
1369
|
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
1369
|
-
const { renderFieldsToJson } = await viteServer.ssrLoadModule(
|
|
1370
|
-
internalSsrPath
|
|
1371
|
-
);
|
|
1370
|
+
const { renderFieldsToJson } = await viteServer.ssrLoadModule(internalSsrPath);
|
|
1372
1371
|
const fieldsJSON = renderFieldsToJson(fields, requestedModulePath);
|
|
1373
1372
|
const fieldValues = getFieldValuesForModule(fieldsJSON, fieldOverrides);
|
|
1374
1373
|
const applyFieldsValidationToRenderContext = getApplyFieldsValidationToRenderContext(
|
|
@@ -1541,9 +1540,10 @@ var moduleRouteHandler = async (request2, response) => {
|
|
|
1541
1540
|
);
|
|
1542
1541
|
const html = htmlShell.replace(
|
|
1543
1542
|
"<!--headend-->",
|
|
1544
|
-
[
|
|
1545
|
-
|
|
1546
|
-
|
|
1543
|
+
[
|
|
1544
|
+
cssNeeded,
|
|
1545
|
+
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
1546
|
+
].join("\n")
|
|
1547
1547
|
).replace(`<!--ssr-outlet-->`, renderedHtml);
|
|
1548
1548
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
1549
1549
|
} catch (e) {
|
|
@@ -2572,7 +2572,7 @@ async function modulePreviewRouteHandler(request2, response) {
|
|
|
2572
2572
|
const modulePath = normalizePath5(
|
|
2573
2573
|
path6.resolve(webRoot2, "components/modules/", moduleName)
|
|
2574
2574
|
);
|
|
2575
|
-
const basePath = getEntryPointBasePath(modulePath)
|
|
2575
|
+
const basePath = `preview/${getEntryPointBasePath(modulePath)}`;
|
|
2576
2576
|
const environmentConfig = buildStaticEnvConfig4(
|
|
2577
2577
|
authedPortalId,
|
|
2578
2578
|
authedHublet,
|
|
@@ -2613,9 +2613,7 @@ async function modulePreviewRouteHandler(request2, response) {
|
|
|
2613
2613
|
throw new Error(`Module does not have a named meta export: ${foundPath}`);
|
|
2614
2614
|
}
|
|
2615
2615
|
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
2616
|
-
const { renderFieldsToJson } = await viteServer.ssrLoadModule(
|
|
2617
|
-
internalSsrPath
|
|
2618
|
-
);
|
|
2616
|
+
const { renderFieldsToJson } = await viteServer.ssrLoadModule(internalSsrPath);
|
|
2619
2617
|
const localFieldsJson = renderFieldsToJson(fields, modulePath);
|
|
2620
2618
|
const localModule = {
|
|
2621
2619
|
isJsModule: true,
|
|
@@ -2696,9 +2694,10 @@ async function modulePreviewRouteHandler(request2, response) {
|
|
|
2696
2694
|
);
|
|
2697
2695
|
const html = htmlShell.replace(
|
|
2698
2696
|
"<!--headend-->",
|
|
2699
|
-
[
|
|
2700
|
-
|
|
2701
|
-
|
|
2697
|
+
[
|
|
2698
|
+
cssNeeded,
|
|
2699
|
+
...inlineAssets.map((inlineAsset) => inlineAsset.html)
|
|
2700
|
+
].join("\n")
|
|
2702
2701
|
).replace(`<!--ssr-outlet-->`, renderedHtml);
|
|
2703
2702
|
response.status(200).set({ "Content-Type": "text/html" }).end(html);
|
|
2704
2703
|
} catch (e) {
|
|
@@ -3193,7 +3192,6 @@ import { get as hsGet6 } from "@hubspot/cli-lib/http.js";
|
|
|
3193
3192
|
// ../cms-js-internal/dist/buildFieldsTypes.js
|
|
3194
3193
|
import { writeFileSync } from "fs";
|
|
3195
3194
|
import ts from "typescript";
|
|
3196
|
-
import React, { isValidElement } from "react";
|
|
3197
3195
|
var fieldTypeNameByType = {
|
|
3198
3196
|
alignment: "AlignmentFieldType",
|
|
3199
3197
|
audioplayer: "AudioFieldType",
|
|
@@ -3241,60 +3239,9 @@ var fieldTypeNameByType = {
|
|
|
3241
3239
|
video: "VideoFieldType",
|
|
3242
3240
|
workflow: "WorkflowFieldType"
|
|
3243
3241
|
};
|
|
3244
|
-
var getChildrenAsArray = (element) => React.Children.toArray(element.props.children);
|
|
3245
3242
|
function getFieldEntries(fields) {
|
|
3246
|
-
if (isValidElement(fields)) {
|
|
3247
|
-
const fieldsJSX = getChildrenAsArray(fields);
|
|
3248
|
-
return getReactFieldEntries(fieldsJSX);
|
|
3249
|
-
} else if (Array.isArray(fields)) {
|
|
3250
|
-
return getJSONFieldEntries(fields);
|
|
3251
|
-
}
|
|
3252
|
-
return void 0;
|
|
3253
|
-
}
|
|
3254
|
-
var getJSXFieldType = (fieldFunctionName) => {
|
|
3255
|
-
switch (fieldFunctionName) {
|
|
3256
|
-
case "RepeatedFieldGroup":
|
|
3257
|
-
case "FieldGroup":
|
|
3258
|
-
return "GroupFieldType";
|
|
3259
|
-
default:
|
|
3260
|
-
return `${fieldFunctionName}Type`;
|
|
3261
|
-
}
|
|
3262
|
-
};
|
|
3263
|
-
var getElementName = (element) => typeof element.type === "string" ? element.type : element.type.name || null;
|
|
3264
|
-
function getReactFieldEntries(fields) {
|
|
3265
|
-
const validTypeNames = Object.values(fieldTypeNameByType);
|
|
3266
|
-
if (!Array.isArray(fields)) {
|
|
3267
|
-
return;
|
|
3268
|
-
}
|
|
3269
|
-
return fields.filter((field) => field.props && field.props.name).map((field) => {
|
|
3270
|
-
const elName = getElementName(field);
|
|
3271
|
-
const fieldType = getJSXFieldType(getElementName(field));
|
|
3272
|
-
if (!validTypeNames.includes(fieldType)) {
|
|
3273
|
-
return void 0;
|
|
3274
|
-
}
|
|
3275
|
-
const { name, default: hasDefault } = field.props;
|
|
3276
|
-
const isRepeater = elName === "RepeatedFieldGroup";
|
|
3277
|
-
const entry = {
|
|
3278
|
-
type: fieldType,
|
|
3279
|
-
name,
|
|
3280
|
-
hasDefault: !!hasDefault,
|
|
3281
|
-
isRepeater,
|
|
3282
|
-
children: []
|
|
3283
|
-
};
|
|
3284
|
-
if (fieldType === "GroupFieldType") {
|
|
3285
|
-
const childrenArray = getChildrenAsArray(field);
|
|
3286
|
-
const children = getReactFieldEntries(childrenArray);
|
|
3287
|
-
return {
|
|
3288
|
-
...entry,
|
|
3289
|
-
children
|
|
3290
|
-
};
|
|
3291
|
-
}
|
|
3292
|
-
return entry;
|
|
3293
|
-
}).filter((entry) => entry !== void 0);
|
|
3294
|
-
}
|
|
3295
|
-
function getJSONFieldEntries(fields) {
|
|
3296
3243
|
if (!Array.isArray(fields)) {
|
|
3297
|
-
return;
|
|
3244
|
+
return void 0;
|
|
3298
3245
|
}
|
|
3299
3246
|
return fields.filter((field) => field.name && field.type).map((field) => {
|
|
3300
3247
|
const { name, type } = field;
|
|
@@ -3306,24 +3253,39 @@ function getJSONFieldEntries(fields) {
|
|
|
3306
3253
|
type: fieldType,
|
|
3307
3254
|
name,
|
|
3308
3255
|
isRepeater: "occurrence" in field,
|
|
3309
|
-
|
|
3256
|
+
isRequired: !!field.required,
|
|
3257
|
+
choices: (
|
|
3258
|
+
// Choices are pair [value, label] but only the value is printed to the page, so flatten it.
|
|
3259
|
+
"choices" in field ? field.choices.map(([value]) => value) : void 0
|
|
3260
|
+
),
|
|
3310
3261
|
children: []
|
|
3311
3262
|
};
|
|
3312
3263
|
if (fieldType === "GroupFieldType" && "children" in field) {
|
|
3313
|
-
const children =
|
|
3264
|
+
const children = getFieldEntries(field.children);
|
|
3314
3265
|
return { ...entry, children };
|
|
3315
3266
|
}
|
|
3316
3267
|
return entry;
|
|
3317
3268
|
}).filter((entry) => entry !== void 0);
|
|
3318
3269
|
}
|
|
3319
|
-
var
|
|
3320
|
-
var
|
|
3321
|
-
var
|
|
3270
|
+
var INVALID_IMPORTS = ["ChoiceFieldType", "GroupFieldType"];
|
|
3271
|
+
var FIELD_GROUP_TYPE = "FieldGroupWithChildren";
|
|
3272
|
+
var REPEATER_GROUP_TYPE = "RepeaterGroup";
|
|
3273
|
+
var REQUIRED_TYPE = "RequiredField";
|
|
3322
3274
|
var DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
3323
3275
|
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
3324
3276
|
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
3325
3277
|
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
3326
|
-
var createPropertySignature = (identifier, type) => ts.factory.createPropertySignature(
|
|
3278
|
+
var createPropertySignature = (identifier, type, hasQuestionToken = false) => ts.factory.createPropertySignature(
|
|
3279
|
+
[],
|
|
3280
|
+
identifier,
|
|
3281
|
+
hasQuestionToken ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : void 0,
|
|
3282
|
+
type
|
|
3283
|
+
);
|
|
3284
|
+
var createUnionTypeFromArray = (values) => ts.factory.createUnionTypeNode(
|
|
3285
|
+
values.map(
|
|
3286
|
+
(value) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value))
|
|
3287
|
+
)
|
|
3288
|
+
);
|
|
3327
3289
|
var buildTypeFromField = (field, additionalNode) => {
|
|
3328
3290
|
const imports = [field.type];
|
|
3329
3291
|
const identifier = ts.factory.createIdentifier(field.name);
|
|
@@ -3331,26 +3293,41 @@ var buildTypeFromField = (field, additionalNode) => {
|
|
|
3331
3293
|
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
3332
3294
|
baseType
|
|
3333
3295
|
]);
|
|
3334
|
-
let finalType = field.
|
|
3296
|
+
let finalType = field.isRequired ? requiredType : baseType;
|
|
3297
|
+
if (field.choices) {
|
|
3298
|
+
finalType = createUnionTypeFromArray(field.choices);
|
|
3299
|
+
}
|
|
3300
|
+
if (field.isRequired) {
|
|
3301
|
+
imports.push(REQUIRED_TYPE);
|
|
3302
|
+
}
|
|
3335
3303
|
if (additionalNode) {
|
|
3336
3304
|
const typeLiteral = ts.isTypeLiteralNode(additionalNode) ? additionalNode : ts.factory.createTypeLiteralNode([additionalNode]);
|
|
3337
|
-
const
|
|
3338
|
-
|
|
3339
|
-
);
|
|
3340
|
-
if (!field.isRepeater) {
|
|
3341
|
-
imports.push(OVERRIDE_TYPE);
|
|
3342
|
-
}
|
|
3343
|
-
finalType = field.isRepeater ? ts.factory.createTypeReferenceNode("Array", [
|
|
3344
|
-
ts.factory.createTypeReferenceNode("Record", [
|
|
3345
|
-
repeaterName,
|
|
3346
|
-
typeLiteral
|
|
3347
|
-
])
|
|
3348
|
-
]) : ts.factory.createTypeReferenceNode(OVERRIDE_TYPE, [
|
|
3349
|
-
finalType,
|
|
3350
|
-
typeLiteral
|
|
3351
|
-
]);
|
|
3305
|
+
const genericType = field.isRepeater ? REPEATER_GROUP_TYPE : FIELD_GROUP_TYPE;
|
|
3306
|
+
imports.push(genericType);
|
|
3307
|
+
finalType = ts.factory.createTypeReferenceNode(genericType, [typeLiteral]);
|
|
3352
3308
|
}
|
|
3353
|
-
return {
|
|
3309
|
+
return {
|
|
3310
|
+
type: createPropertySignature(
|
|
3311
|
+
identifier,
|
|
3312
|
+
finalType,
|
|
3313
|
+
!field.isRequired && !additionalNode
|
|
3314
|
+
),
|
|
3315
|
+
imports
|
|
3316
|
+
};
|
|
3317
|
+
};
|
|
3318
|
+
var filterUnusedImports = (imports, type) => {
|
|
3319
|
+
const usedImports = /* @__PURE__ */ new Set();
|
|
3320
|
+
const visit = (node) => {
|
|
3321
|
+
if (ts.isTypeReferenceNode(node)) {
|
|
3322
|
+
const typeName = node.typeName;
|
|
3323
|
+
if ("escapedText" in typeName) {
|
|
3324
|
+
usedImports.add(typeName.escapedText.toString());
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
ts.forEachChild(node, visit);
|
|
3328
|
+
};
|
|
3329
|
+
visit(type);
|
|
3330
|
+
return imports.filter((name) => usedImports.has(name));
|
|
3354
3331
|
};
|
|
3355
3332
|
function getImportDeclaration(imports, moduleSpecifier) {
|
|
3356
3333
|
const importSpecifiers = Array.from(imports).map(
|
|
@@ -3369,20 +3346,16 @@ function getImportDeclaration(imports, moduleSpecifier) {
|
|
|
3369
3346
|
);
|
|
3370
3347
|
}
|
|
3371
3348
|
function getFieldTypes(fields) {
|
|
3372
|
-
const imports = [
|
|
3349
|
+
const imports = [];
|
|
3373
3350
|
const types = fields.map((field) => {
|
|
3374
3351
|
if (field.children) {
|
|
3375
3352
|
const childrenResult = getFieldTypes(field.children);
|
|
3376
3353
|
imports.push(...childrenResult.imports);
|
|
3377
3354
|
if (childrenResult.types.length) {
|
|
3378
3355
|
const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
|
|
3379
|
-
const childrenPropertySignature = createPropertySignature(
|
|
3380
|
-
"children",
|
|
3381
|
-
subType
|
|
3382
|
-
);
|
|
3383
3356
|
const { type: type2, imports: newImports2 } = buildTypeFromField(
|
|
3384
3357
|
field,
|
|
3385
|
-
|
|
3358
|
+
subType
|
|
3386
3359
|
);
|
|
3387
3360
|
imports.push(...newImports2);
|
|
3388
3361
|
return type2;
|
|
@@ -3392,14 +3365,13 @@ function getFieldTypes(fields) {
|
|
|
3392
3365
|
imports.push(...newImports);
|
|
3393
3366
|
return type;
|
|
3394
3367
|
});
|
|
3395
|
-
|
|
3368
|
+
const validImports = Array.from(
|
|
3369
|
+
new Set(imports.filter((name) => !INVALID_IMPORTS.includes(name)))
|
|
3370
|
+
);
|
|
3371
|
+
return { types, imports: validImports };
|
|
3396
3372
|
}
|
|
3397
3373
|
function constructFinalType(fields, typeName) {
|
|
3398
3374
|
const { types, imports } = getFieldTypes(fields);
|
|
3399
|
-
const importDeclaration = getImportDeclaration(
|
|
3400
|
-
imports,
|
|
3401
|
-
CMS_COMPONENTS_FIELD_TYPES
|
|
3402
|
-
);
|
|
3403
3375
|
const baseType = ts.factory.createTypeAliasDeclaration(
|
|
3404
3376
|
[],
|
|
3405
3377
|
[],
|
|
@@ -3417,6 +3389,11 @@ function constructFinalType(fields, typeName) {
|
|
|
3417
3389
|
void 0,
|
|
3418
3390
|
wrappedType
|
|
3419
3391
|
);
|
|
3392
|
+
const filteredImports = filterUnusedImports(imports, finalType);
|
|
3393
|
+
const importDeclaration = getImportDeclaration(
|
|
3394
|
+
[...filteredImports, DEFAULT_VALUES_TYPE],
|
|
3395
|
+
CMS_COMPONENTS_FIELD_TYPES
|
|
3396
|
+
);
|
|
3420
3397
|
const defaultExport = ts.factory.createExportDefault(
|
|
3421
3398
|
ts.factory.createIdentifier(typeName)
|
|
3422
3399
|
);
|
|
@@ -3502,22 +3479,22 @@ var getIndexFile = (filePath, projectRoot) => {
|
|
|
3502
3479
|
const indexFileName = files.find((file) => file.startsWith("index."));
|
|
3503
3480
|
return indexFileName ? { indexFilePath: path8.join(dir, indexFileName), isRootModuleFile } : void 0;
|
|
3504
3481
|
};
|
|
3505
|
-
var getIndexFileFields = async (indexFilePath, viteServer) => {
|
|
3482
|
+
var getIndexFileFields = async (indexFilePath, indexFileName, viteServer) => {
|
|
3506
3483
|
let indexFile;
|
|
3484
|
+
let renderFieldsToJson;
|
|
3507
3485
|
try {
|
|
3508
3486
|
indexFile = await viteServer.ssrLoadModule(indexFilePath);
|
|
3487
|
+
const internalSsrPath = packagePath(import.meta.url, "internalSsr");
|
|
3488
|
+
({ renderFieldsToJson } = await viteServer.ssrLoadModule(internalSsrPath));
|
|
3509
3489
|
} catch (e) {
|
|
3510
3490
|
return void 0;
|
|
3511
3491
|
}
|
|
3512
3492
|
if (!indexFile.fields)
|
|
3513
3493
|
return void 0;
|
|
3514
3494
|
const fields = indexFile.fields;
|
|
3515
|
-
const
|
|
3516
|
-
const
|
|
3517
|
-
|
|
3518
|
-
return fields;
|
|
3519
|
-
}
|
|
3520
|
-
return void 0;
|
|
3495
|
+
const renderedFieldsJson = renderFieldsToJson(fields, indexFileName);
|
|
3496
|
+
const isValidFields = Array.isArray(renderedFieldsJson);
|
|
3497
|
+
return isValidFields ? renderedFieldsJson : void 0;
|
|
3521
3498
|
};
|
|
3522
3499
|
var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
3523
3500
|
const indexInfo = getIndexFile(filePath, projectRoot);
|
|
@@ -3528,7 +3505,11 @@ var maybeUpdateFields = async (filePath, viteServer, projectRoot) => {
|
|
|
3528
3505
|
const isTypeFile = filePath.endsWith(".types.ts");
|
|
3529
3506
|
if (isTypeFile)
|
|
3530
3507
|
return;
|
|
3531
|
-
const fields = await getIndexFileFields(
|
|
3508
|
+
const fields = await getIndexFileFields(
|
|
3509
|
+
indexFilePath,
|
|
3510
|
+
indexFileName,
|
|
3511
|
+
viteServer
|
|
3512
|
+
);
|
|
3532
3513
|
if (fields) {
|
|
3533
3514
|
const typeFileName = isRootModuleFile ? `${indexFileName}.fields.types.ts` : "fields.type.ts";
|
|
3534
3515
|
const typeFilePath = path8.join(path8.dirname(filePath), typeFileName);
|
|
@@ -341,9 +341,9 @@ var init_basicUtils = __esm({
|
|
|
341
341
|
">": "\\u003E",
|
|
342
342
|
"/": "\\u002F"
|
|
343
343
|
};
|
|
344
|
-
clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || (id => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
344
|
+
clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport * as cmsComponents from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nconst buildIslandIdentifierPrefix =\n cmsComponents.buildIslandIdentifierPrefix || ((id) => id);\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: React.ComponentType<any>\n) {\n const {\n island,\n rootElement,\n postHydration,\n pageUrl,\n islands,\n basePath,\n WrapperModule,\n } = renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: buildIslandIdentifierPrefix(renderableIsland.island.id),\n };\n\n let innerComponent = <Component islandId={island.id} {...island.props} />;\n if (WrapperModule) {\n innerComponent = <WrapperModule>{innerComponent}</WrapperModule>;\n }\n\n const elementsToHydrate = (\n <Suspense fallback={`client hydrate fail/waiting for ${island.id}`}>\n <ClientRenderContextProvider\n pageUrl={pageUrl}\n islands={islands}\n onTopLevelHydrationFinish={postHydration}\n island={island}\n basePath={basePath}\n >\n {innerComponent}\n </ClientRenderContextProvider>\n </Suspense>\n );\n\n if (island.clientOnly) {\n reactRoot = ReactDOMClient.createRoot(rootElement, rootOptions);\n reactRoot.render(elementsToHydrate);\n } else {\n reactRoot = ReactDOMClient.hydrateRoot(\n rootElement,\n elementsToHydrate,\n rootOptions\n );\n }\n return reactRoot;\n}\n";
|
|
345
345
|
virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
346
|
-
scriptTagToLogServerMessages = (messagesForBrowser, groupLabel) => {
|
|
346
|
+
scriptTagToLogServerMessages = (messagesForBrowser, groupLabel, nonceAttribute) => {
|
|
347
347
|
if (!messagesForBrowser) {
|
|
348
348
|
return "";
|
|
349
349
|
}
|
|
@@ -367,7 +367,7 @@ var init_basicUtils = __esm({
|
|
|
367
367
|
groupEnd = ` console.groupEnd()
|
|
368
368
|
`;
|
|
369
369
|
}
|
|
370
|
-
return `<script>${groupStart}
|
|
370
|
+
return `<script ${nonceAttribute}>${groupStart}
|
|
371
371
|
${consoleLines.join("\n")}
|
|
372
372
|
${groupEnd}</script>
|
|
373
373
|
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.12",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@hubspot/cli-lib": "^3.0.12",
|
|
29
|
-
"@hubspot/cms-components": "^0.15.
|
|
29
|
+
"@hubspot/cms-components": "^0.15.12",
|
|
30
30
|
"@inquirer/select": "^2.0.0",
|
|
31
31
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
32
32
|
"@storybook/addon-actions": "7.1.1",
|
|
@@ -108,5 +108,5 @@
|
|
|
108
108
|
"publishConfig": {
|
|
109
109
|
"access": "public"
|
|
110
110
|
},
|
|
111
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "13db7ec0fca12c54eeed388bf3a3a261205d9ede"
|
|
112
112
|
}
|