@hubspot/cms-dev-server 0.4.17 → 0.5.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/components/ModulesList.js +14 -0
- package/dist/components/PartialsList.js +13 -0
- package/dist/createDevServer.js +162 -0
- package/dist/createViteDevServer.js +51 -0
- package/dist/fsevents-72LCIACT.node +0 -0
- package/dist/index.js +2 -2
- package/dist/internalSsr.js +20 -6
- package/dist/lib/cli.js +27 -0
- package/dist/lib/debug.js +2 -0
- package/dist/lib/errors.js +22 -0
- package/dist/lib/fullOriginalUrlFromRequest.js +3 -0
- package/dist/lib/httpsRedirectingServer.js +48 -0
- package/dist/lib/moduleGraph.js +11 -0
- package/dist/lib/proxyHelpers.js +70 -0
- package/dist/lib/proxyHelpers.test.js +136 -0
- package/dist/lib/renderComponentWithCSS.js +26 -0
- package/dist/lib/renderHelpers.js +45 -0
- package/dist/lib/renderModule.js +56 -0
- package/dist/lib/renderPartial.js +15 -0
- package/dist/lib/templates.js +55 -0
- package/dist/proxyPage/constants.js +1 -0
- package/dist/proxyPage/fetchContentMetadata.js +59 -0
- package/dist/proxyPage/fetchDomains.js +29 -0
- package/dist/proxyPage/fetchPreviewInfo.js +37 -0
- package/dist/proxyPage/proxyPage.js +174 -0
- package/dist/proxyPage/renderLocalError.js +27 -0
- package/dist/proxyPage/utils.js +38 -0
- package/dist/routes/createDevServerRoutes.js +43 -0
- package/dist/routes/homeRouteHandler.js +12 -0
- package/dist/routes/linksToAllModulesRouteHandler.js +10 -0
- package/dist/routes/linksToAllPartialsRouteHandler.js +10 -0
- package/dist/routes/module.js +41 -0
- package/dist/routes/partial.js +30 -0
- package/dist/routes/proxyPageResourceRedirect.js +22 -0
- package/dist/routes/proxyPageRouteHandler.js +40 -0
- package/dist/routes/proxyPathPageResourceRedirect.js +36 -0
- package/dist/routes/proxyPathPageRouteHandler.js +43 -0
- package/dist/run.js +157 -50
- package/dist/shadowDevServer/createShadowDevServerRoutes.js +63 -0
- package/dist/shadowDevServer/startShadowDevServer.js +31 -0
- package/dist/storybook/getFieldsArgTypes.js +54 -0
- package/dist/storybook/getFieldsArgTypes.test.js +91 -0
- package/dist/storybook/getNestedFieldObjectForArgs.js +22 -0
- package/dist/storybook/getNestedFieldObjectForArgs.test.js +40 -0
- package/dist/storybook/index.js +1 -1
- package/dist/storybook/main.js +21 -7
- package/dist/storybook/moduleStory.js +61 -0
- package/dist/storybook/preview.js +9 -0
- package/dist/storybook/types.js +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { ModuleFields, BooleanField, TextField, FieldGroup, NumberField, ColorField, } from '@hubspot/cms-components/fields';
|
|
4
|
+
import { renderFieldsToJson } from '@hubspot/cms-js-internal';
|
|
5
|
+
import getFieldsArgTypes from './getFieldsArgTypes.js';
|
|
6
|
+
describe('getFieldsArgTypes', () => {
|
|
7
|
+
it('creates argType for boolean field', () => {
|
|
8
|
+
const fields = (_jsx(ModuleFields, { children: _jsx(BooleanField, { name: "testBooleanField", label: "field", default: false }) }));
|
|
9
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
10
|
+
expect(argTypes).toStrictEqual({
|
|
11
|
+
testBooleanField: {
|
|
12
|
+
control: 'boolean',
|
|
13
|
+
defaultValue: false,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
it('creates text argType for text field', () => {
|
|
18
|
+
const fields = (_jsx(ModuleFields, { children: _jsx(TextField, { name: "testStringField", label: "field", default: 'test' }) }));
|
|
19
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
20
|
+
expect(argTypes).toStrictEqual({
|
|
21
|
+
testStringField: {
|
|
22
|
+
control: 'text',
|
|
23
|
+
defaultValue: 'test',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
it('creates number argType for number field', () => {
|
|
28
|
+
const fields = (_jsx(ModuleFields, { children: _jsx(NumberField, { name: "testNumberField", label: "field", default: 123 }) }));
|
|
29
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
30
|
+
expect(argTypes).toStrictEqual({
|
|
31
|
+
testNumberField: {
|
|
32
|
+
control: 'number',
|
|
33
|
+
defaultValue: 123,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
it('creates object argType for unknown field', () => {
|
|
38
|
+
const fields = (_jsx(ModuleFields, { children: _jsx(ColorField, { name: "testColorField", label: "field", default: {
|
|
39
|
+
color: '#fff',
|
|
40
|
+
} }) }));
|
|
41
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
42
|
+
expect(argTypes).toStrictEqual({
|
|
43
|
+
testColorField: {
|
|
44
|
+
control: 'object',
|
|
45
|
+
defaultValue: {
|
|
46
|
+
color: '#fff',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
it('prefixes fields in a group with . separated group names', () => {
|
|
52
|
+
const fields = (_jsx(ModuleFields, { children: _jsxs(FieldGroup, { name: "mygroup", label: "field group", children: [_jsx(TextField, { name: "testStringField", label: "field", default: 'test' }), _jsx(BooleanField, { name: "testBooleanField", label: "field", default: false })] }) }));
|
|
53
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
54
|
+
expect(argTypes).toStrictEqual({
|
|
55
|
+
'mygroup.testStringField': {
|
|
56
|
+
control: 'text',
|
|
57
|
+
defaultValue: 'test',
|
|
58
|
+
},
|
|
59
|
+
'mygroup.testBooleanField': {
|
|
60
|
+
control: 'boolean',
|
|
61
|
+
defaultValue: false,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it('handles multiple nesting alongside top level values', () => {
|
|
66
|
+
const fields = (_jsxs(ModuleFields, { children: [_jsx(TextField, { name: "toplevel", label: "top level text field", default: "defaultvalue" }), _jsxs(FieldGroup, { name: "mygroup", label: "field group", children: [_jsx(TextField, { name: "testStringField", label: "field", default: 'test' }), _jsx(BooleanField, { name: "testBooleanField", label: "field", default: false }), _jsxs(FieldGroup, { name: "nestedgroup", label: "nested group", children: [_jsx(TextField, { name: "testStringField", label: "field", default: 'test' }), _jsx(BooleanField, { name: "testBooleanField", label: "field", default: false })] })] })] }));
|
|
67
|
+
const argTypes = getFieldsArgTypes(renderFieldsToJson(fields));
|
|
68
|
+
expect(argTypes).toStrictEqual({
|
|
69
|
+
toplevel: {
|
|
70
|
+
control: 'text',
|
|
71
|
+
defaultValue: 'defaultvalue',
|
|
72
|
+
},
|
|
73
|
+
'mygroup.testStringField': {
|
|
74
|
+
control: 'text',
|
|
75
|
+
defaultValue: 'test',
|
|
76
|
+
},
|
|
77
|
+
'mygroup.testBooleanField': {
|
|
78
|
+
control: 'boolean',
|
|
79
|
+
defaultValue: false,
|
|
80
|
+
},
|
|
81
|
+
'mygroup.nestedgroup.testStringField': {
|
|
82
|
+
control: 'text',
|
|
83
|
+
defaultValue: 'test',
|
|
84
|
+
},
|
|
85
|
+
'mygroup.nestedgroup.testBooleanField': {
|
|
86
|
+
control: 'boolean',
|
|
87
|
+
defaultValue: false,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// default values come through via `defaultValue` in the story's argTypes, we
|
|
2
|
+
// need to re-nest them to match the field structure
|
|
3
|
+
export default function getNestedFieldObjectForArgs(_args) {
|
|
4
|
+
const result = {};
|
|
5
|
+
for (const argPath in _args) {
|
|
6
|
+
if (Object.prototype.hasOwnProperty.call(_args, argPath)) {
|
|
7
|
+
const argPathSegments = argPath.split('.');
|
|
8
|
+
const nestedSegments = argPathSegments.slice(0, -1);
|
|
9
|
+
const fieldName = argPathSegments[argPathSegments.length - 1];
|
|
10
|
+
const fieldValue = _args[argPath];
|
|
11
|
+
let currentNest = result;
|
|
12
|
+
for (const segment of nestedSegments) {
|
|
13
|
+
if (!Object.prototype.hasOwnProperty.call(currentNest, segment)) {
|
|
14
|
+
currentNest[segment] = {};
|
|
15
|
+
}
|
|
16
|
+
currentNest = currentNest[segment];
|
|
17
|
+
}
|
|
18
|
+
currentNest[fieldName] = fieldValue;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import getNestedFieldObjectForArgs from './getNestedFieldObjectForArgs.js';
|
|
3
|
+
describe('getNestedFieldObjectForArgs', () => {
|
|
4
|
+
it('leaves top level args as is', () => {
|
|
5
|
+
const argMap = {
|
|
6
|
+
testField: 'testValue',
|
|
7
|
+
testField2: 'testValue',
|
|
8
|
+
};
|
|
9
|
+
const result = getNestedFieldObjectForArgs(argMap);
|
|
10
|
+
expect(result).toStrictEqual(argMap);
|
|
11
|
+
});
|
|
12
|
+
it('turns a . separated arg name into a nested field', () => {
|
|
13
|
+
const argMap = {
|
|
14
|
+
'group.testField': 'testValue',
|
|
15
|
+
topLevelField: 'testValue',
|
|
16
|
+
};
|
|
17
|
+
const result = getNestedFieldObjectForArgs(argMap);
|
|
18
|
+
expect(result).toStrictEqual({
|
|
19
|
+
group: {
|
|
20
|
+
testField: 'testValue',
|
|
21
|
+
},
|
|
22
|
+
topLevelField: 'testValue',
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
it('keeps nested fields with the same group prefix nested in the same object', () => {
|
|
26
|
+
const argMap = {
|
|
27
|
+
'group.testField': 'testValue',
|
|
28
|
+
'group.secondField': 'testValue',
|
|
29
|
+
topLevelField: 'testValue',
|
|
30
|
+
};
|
|
31
|
+
const result = getNestedFieldObjectForArgs(argMap);
|
|
32
|
+
expect(result).toStrictEqual({
|
|
33
|
+
group: {
|
|
34
|
+
testField: 'testValue',
|
|
35
|
+
secondField: 'testValue',
|
|
36
|
+
},
|
|
37
|
+
topLevelField: 'testValue',
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
package/dist/storybook/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { createRequire } from "module";
|
|
|
8
8
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
9
9
|
import stream from "stream";
|
|
10
10
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
11
|
-
import {
|
|
11
|
+
import { createServerRenderContextV2, ServerRenderContext } from "@hubspot/cms-components";
|
|
12
12
|
import { createHash } from "crypto";
|
|
13
13
|
import { existsSync, readdirSync, lstatSync } from "fs";
|
|
14
14
|
import { join } from "path/posix";
|
package/dist/storybook/main.js
CHANGED
|
@@ -13,6 +13,7 @@ var dist_exports = {};
|
|
|
13
13
|
__export(dist_exports, {
|
|
14
14
|
COMPONENT_EXTENSIONS: () => COMPONENT_EXTENSIONS,
|
|
15
15
|
CSS_LANGS_RE: () => CSS_LANGS_RE,
|
|
16
|
+
ENABLED_FEATURES_GATE_MAP: () => ENABLED_FEATURES_GATE_MAP,
|
|
16
17
|
ENTRY_POINTS_PATH: () => ENTRY_POINTS_PATH,
|
|
17
18
|
GATES: () => GATES,
|
|
18
19
|
MODULE_FOLDER_PATH: () => MODULE_FOLDER_PATH,
|
|
@@ -51,7 +52,7 @@ import { createRequire } from "module";
|
|
|
51
52
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
52
53
|
import stream from "stream";
|
|
53
54
|
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
54
|
-
import {
|
|
55
|
+
import { createServerRenderContextV2, ServerRenderContext } from "@hubspot/cms-components";
|
|
55
56
|
import { createHash } from "crypto";
|
|
56
57
|
import { existsSync, readdirSync, lstatSync } from "fs";
|
|
57
58
|
import { join } from "path/posix";
|
|
@@ -177,18 +178,22 @@ function clientIslandEntryPlugin() {
|
|
|
177
178
|
}
|
|
178
179
|
};
|
|
179
180
|
}
|
|
180
|
-
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, renderOptions) {
|
|
181
|
+
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, renderOptions) {
|
|
181
182
|
const componentDebugName = Component.displayName || Component.name;
|
|
182
183
|
return renderOnServer(
|
|
183
184
|
/* @__PURE__ */ jsx2(Component, { ...props }),
|
|
184
185
|
pageUrl,
|
|
185
186
|
environmentConfig,
|
|
187
|
+
entryPointBasePath,
|
|
186
188
|
componentDebugName,
|
|
187
189
|
renderOptions
|
|
188
190
|
);
|
|
189
191
|
}
|
|
190
|
-
async function renderOnServer(elements, pageUrl, environmentConfig, debugName, renderOptions) {
|
|
191
|
-
const renderContext =
|
|
192
|
+
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
|
|
193
|
+
const renderContext = createServerRenderContextV2(pageUrl, {
|
|
194
|
+
environmentConfig,
|
|
195
|
+
entryPointBasePath
|
|
196
|
+
});
|
|
192
197
|
let html = await renderStreamToPromise(
|
|
193
198
|
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
194
199
|
renderOptions
|
|
@@ -242,13 +247,16 @@ function findAllPartialsInRoot(webRoot2) {
|
|
|
242
247
|
);
|
|
243
248
|
return { partialNames, partialSubpaths };
|
|
244
249
|
}
|
|
245
|
-
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl) {
|
|
250
|
+
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath) {
|
|
246
251
|
const globals = [
|
|
247
252
|
`window.__hsEnvConfig = ${JSON.stringify(environmentConfig.toJSON())};`
|
|
248
253
|
];
|
|
249
254
|
if (hsServerPageUrl) {
|
|
250
255
|
globals.push(`window.__hsServerPageUrl = '${hsServerPageUrl}';`);
|
|
251
256
|
}
|
|
257
|
+
if (hsBasePath) {
|
|
258
|
+
globals.push(`window.__hsBasePath = '${hsBasePath}';`);
|
|
259
|
+
}
|
|
252
260
|
return `
|
|
253
261
|
<script type="text/javascript">
|
|
254
262
|
${globals.join("\n ")}
|
|
@@ -287,7 +295,7 @@ function renderFieldsToJson(fields) {
|
|
|
287
295
|
);
|
|
288
296
|
return moduleJson;
|
|
289
297
|
}
|
|
290
|
-
var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, serializeIslandDataToJSON, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, require2, GATES, BUILD_INFO_PATH, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, jsx2, promiseForNewWritableStream, renderStreamToPromise, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, findAllComponentsIn;
|
|
298
|
+
var COMPONENT_EXTENSIONS, ENTRY_POINTS_PATH, MODULE_FOLDER_PATH, VIRTUAL_ISLAND_RUNTIME, VIRTUAL_CONFIG_SETUP, CSS_LANGS_RE, collectCssModules, collectCssInDev, serializeIslandDataToJSON, writeSharedStateToJsGlobal, createIslandsGlobalJsForClientInDev, require2, GATES, ENABLED_FEATURES_GATE_MAP, BUILD_INFO_PATH, viteRoot, viteCommand, clientRenderIsland, virtualClientRenderIslandModuleId, jsx2, promiseForNewWritableStream, renderStreamToPromise, scriptTagToLogServerMessages, getComponentExtension, hasComponentExtension, isStorybookStory, removeComponentExtension, COMBINED_REACT_BASE_PATH, ISLAND_RUNTIME_CONFIG_BASE_PATH, findAllComponentsIn;
|
|
291
299
|
var init_dist = __esm({
|
|
292
300
|
"../cms-js-internal/dist/index.js"() {
|
|
293
301
|
COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
@@ -403,8 +411,14 @@ ${indentString}`);
|
|
|
403
411
|
"CMS:JSRenderer:LocalProxySchemaVersion1",
|
|
404
412
|
"CMS:JSRenderer:GraphQLQueryBuild"
|
|
405
413
|
];
|
|
414
|
+
ENABLED_FEATURES_GATE_MAP = {
|
|
415
|
+
"cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
|
|
416
|
+
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
417
|
+
"cms:jsr:localProxySchemaVersion1": "CMS:JSRenderer:LocalProxySchemaVersion1",
|
|
418
|
+
"cms:jsr:graphqQLQueryBuild": "CMS:JSRenderer:GraphQLQueryBuild"
|
|
419
|
+
};
|
|
406
420
|
BUILD_INFO_PATH = "/build-info.json";
|
|
407
|
-
clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: `island-${renderableIsland.index}-`,\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 >\n <Component islandId={island.id} {...island.props} />\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";
|
|
421
|
+
clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport { ClientRenderContextProvider } from '@hubspot/cms-components';\nimport { Suspense } from 'react';\nimport ReactDOMClient from 'react-dom/client';\n\nexport function clientRenderIsland(\n renderableIsland: RenderableIsland,\n Component: any\n) {\n const { island, rootElement, postHydration, pageUrl, islands, basePath } =\n renderableIsland;\n let reactRoot: any;\n\n const rootOptions = {\n // Ensure useId is unique across island roots\n identifierPrefix: `island-${renderableIsland.index}-`,\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 <Component islandId={island.id} {...island.props} />\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";
|
|
408
422
|
virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
409
423
|
jsx2 = jsxRuntime.jsx;
|
|
410
424
|
promiseForNewWritableStream = () => {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
|
+
import { renderToStaticMarkup } from 'react-dom/server';
|
|
4
|
+
import { renderFieldsToJson } from '@hubspot/cms-js-internal';
|
|
5
|
+
import getFieldsArgTypes from './getFieldsArgTypes.js';
|
|
6
|
+
import getNestedFieldObjectForArgs from './getNestedFieldObjectForArgs.js';
|
|
7
|
+
export function moduleFieldsToJson(fields) {
|
|
8
|
+
let moduleJson;
|
|
9
|
+
const outputCallback = (callbackJson) => {
|
|
10
|
+
moduleJson = callbackJson;
|
|
11
|
+
};
|
|
12
|
+
renderToStaticMarkup(React.cloneElement(fields, {
|
|
13
|
+
outputCallback,
|
|
14
|
+
}));
|
|
15
|
+
if (!moduleJson) {
|
|
16
|
+
throw new Error("couldn't render module fields definition to fields.json");
|
|
17
|
+
}
|
|
18
|
+
return moduleJson;
|
|
19
|
+
}
|
|
20
|
+
export function moduleStory(ModuleComponent, fields) {
|
|
21
|
+
const moduleJson = renderFieldsToJson(fields);
|
|
22
|
+
const argTypes = getFieldsArgTypes(moduleJson);
|
|
23
|
+
const story = (_args) => _jsx(ModuleComponent, { ..._args });
|
|
24
|
+
const storyWithArgs = story.bind({});
|
|
25
|
+
storyWithArgs.argTypes = argTypes;
|
|
26
|
+
storyWithArgs.args = {};
|
|
27
|
+
return storyWithArgs;
|
|
28
|
+
}
|
|
29
|
+
export function moduleStoryWithIsland(moduleName, fields) {
|
|
30
|
+
const moduleJson = moduleFieldsToJson(fields);
|
|
31
|
+
const argTypes = getFieldsArgTypes(moduleJson);
|
|
32
|
+
const story = (_args) => {
|
|
33
|
+
const fieldValues = getNestedFieldObjectForArgs(_args);
|
|
34
|
+
const fieldValuesString = JSON.stringify(fieldValues);
|
|
35
|
+
const domain = `${window.location.protocol}//${window.location.hostname.replace('storybook.', '')}:3000`;
|
|
36
|
+
const fieldValuesJson = encodeURIComponent(fieldValuesString);
|
|
37
|
+
const iframeSrc = `${domain}/module/${moduleName}?fields=${fieldValuesJson}`;
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const existingElement = document.querySelector('#hs-module-iframe');
|
|
40
|
+
if (existingElement) {
|
|
41
|
+
existingElement.setAttribute('src', iframeSrc);
|
|
42
|
+
return () => {
|
|
43
|
+
existingElement.remove();
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const iframeElement = document.createElement('iframe');
|
|
47
|
+
iframeElement.setAttribute('src', iframeSrc);
|
|
48
|
+
iframeElement.setAttribute('id', 'hs-module-iframe');
|
|
49
|
+
iframeElement.setAttribute('style', `border: none;width: 100%;height: 100%;overflow: auto;`);
|
|
50
|
+
document.body.appendChild(iframeElement);
|
|
51
|
+
return () => {
|
|
52
|
+
iframeElement.remove();
|
|
53
|
+
};
|
|
54
|
+
}, [iframeSrc]);
|
|
55
|
+
return _jsx("div", {});
|
|
56
|
+
};
|
|
57
|
+
const storyWithArgs = story.bind({});
|
|
58
|
+
storyWithArgs.argTypes = argTypes;
|
|
59
|
+
storyWithArgs.args = {};
|
|
60
|
+
return storyWithArgs;
|
|
61
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ServerRenderContext, createServerRenderContext, ClientRenderContextProvider, } from '@hubspot/cms-components';
|
|
3
|
+
export const parameters = {
|
|
4
|
+
actions: { argTypesRegex: '^on[A-Z].*' },
|
|
5
|
+
};
|
|
6
|
+
const contextValue = createServerRenderContext('http://testUrl.com');
|
|
7
|
+
export const decorators = [
|
|
8
|
+
Story => (_jsx(ClientRenderContextProvider, { pageUrl: "http://test.com", islands: [], children: _jsx(ServerRenderContext.Provider, { value: contextValue, children: _jsx(Story, {}) }) })),
|
|
9
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@hubspot/cli-lib": "^3.0.12",
|
|
27
|
-
"@hubspot/cms-components": "^0.
|
|
27
|
+
"@hubspot/cms-components": "^0.5.0",
|
|
28
28
|
"@storybook/addon-actions": "^7.0.0-beta.19",
|
|
29
29
|
"@storybook/addon-essentials": "^7.0.0-beta.19",
|
|
30
30
|
"@storybook/addon-interactions": "^7.0.0-beta.19",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"publishConfig": {
|
|
96
96
|
"access": "public"
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "0672519928c58b623ecd26818346ae1eafa6941a"
|
|
99
99
|
}
|