@hubspot/cms-dev-server 0.15.11 → 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 +66 -53
- 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) {
|
|
@@ -3254,7 +3253,7 @@ function getFieldEntries(fields) {
|
|
|
3254
3253
|
type: fieldType,
|
|
3255
3254
|
name,
|
|
3256
3255
|
isRepeater: "occurrence" in field,
|
|
3257
|
-
|
|
3256
|
+
isRequired: !!field.required,
|
|
3258
3257
|
choices: (
|
|
3259
3258
|
// Choices are pair [value, label] but only the value is printed to the page, so flatten it.
|
|
3260
3259
|
"choices" in field ? field.choices.map(([value]) => value) : void 0
|
|
@@ -3268,15 +3267,20 @@ function getFieldEntries(fields) {
|
|
|
3268
3267
|
return entry;
|
|
3269
3268
|
}).filter((entry) => entry !== void 0);
|
|
3270
3269
|
}
|
|
3271
|
-
var INVALID_IMPORTS = ["ChoiceFieldType"];
|
|
3272
|
-
var
|
|
3273
|
-
var
|
|
3274
|
-
var
|
|
3270
|
+
var INVALID_IMPORTS = ["ChoiceFieldType", "GroupFieldType"];
|
|
3271
|
+
var FIELD_GROUP_TYPE = "FieldGroupWithChildren";
|
|
3272
|
+
var REPEATER_GROUP_TYPE = "RepeaterGroup";
|
|
3273
|
+
var REQUIRED_TYPE = "RequiredField";
|
|
3275
3274
|
var DEFAULT_VALUES_TYPE = "DefaultValues";
|
|
3276
3275
|
var CMS_COMPONENTS = "@hubspot/cms-components";
|
|
3277
3276
|
var CMS_COMPONENTS_FIELD_TYPES = `${CMS_COMPONENTS}/fields`;
|
|
3278
3277
|
var AUTO_GEN_COMMENT = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.";
|
|
3279
|
-
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
|
+
);
|
|
3280
3284
|
var createUnionTypeFromArray = (values) => ts.factory.createUnionTypeNode(
|
|
3281
3285
|
values.map(
|
|
3282
3286
|
(value) => ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(value))
|
|
@@ -3289,29 +3293,41 @@ var buildTypeFromField = (field, additionalNode) => {
|
|
|
3289
3293
|
const requiredType = ts.factory.createTypeReferenceNode(REQUIRED_TYPE, [
|
|
3290
3294
|
baseType
|
|
3291
3295
|
]);
|
|
3292
|
-
let finalType = field.
|
|
3296
|
+
let finalType = field.isRequired ? requiredType : baseType;
|
|
3293
3297
|
if (field.choices) {
|
|
3294
3298
|
finalType = createUnionTypeFromArray(field.choices);
|
|
3295
3299
|
}
|
|
3300
|
+
if (field.isRequired) {
|
|
3301
|
+
imports.push(REQUIRED_TYPE);
|
|
3302
|
+
}
|
|
3296
3303
|
if (additionalNode) {
|
|
3297
3304
|
const typeLiteral = ts.isTypeLiteralNode(additionalNode) ? additionalNode : ts.factory.createTypeLiteralNode([additionalNode]);
|
|
3298
|
-
const
|
|
3299
|
-
|
|
3300
|
-
);
|
|
3301
|
-
if (!field.isRepeater) {
|
|
3302
|
-
imports.push(OVERRIDE_TYPE);
|
|
3303
|
-
}
|
|
3304
|
-
finalType = field.isRepeater ? ts.factory.createTypeReferenceNode("Array", [
|
|
3305
|
-
ts.factory.createTypeReferenceNode("Record", [
|
|
3306
|
-
repeaterName,
|
|
3307
|
-
typeLiteral
|
|
3308
|
-
])
|
|
3309
|
-
]) : ts.factory.createTypeReferenceNode(OVERRIDE_TYPE, [
|
|
3310
|
-
finalType,
|
|
3311
|
-
typeLiteral
|
|
3312
|
-
]);
|
|
3305
|
+
const genericType = field.isRepeater ? REPEATER_GROUP_TYPE : FIELD_GROUP_TYPE;
|
|
3306
|
+
imports.push(genericType);
|
|
3307
|
+
finalType = ts.factory.createTypeReferenceNode(genericType, [typeLiteral]);
|
|
3313
3308
|
}
|
|
3314
|
-
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));
|
|
3315
3331
|
};
|
|
3316
3332
|
function getImportDeclaration(imports, moduleSpecifier) {
|
|
3317
3333
|
const importSpecifiers = Array.from(imports).map(
|
|
@@ -3330,20 +3346,16 @@ function getImportDeclaration(imports, moduleSpecifier) {
|
|
|
3330
3346
|
);
|
|
3331
3347
|
}
|
|
3332
3348
|
function getFieldTypes(fields) {
|
|
3333
|
-
const imports = [
|
|
3349
|
+
const imports = [];
|
|
3334
3350
|
const types = fields.map((field) => {
|
|
3335
3351
|
if (field.children) {
|
|
3336
3352
|
const childrenResult = getFieldTypes(field.children);
|
|
3337
3353
|
imports.push(...childrenResult.imports);
|
|
3338
3354
|
if (childrenResult.types.length) {
|
|
3339
3355
|
const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
|
|
3340
|
-
const childrenPropertySignature = createPropertySignature(
|
|
3341
|
-
"children",
|
|
3342
|
-
subType
|
|
3343
|
-
);
|
|
3344
3356
|
const { type: type2, imports: newImports2 } = buildTypeFromField(
|
|
3345
3357
|
field,
|
|
3346
|
-
|
|
3358
|
+
subType
|
|
3347
3359
|
);
|
|
3348
3360
|
imports.push(...newImports2);
|
|
3349
3361
|
return type2;
|
|
@@ -3360,10 +3372,6 @@ function getFieldTypes(fields) {
|
|
|
3360
3372
|
}
|
|
3361
3373
|
function constructFinalType(fields, typeName) {
|
|
3362
3374
|
const { types, imports } = getFieldTypes(fields);
|
|
3363
|
-
const importDeclaration = getImportDeclaration(
|
|
3364
|
-
imports,
|
|
3365
|
-
CMS_COMPONENTS_FIELD_TYPES
|
|
3366
|
-
);
|
|
3367
3375
|
const baseType = ts.factory.createTypeAliasDeclaration(
|
|
3368
3376
|
[],
|
|
3369
3377
|
[],
|
|
@@ -3381,6 +3389,11 @@ function constructFinalType(fields, typeName) {
|
|
|
3381
3389
|
void 0,
|
|
3382
3390
|
wrappedType
|
|
3383
3391
|
);
|
|
3392
|
+
const filteredImports = filterUnusedImports(imports, finalType);
|
|
3393
|
+
const importDeclaration = getImportDeclaration(
|
|
3394
|
+
[...filteredImports, DEFAULT_VALUES_TYPE],
|
|
3395
|
+
CMS_COMPONENTS_FIELD_TYPES
|
|
3396
|
+
);
|
|
3384
3397
|
const defaultExport = ts.factory.createExportDefault(
|
|
3385
3398
|
ts.factory.createIdentifier(typeName)
|
|
3386
3399
|
);
|
|
@@ -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
|
}
|