@hubspot/cms-dev-server 1.1.0-prerelease.9 → 1.2.0
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/app/assets/LexendDeca-Bold-B8uERmr8.woff2 +0 -0
- package/dist/app/assets/LexendDeca-Light-BtcvwT5C.woff2 +0 -0
- package/dist/app/assets/LexendDeca-Medium-CxVPR2j6.woff2 +0 -0
- package/dist/app/assets/LexendDeca-SemiBold-BhzS3XUP.woff2 +0 -0
- package/dist/app/assets/index-PcyCbkys.css +1 -0
- package/dist/app/assets/index-tvg7JxpD.js +164 -0
- package/dist/app/index.html +15 -0
- package/dist/app/server/assets/RenderTreeSeparately-T6CL43QJ-D50VfKo0.js +111 -0
- package/dist/app/server/serverEntry.js +3641 -0
- package/dist/generateJsonFromJsx.js +744 -0
- package/dist/html/baseTemplate.html +1 -0
- package/dist/index.js +5800 -0
- package/dist/internalSsr.js +1312 -0
- package/dist/island-runtime.js +267 -0
- package/dist/run.js +6495 -4
- package/dist/storybook/index.js +241 -0
- package/dist/storybook-main/main.js +1457 -0
- package/dist/storybook-main/preview.js +21 -0
- package/package.json +93 -24
- package/types/api/designmanager.d.ts +44 -0
- package/types/api/project.d.ts +5 -0
- package/types/api/session.d.ts +2 -0
- package/types/components/HubLModulesList.d.ts +4 -0
- package/types/components/HubLTemplatesList.d.ts +5 -0
- package/types/components/ModulesList.d.ts +5 -0
- package/types/components/PartialsList.d.ts +4 -0
- package/types/createAppServer.d.ts +3 -0
- package/types/createDevServer.d.ts +5 -0
- package/types/createViteDevServer.d.ts +6 -0
- package/types/fileManager.d.ts +4 -0
- package/types/index.d.ts +2 -0
- package/types/lib/cliUtils.d.ts +15 -0
- package/types/lib/configHelpers.d.ts +2 -0
- package/types/lib/criticalDevErrorsToServerMessages.d.ts +4 -0
- package/types/lib/debug.d.ts +1 -0
- package/types/lib/errors.d.ts +6 -0
- package/types/lib/fetchModuleGraphQLData.d.ts +24 -0
- package/types/lib/fullOriginalUrlFromRequest.d.ts +2 -0
- package/types/lib/gates.d.ts +2 -0
- package/types/lib/getDevServerUIData.d.ts +60 -0
- package/types/lib/getFieldValuesForModule.d.ts +2 -0
- package/types/lib/getJSRenderingGates.d.ts +8 -0
- package/types/lib/httpsRedirectingServer.d.ts +11 -0
- package/types/lib/logColors.d.ts +6 -0
- package/types/lib/moduleGraph.d.ts +1 -0
- package/types/lib/packagePath.d.ts +1 -0
- package/types/lib/pathHelpers.d.ts +3 -0
- package/types/lib/previewUtils.d.ts +22 -0
- package/types/lib/proxyHelpers.d.ts +29 -0
- package/types/lib/renderComponentWithCSS.d.ts +14 -0
- package/types/lib/renderHelpers.d.ts +1 -0
- package/types/lib/renderModule.d.ts +11 -0
- package/types/lib/renderModuleFieldsJson.d.ts +4 -0
- package/types/lib/renderModulePreview.d.ts +6 -0
- package/types/lib/renderPartial.d.ts +5 -0
- package/types/lib/templates.d.ts +4 -0
- package/types/lib/trackUsage.d.ts +3 -0
- package/types/lib/validateHSPlatform.d.ts +3 -0
- package/types/lib/watchFieldsUpdates.d.ts +22 -0
- package/types/plugins/cmsComponentsShimPlugin.d.ts +11 -0
- package/types/plugins/devSecretsPlugin.d.ts +2 -0
- package/types/plugins/hsStaticAssetPlugin.d.ts +2 -0
- package/types/proxyPage/constants.d.ts +1 -0
- package/types/proxyPage/fetchContentMetadata.d.ts +7 -0
- package/types/proxyPage/fetchDomains.d.ts +9 -0
- package/types/proxyPage/fetchPreviewInfo.d.ts +7 -0
- package/types/proxyPage/proxyPage.d.ts +11 -0
- package/types/proxyPage/renderLocalError.d.ts +2 -0
- package/types/proxyPage/utils.d.ts +4 -0
- package/types/routes/appServerRouteHandler.d.ts +3 -0
- package/types/routes/createAppServerAPIRoutes.d.ts +5 -0
- package/types/routes/createDevServerRoutes.d.ts +4 -0
- package/types/routes/hublModuleRouteHandler.d.ts +2 -0
- package/types/routes/hublTemplateRouteHandler.d.ts +2 -0
- package/types/routes/legacyRouteHandler.d.ts +3 -0
- package/types/routes/linksToAllModulesRouteHandler.d.ts +2 -0
- package/types/routes/linksToAllPartialsRouteHandler.d.ts +2 -0
- package/types/routes/module.d.ts +3 -0
- package/types/routes/moduleFieldsJson.d.ts +3 -0
- package/types/routes/modulePreviewRouteHandler.d.ts +3 -0
- package/types/routes/partial.d.ts +2 -0
- package/types/routes/proxyPageResourceRedirect.d.ts +2 -0
- package/types/routes/proxyPageRouteHandler.d.ts +2 -0
- package/types/routes/proxyPathPageResourceRedirect.d.ts +2 -0
- package/types/routes/proxyPathPageRouteHandler.d.ts +2 -0
- package/types/routes/proxyServerlessHandler.d.ts +2 -0
- package/types/routes/remoteFsDirtyHandler.d.ts +2 -0
- package/types/shadowDevServer/createShadowDevServerRoutes.d.ts +1 -0
- package/types/shadowDevServer/startShadowDevServer.d.ts +1 -0
- package/types/storybook/getFieldsArgTypes.d.ts +3 -0
- package/types/storybook/getNestedFieldObjectForArgs.d.ts +6 -0
- package/types/storybook/index.d.ts +1 -0
- package/types/storybook/moduleStory.d.ts +5 -0
- package/types/storybook/types.d.ts +15 -0
- package/dist/components/ModulesList.js +0 -14
- package/dist/components/PartialsList.js +0 -13
- package/dist/createDevServer.js +0 -26
- package/dist/createViteDevServer.js +0 -26
- package/dist/lib/createIslandsGlobalJsForClientInDev.js +0 -32
- package/dist/lib/fullOriginalUrlFromRequest.js +0 -3
- package/dist/lib/htmlHelpers.js +0 -10
- package/dist/lib/moduleGraph.js +0 -11
- package/dist/lib/proxyHelpers.js +0 -69
- package/dist/lib/proxyHelpers.test.js +0 -136
- package/dist/lib/renderComponentWithCSS.js +0 -26
- package/dist/lib/renderHelpers.js +0 -45
- package/dist/lib/renderModule.js +0 -88
- package/dist/lib/renderPartial.js +0 -12
- package/dist/lib/templates.js +0 -48
- package/dist/lib/traverseFieldsJson.js +0 -78
- package/dist/proxyPage/constants.js +0 -4
- package/dist/proxyPage/fetchContentMetadata.js +0 -51
- package/dist/proxyPage/fetchPreviewInfo.js +0 -37
- package/dist/proxyPage/proxyPage.js +0 -167
- package/dist/proxyPage/renderLocalError.js +0 -27
- package/dist/proxyPage/utils.js +0 -38
- package/dist/render/renderOnServer.js +0 -40
- package/dist/render/renderOnServer.test.js +0 -24
- package/dist/render/renderStreamToPromise.js +0 -35
- package/dist/resolveSharedDeps.js +0 -28
- package/dist/routes/createDevServerRoutes.js +0 -21
- package/dist/routes/homeRouteHandler.js +0 -12
- package/dist/routes/linksToAllModulesRouteHandler.js +0 -10
- package/dist/routes/linksToAllPartialsRouteHandler.js +0 -10
- package/dist/routes/module.js +0 -27
- package/dist/routes/partial.js +0 -27
- package/dist/routes/proxyPageResourceRedirect.js +0 -12
- package/dist/routes/proxyPageRouteHandler.js +0 -40
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// src/storybook/moduleStory.tsx
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
|
|
4
|
+
// ../cms-js-internal/dist/types-ohevhxjF.js
|
|
5
|
+
function namespaceModulePropsShape(props) {
|
|
6
|
+
const {
|
|
7
|
+
dataQueryResult,
|
|
8
|
+
hublParameters,
|
|
9
|
+
fieldValues: passedFieldValues,
|
|
10
|
+
hublData,
|
|
11
|
+
experimentalHublData,
|
|
12
|
+
moduleName,
|
|
13
|
+
supplementalFieldValues
|
|
14
|
+
} = props;
|
|
15
|
+
const oldPropsShape = { ...props };
|
|
16
|
+
if (oldPropsShape.dataQueryResult) {
|
|
17
|
+
delete oldPropsShape.dataQueryResult;
|
|
18
|
+
}
|
|
19
|
+
if (oldPropsShape.hublParameters) {
|
|
20
|
+
delete oldPropsShape.hublParameters;
|
|
21
|
+
}
|
|
22
|
+
const fieldValues = passedFieldValues || oldPropsShape;
|
|
23
|
+
return {
|
|
24
|
+
...fieldValues,
|
|
25
|
+
dataQueryResult,
|
|
26
|
+
fieldValues,
|
|
27
|
+
hublParameters,
|
|
28
|
+
hublData,
|
|
29
|
+
experimentalHublData,
|
|
30
|
+
moduleName,
|
|
31
|
+
supplementalFieldValues
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ../cms-js-internal/dist/index.js
|
|
36
|
+
import * as dotProp from "dot-prop";
|
|
37
|
+
import _traverse from "@babel/traverse";
|
|
38
|
+
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
39
|
+
import * as cmsComponents from "@hubspot/cms-components";
|
|
40
|
+
import { isValidElement, cloneElement } from "react";
|
|
41
|
+
var { setProperty, getProperty, hasProperty } = dotProp;
|
|
42
|
+
var traverse = _traverse.default;
|
|
43
|
+
var {
|
|
44
|
+
createServerRenderContextV2: createServerRenderContextV22,
|
|
45
|
+
createServerRenderContext: createServerRenderContext2,
|
|
46
|
+
renderServerSidePropsWithAsyncLocalStoreContext
|
|
47
|
+
} = cmsComponents;
|
|
48
|
+
function renderFieldsJSX(fieldsJSX) {
|
|
49
|
+
let moduleJson;
|
|
50
|
+
const outputCallback = (callbackJson) => {
|
|
51
|
+
moduleJson = callbackJson;
|
|
52
|
+
};
|
|
53
|
+
renderToStaticMarkup(
|
|
54
|
+
cloneElement(fieldsJSX, {
|
|
55
|
+
outputCallback
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
if (!moduleJson) {
|
|
59
|
+
throw new Error("couldn't render module fields definition to fields.json");
|
|
60
|
+
}
|
|
61
|
+
return moduleJson;
|
|
62
|
+
}
|
|
63
|
+
function renderFieldsToJson(fields, moduleName) {
|
|
64
|
+
let fieldsJSON;
|
|
65
|
+
try {
|
|
66
|
+
if (isValidElement(fields)) {
|
|
67
|
+
fieldsJSON = renderFieldsJSX(fields);
|
|
68
|
+
} else if (Array.isArray(fields)) {
|
|
69
|
+
fieldsJSON = fields;
|
|
70
|
+
} else {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Couldn't recognize \`fields\` value for module ${moduleName}`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return fieldsJSON;
|
|
76
|
+
} catch (e2) {
|
|
77
|
+
e2.message = `Error when rendering fields for ${moduleName}: ${e2.message}`;
|
|
78
|
+
throw e2;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/storybook/getFieldsArgTypes.ts
|
|
83
|
+
function getFieldsArgTypes(fieldsJson, currentPathSegments = []) {
|
|
84
|
+
let resultArgTypes = {};
|
|
85
|
+
for (const field of fieldsJson) {
|
|
86
|
+
const fullFieldName = [...currentPathSegments, field.name].join(".");
|
|
87
|
+
switch (field.type) {
|
|
88
|
+
case "group": {
|
|
89
|
+
if (!field.children) {
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const groupResult = getFieldsArgTypes(field.children, [
|
|
93
|
+
...currentPathSegments,
|
|
94
|
+
field.name
|
|
95
|
+
]);
|
|
96
|
+
resultArgTypes = {
|
|
97
|
+
...resultArgTypes,
|
|
98
|
+
...groupResult
|
|
99
|
+
};
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case "boolean": {
|
|
103
|
+
resultArgTypes[fullFieldName] = {
|
|
104
|
+
control: "boolean",
|
|
105
|
+
defaultValue: field.default
|
|
106
|
+
};
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case "text": {
|
|
110
|
+
resultArgTypes[fullFieldName] = {
|
|
111
|
+
control: "text",
|
|
112
|
+
defaultValue: field.default
|
|
113
|
+
};
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case "number": {
|
|
117
|
+
resultArgTypes[fullFieldName] = {
|
|
118
|
+
control: "number",
|
|
119
|
+
defaultValue: field.default
|
|
120
|
+
};
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case "choice": {
|
|
124
|
+
const options = field.choices ? field.choices.map((choice) => choice[1]) : [];
|
|
125
|
+
resultArgTypes[fullFieldName] = {
|
|
126
|
+
control: "select",
|
|
127
|
+
defaultValue: field.default,
|
|
128
|
+
options
|
|
129
|
+
};
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
default: {
|
|
133
|
+
resultArgTypes[fullFieldName] = {
|
|
134
|
+
control: "object",
|
|
135
|
+
defaultValue: field.default
|
|
136
|
+
};
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return resultArgTypes;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/storybook/getNestedFieldObjectForArgs.ts
|
|
145
|
+
function getNestedFieldObjectForArgs(_args) {
|
|
146
|
+
const result = {};
|
|
147
|
+
for (const argPath in _args) {
|
|
148
|
+
if (Object.prototype.hasOwnProperty.call(_args, argPath)) {
|
|
149
|
+
const argPathSegments = argPath.split(".");
|
|
150
|
+
const nestedSegments = argPathSegments.slice(0, -1);
|
|
151
|
+
const fieldName = argPathSegments[argPathSegments.length - 1];
|
|
152
|
+
const fieldValue = _args[argPath];
|
|
153
|
+
let currentNest = result;
|
|
154
|
+
for (const segment of nestedSegments) {
|
|
155
|
+
if (!Object.prototype.hasOwnProperty.call(currentNest, segment)) {
|
|
156
|
+
currentNest[segment] = {};
|
|
157
|
+
}
|
|
158
|
+
currentNest = currentNest[segment];
|
|
159
|
+
}
|
|
160
|
+
currentNest[fieldName] = fieldValue;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/storybook/moduleStory.tsx
|
|
167
|
+
import { jsx } from "react/jsx-runtime";
|
|
168
|
+
function moduleArgs(argTypes) {
|
|
169
|
+
const args = {};
|
|
170
|
+
for (const argKey in argTypes) {
|
|
171
|
+
if (Object.hasOwnProperty.call(argTypes, argKey)) {
|
|
172
|
+
args[argKey] = argTypes[argKey].defaultValue;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return args;
|
|
176
|
+
}
|
|
177
|
+
function moduleStory(ModuleComponent, fields, storyArgs) {
|
|
178
|
+
const fieldsJSON = renderFieldsToJson(fields, ModuleComponent.name);
|
|
179
|
+
const argTypes = getFieldsArgTypes(fieldsJSON);
|
|
180
|
+
const args = { ...moduleArgs(argTypes), ...storyArgs };
|
|
181
|
+
return {
|
|
182
|
+
render: (_args) => {
|
|
183
|
+
const fieldValues = getNestedFieldObjectForArgs(_args);
|
|
184
|
+
const props = namespaceModulePropsShape(fieldValues);
|
|
185
|
+
return /* @__PURE__ */ jsx(ModuleComponent, { ...props });
|
|
186
|
+
},
|
|
187
|
+
argTypes,
|
|
188
|
+
args
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function moduleStoryWithIsland(moduleName, fields, storyArgs) {
|
|
192
|
+
if (typeof moduleName !== "string") {
|
|
193
|
+
throw new Error(
|
|
194
|
+
"moduleStoryWithIsland takes a `moduleName` that matches the file or folder name for the module as a string for the first argument, and the module's Fields JSX as the second parameter"
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (!fields) {
|
|
198
|
+
throw new Error(
|
|
199
|
+
"moduleStoryWithIsland requires a second parameter of the module's fields configuration"
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
const fieldsJSON = renderFieldsToJson(fields, moduleName);
|
|
203
|
+
const argTypes = getFieldsArgTypes(fieldsJSON);
|
|
204
|
+
const args = { ...moduleArgs(argTypes), ...storyArgs };
|
|
205
|
+
return {
|
|
206
|
+
argTypes,
|
|
207
|
+
args,
|
|
208
|
+
render: (_args) => {
|
|
209
|
+
const fieldValues = getNestedFieldObjectForArgs(_args);
|
|
210
|
+
const fieldValuesString = JSON.stringify(fieldValues);
|
|
211
|
+
const domain = `${window.location.protocol}//${window.location.hostname.replace("storybook.", "")}:3000`;
|
|
212
|
+
const fieldValuesJson = encodeURIComponent(fieldValuesString);
|
|
213
|
+
const iframeSrc = `${domain}/module/${moduleName}?fields=${fieldValuesJson}`;
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
const existingElement = document.querySelector("#hs-module-iframe");
|
|
216
|
+
if (existingElement) {
|
|
217
|
+
existingElement.setAttribute("src", iframeSrc);
|
|
218
|
+
return () => {
|
|
219
|
+
existingElement.remove();
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const iframeElement = document.createElement("iframe");
|
|
223
|
+
iframeElement.setAttribute("src", iframeSrc);
|
|
224
|
+
iframeElement.setAttribute("id", "hs-module-iframe");
|
|
225
|
+
iframeElement.setAttribute(
|
|
226
|
+
"style",
|
|
227
|
+
`border: none;width: 100%;height: 100%;overflow: auto;position: absolute;left: 0;top: 0;`
|
|
228
|
+
);
|
|
229
|
+
document.querySelector("#storybook-root").appendChild(iframeElement);
|
|
230
|
+
return () => {
|
|
231
|
+
iframeElement.remove();
|
|
232
|
+
};
|
|
233
|
+
}, [iframeSrc]);
|
|
234
|
+
return /* @__PURE__ */ jsx("div", {});
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
export {
|
|
239
|
+
moduleStory,
|
|
240
|
+
moduleStoryWithIsland
|
|
241
|
+
};
|