@hubspot/cms-dev-server 0.14.1 → 0.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/internalSsr.js +4 -2
- package/dist/run.js +153 -27
- package/dist/storybook/index.js +4 -2
- package/dist/storybook-main/main.js +4 -2
- package/package.json +5 -4
- package/dist/createViteDevServer-5624911d.js +0 -69
- package/dist/index-de34229d.js +0 -525
- package/dist/index-e4860c0f.js +0 -150
- package/dist/index2.js +0 -178
- package/dist/main.js +0 -52
- package/dist/preview.js +0 -18
- package/types/island-runtime.d.ts +0 -2
package/dist/index2.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { j as jsx } from "./index-e4860c0f.js";
|
|
2
|
-
import React, { useEffect } from "react";
|
|
3
|
-
import { renderToStaticMarkup } from "react-dom/server";
|
|
4
|
-
import { renderFieldsToJson } from "./index-de34229d.js";
|
|
5
|
-
import "react/jsx-runtime";
|
|
6
|
-
import "stream";
|
|
7
|
-
import "path";
|
|
8
|
-
import "fs";
|
|
9
|
-
import "crypto";
|
|
10
|
-
import "path/posix";
|
|
11
|
-
function getFieldsArgTypes(fieldsJson, currentPathSegments = []) {
|
|
12
|
-
let resultArgTypes = {};
|
|
13
|
-
for (const field of fieldsJson) {
|
|
14
|
-
const fullFieldName = [...currentPathSegments, field.name].join(".");
|
|
15
|
-
switch (field.type) {
|
|
16
|
-
case "group": {
|
|
17
|
-
if (!field.children) {
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
const groupResult = getFieldsArgTypes(field.children, [
|
|
21
|
-
...currentPathSegments,
|
|
22
|
-
field.name
|
|
23
|
-
]);
|
|
24
|
-
resultArgTypes = {
|
|
25
|
-
...resultArgTypes,
|
|
26
|
-
...groupResult
|
|
27
|
-
};
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
case "boolean": {
|
|
31
|
-
resultArgTypes[fullFieldName] = {
|
|
32
|
-
control: "boolean",
|
|
33
|
-
defaultValue: field.default
|
|
34
|
-
};
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
case "text": {
|
|
38
|
-
resultArgTypes[fullFieldName] = {
|
|
39
|
-
control: "text",
|
|
40
|
-
defaultValue: field.default
|
|
41
|
-
};
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
case "number": {
|
|
45
|
-
resultArgTypes[fullFieldName] = {
|
|
46
|
-
control: "number",
|
|
47
|
-
defaultValue: field.default
|
|
48
|
-
};
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
case "choice": {
|
|
52
|
-
resultArgTypes[fullFieldName] = {
|
|
53
|
-
control: "select",
|
|
54
|
-
defaultValue: field.default,
|
|
55
|
-
options: field.choices || []
|
|
56
|
-
};
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
default: {
|
|
60
|
-
resultArgTypes[fullFieldName] = {
|
|
61
|
-
control: "object",
|
|
62
|
-
defaultValue: field.default
|
|
63
|
-
};
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return resultArgTypes;
|
|
69
|
-
}
|
|
70
|
-
function getNestedFieldObjectForArgs(_args) {
|
|
71
|
-
const result = {};
|
|
72
|
-
for (const argPath in _args) {
|
|
73
|
-
if (Object.prototype.hasOwnProperty.call(_args, argPath)) {
|
|
74
|
-
const argPathSegments = argPath.split(".");
|
|
75
|
-
const nestedSegments = argPathSegments.slice(0, -1);
|
|
76
|
-
const fieldName = argPathSegments[argPathSegments.length - 1];
|
|
77
|
-
const fieldValue = _args[argPath];
|
|
78
|
-
let currentNest = result;
|
|
79
|
-
for (const segment of nestedSegments) {
|
|
80
|
-
if (!Object.prototype.hasOwnProperty.call(currentNest, segment)) {
|
|
81
|
-
currentNest[segment] = {};
|
|
82
|
-
}
|
|
83
|
-
currentNest = currentNest[segment];
|
|
84
|
-
}
|
|
85
|
-
currentNest[fieldName] = fieldValue;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
function moduleFieldsToJson(fields) {
|
|
91
|
-
let moduleJson;
|
|
92
|
-
const outputCallback = (callbackJson) => {
|
|
93
|
-
moduleJson = callbackJson;
|
|
94
|
-
};
|
|
95
|
-
renderToStaticMarkup(
|
|
96
|
-
React.cloneElement(fields, {
|
|
97
|
-
outputCallback
|
|
98
|
-
})
|
|
99
|
-
);
|
|
100
|
-
if (!moduleJson) {
|
|
101
|
-
throw new Error("couldn't render module fields definition to fields.json");
|
|
102
|
-
}
|
|
103
|
-
return moduleJson;
|
|
104
|
-
}
|
|
105
|
-
function moduleArgs(argTypes) {
|
|
106
|
-
const args = {};
|
|
107
|
-
for (const argKey in argTypes) {
|
|
108
|
-
if (Object.hasOwnProperty.call(argTypes, argKey)) {
|
|
109
|
-
args[argKey] = argTypes[argKey].defaultValue;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return args;
|
|
113
|
-
}
|
|
114
|
-
function moduleStory(ModuleComponent, fields, storyArgs) {
|
|
115
|
-
const moduleJson = renderFieldsToJson(fields);
|
|
116
|
-
const argTypes = getFieldsArgTypes(moduleJson);
|
|
117
|
-
const args = { ...moduleArgs(argTypes), ...storyArgs };
|
|
118
|
-
return {
|
|
119
|
-
render: (_args) => {
|
|
120
|
-
const fieldValues = getNestedFieldObjectForArgs(_args);
|
|
121
|
-
return /* @__PURE__ */ jsx(ModuleComponent, { ...fieldValues });
|
|
122
|
-
},
|
|
123
|
-
argTypes,
|
|
124
|
-
args
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
function moduleStoryWithIsland(fields, moduleName, storyArgs) {
|
|
128
|
-
if (typeof moduleName !== "string") {
|
|
129
|
-
throw new Error(
|
|
130
|
-
"moduleStoryWithIsland takes Fields JSX as the first argument, and the moduleName that matches the file or folder name for the module as a string for the second parameter"
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
if (!moduleName) {
|
|
134
|
-
throw new Error(
|
|
135
|
-
"moduleStoryWithIsland requires a second moduleName parameter that matches the file or folder name for the module"
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
const moduleJson = moduleFieldsToJson(fields);
|
|
139
|
-
const argTypes = getFieldsArgTypes(moduleJson);
|
|
140
|
-
const args = { ...moduleArgs(argTypes), ...storyArgs };
|
|
141
|
-
return {
|
|
142
|
-
argTypes,
|
|
143
|
-
args,
|
|
144
|
-
render: (_args) => {
|
|
145
|
-
const fieldValues = getNestedFieldObjectForArgs(_args);
|
|
146
|
-
const fieldValuesString = JSON.stringify(fieldValues);
|
|
147
|
-
const domain = `${window.location.protocol}//${window.location.hostname.replace("storybook.", "")}:3000`;
|
|
148
|
-
const fieldValuesJson = encodeURIComponent(fieldValuesString);
|
|
149
|
-
const iframeSrc = `${domain}/module/${moduleName}?fields=${fieldValuesJson}`;
|
|
150
|
-
useEffect(() => {
|
|
151
|
-
const existingElement = document.querySelector("#hs-module-iframe");
|
|
152
|
-
if (existingElement) {
|
|
153
|
-
existingElement.setAttribute("src", iframeSrc);
|
|
154
|
-
return () => {
|
|
155
|
-
existingElement.remove();
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
const iframeElement = document.createElement("iframe");
|
|
159
|
-
iframeElement.setAttribute("src", iframeSrc);
|
|
160
|
-
iframeElement.setAttribute("id", "hs-module-iframe");
|
|
161
|
-
iframeElement.setAttribute(
|
|
162
|
-
"style",
|
|
163
|
-
`border: none;width: 100%;height: 100%;overflow: auto;`
|
|
164
|
-
);
|
|
165
|
-
document.querySelector("#storybook-root").appendChild(iframeElement);
|
|
166
|
-
return () => {
|
|
167
|
-
iframeElement.remove();
|
|
168
|
-
};
|
|
169
|
-
}, [iframeSrc]);
|
|
170
|
-
return /* @__PURE__ */ jsx("div", {});
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
export {
|
|
175
|
-
moduleFieldsToJson,
|
|
176
|
-
moduleStory,
|
|
177
|
-
moduleStoryWithIsland
|
|
178
|
-
};
|
package/dist/main.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { mergeConfig } from "vite";
|
|
3
|
-
const webRoot = process.env.WEB_ROOT;
|
|
4
|
-
const storyPath = path.resolve(process.cwd(), webRoot, "**/*.stories.*");
|
|
5
|
-
const jsRenderingGates = process.env.GATES ? process.env.GATES.split(",") : [];
|
|
6
|
-
const main = {
|
|
7
|
-
addons: ["@storybook/addon-essentials"],
|
|
8
|
-
framework: "@storybook/react-vite",
|
|
9
|
-
stories: [storyPath],
|
|
10
|
-
previewHead: (head) => {
|
|
11
|
-
return `
|
|
12
|
-
${head}
|
|
13
|
-
|
|
14
|
-
<script type="module">
|
|
15
|
-
import { initConfigSingletonFromJSON } from '@hubspot/cms-components/config';
|
|
16
|
-
|
|
17
|
-
initConfigSingletonFromJSON(${JSON.stringify({
|
|
18
|
-
portalId: process.env.portalId,
|
|
19
|
-
hublet: process.env.hublet,
|
|
20
|
-
hsEnv: process.env.hsEnv,
|
|
21
|
-
hsDeployed: false,
|
|
22
|
-
hsJSRGates: jsRenderingGates
|
|
23
|
-
})})
|
|
24
|
-
<\/script>
|
|
25
|
-
|
|
26
|
-
`;
|
|
27
|
-
},
|
|
28
|
-
viteFinal: async (config) => {
|
|
29
|
-
const { resolveIslandPlugin } = await import("./index-de34229d.js");
|
|
30
|
-
const viteConfig = {
|
|
31
|
-
resolve: {
|
|
32
|
-
dedupe: [
|
|
33
|
-
"react",
|
|
34
|
-
"react-dom",
|
|
35
|
-
"@hubspot/cms-components",
|
|
36
|
-
"@hubspot/cms-dev-server"
|
|
37
|
-
]
|
|
38
|
-
},
|
|
39
|
-
optimizeDeps: {
|
|
40
|
-
include: ["react", "react-dom", "react-dom/client"]
|
|
41
|
-
},
|
|
42
|
-
css: {
|
|
43
|
-
postcss: webRoot
|
|
44
|
-
},
|
|
45
|
-
plugins: [resolveIslandPlugin(jsRenderingGates)]
|
|
46
|
-
};
|
|
47
|
-
return mergeConfig(config, viteConfig);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
export {
|
|
51
|
-
main as default
|
|
52
|
-
};
|
package/dist/preview.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { d as createServerRenderContextV2, j as jsx, C as ClientRenderContextProvider, S as ServerRenderContext } from "./index-e4860c0f.js";
|
|
2
|
-
import "react";
|
|
3
|
-
import "react/jsx-runtime";
|
|
4
|
-
import "stream";
|
|
5
|
-
import "react-dom/server";
|
|
6
|
-
const parameters = {
|
|
7
|
-
actions: { argTypesRegex: "^on[A-Z].*" }
|
|
8
|
-
};
|
|
9
|
-
const contextValue = createServerRenderContextV2("http://testUrl.com", {
|
|
10
|
-
environmentConfig: null
|
|
11
|
-
});
|
|
12
|
-
const decorators = [
|
|
13
|
-
(Story) => /* @__PURE__ */ jsx(ClientRenderContextProvider, { pageUrl: "http://test.com", islands: [], children: /* @__PURE__ */ jsx(ServerRenderContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(Story, {}) }) })
|
|
14
|
-
];
|
|
15
|
-
export {
|
|
16
|
-
decorators,
|
|
17
|
-
parameters
|
|
18
|
-
};
|