@hubspot/cms-dev-server 0.14.1 → 0.14.2
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 -36
- package/dist/run.js +4 -35
- package/dist/storybook-main/main.js +4 -36
- package/package.json +3 -3
- 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/internalSsr.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// ../cms-js-internal/dist/index.js
|
|
2
|
-
import { hasProperty, setProperty, getProperty } from "dot-prop";
|
|
3
2
|
import path from "path";
|
|
4
3
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
5
4
|
import stream from "stream";
|
|
@@ -97,7 +96,7 @@ function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent =
|
|
|
97
96
|
${indentString}`
|
|
98
97
|
);
|
|
99
98
|
}
|
|
100
|
-
var serializeIslandDataForInlineScript = (tweakedIslandsArray,
|
|
99
|
+
var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, prettyPrint) => {
|
|
101
100
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
102
101
|
({
|
|
103
102
|
id,
|
|
@@ -109,7 +108,6 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestD
|
|
|
109
108
|
priority,
|
|
110
109
|
url,
|
|
111
110
|
sharedStateID,
|
|
112
|
-
supplementalFieldValues,
|
|
113
111
|
wrapperModuleId,
|
|
114
112
|
wrapperUrl
|
|
115
113
|
}) => {
|
|
@@ -132,13 +130,6 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestD
|
|
|
132
130
|
if (wrapperUrl) {
|
|
133
131
|
output.wrapperUrl = wrapperUrl;
|
|
134
132
|
}
|
|
135
|
-
const filteredSupplementalFieldValues = filterOutUnreadSupplementalFieldValues(
|
|
136
|
-
supplementalFieldValues,
|
|
137
|
-
perServerRequestData.get("supplementalFieldValuesRead")
|
|
138
|
-
);
|
|
139
|
-
if (filteredSupplementalFieldValues) {
|
|
140
|
-
output.supplementalFieldValues = filteredSupplementalFieldValues;
|
|
141
|
-
}
|
|
142
133
|
return output;
|
|
143
134
|
}
|
|
144
135
|
);
|
|
@@ -148,25 +139,6 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestD
|
|
|
148
139
|
prettyPrint
|
|
149
140
|
});
|
|
150
141
|
};
|
|
151
|
-
function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
|
|
152
|
-
if (!supplementalFieldValues) {
|
|
153
|
-
return supplementalFieldValues;
|
|
154
|
-
}
|
|
155
|
-
if (!supplementalFieldValuesRead) {
|
|
156
|
-
return supplementalFieldValues;
|
|
157
|
-
}
|
|
158
|
-
const result = {};
|
|
159
|
-
Array.from(supplementalFieldValuesRead).forEach((fieldPath) => {
|
|
160
|
-
if (hasProperty(supplementalFieldValues, fieldPath)) {
|
|
161
|
-
setProperty(
|
|
162
|
-
result,
|
|
163
|
-
fieldPath,
|
|
164
|
-
getProperty(supplementalFieldValues, fieldPath)
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
return result;
|
|
169
|
-
}
|
|
170
142
|
var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0, prettyPrint) => {
|
|
171
143
|
const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
|
|
172
144
|
if (sharedStateIDs.length > 0) {
|
|
@@ -244,7 +216,6 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
|
|
|
244
216
|
indent
|
|
245
217
|
)}window.__islands = ${serializeIslandDataForInlineScript(
|
|
246
218
|
islands,
|
|
247
|
-
perServerRequestData,
|
|
248
219
|
indent,
|
|
249
220
|
prettyPrint
|
|
250
221
|
)}${writeSharedStateToJsGlobal(
|
|
@@ -391,24 +362,21 @@ ${consoleLines.join("\n")}
|
|
|
391
362
|
${groupEnd}</script>
|
|
392
363
|
`;
|
|
393
364
|
};
|
|
394
|
-
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath,
|
|
365
|
+
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, renderOptions) {
|
|
395
366
|
const componentDebugName = Component.displayName || Component.name;
|
|
396
367
|
return renderOnServer(
|
|
397
368
|
/* @__PURE__ */ jsx2(Component, { ...props }),
|
|
398
369
|
pageUrl,
|
|
399
370
|
environmentConfig,
|
|
400
371
|
entryPointBasePath,
|
|
401
|
-
contextOptions,
|
|
402
372
|
componentDebugName,
|
|
403
373
|
renderOptions
|
|
404
374
|
);
|
|
405
375
|
}
|
|
406
|
-
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath,
|
|
407
|
-
const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
|
|
376
|
+
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
|
|
408
377
|
const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
|
|
409
378
|
environmentConfig,
|
|
410
|
-
entryPointBasePath
|
|
411
|
-
supplementalFieldValues
|
|
379
|
+
entryPointBasePath
|
|
412
380
|
}) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
|
|
413
381
|
let html = await renderStreamToPromise(
|
|
414
382
|
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
package/dist/run.js
CHANGED
|
@@ -127,7 +127,6 @@ function packagePath(metaUrl, projectPath) {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
// ../cms-js-internal/dist/index.js
|
|
130
|
-
import { hasProperty, setProperty, getProperty } from "dot-prop";
|
|
131
130
|
import path2 from "path";
|
|
132
131
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
133
132
|
import stream from "stream";
|
|
@@ -163,7 +162,7 @@ function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent =
|
|
|
163
162
|
${indentString}`
|
|
164
163
|
);
|
|
165
164
|
}
|
|
166
|
-
var serializeIslandDataForInlineScript = (tweakedIslandsArray,
|
|
165
|
+
var serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, prettyPrint) => {
|
|
167
166
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
168
167
|
({
|
|
169
168
|
id,
|
|
@@ -175,7 +174,6 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestD
|
|
|
175
174
|
priority,
|
|
176
175
|
url: url3,
|
|
177
176
|
sharedStateID,
|
|
178
|
-
supplementalFieldValues,
|
|
179
177
|
wrapperModuleId,
|
|
180
178
|
wrapperUrl
|
|
181
179
|
}) => {
|
|
@@ -198,13 +196,6 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestD
|
|
|
198
196
|
if (wrapperUrl) {
|
|
199
197
|
output.wrapperUrl = wrapperUrl;
|
|
200
198
|
}
|
|
201
|
-
const filteredSupplementalFieldValues = filterOutUnreadSupplementalFieldValues(
|
|
202
|
-
supplementalFieldValues,
|
|
203
|
-
perServerRequestData.get("supplementalFieldValuesRead")
|
|
204
|
-
);
|
|
205
|
-
if (filteredSupplementalFieldValues) {
|
|
206
|
-
output.supplementalFieldValues = filteredSupplementalFieldValues;
|
|
207
|
-
}
|
|
208
199
|
return output;
|
|
209
200
|
}
|
|
210
201
|
);
|
|
@@ -214,25 +205,6 @@ var serializeIslandDataForInlineScript = (tweakedIslandsArray, perServerRequestD
|
|
|
214
205
|
prettyPrint
|
|
215
206
|
});
|
|
216
207
|
};
|
|
217
|
-
function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
|
|
218
|
-
if (!supplementalFieldValues) {
|
|
219
|
-
return supplementalFieldValues;
|
|
220
|
-
}
|
|
221
|
-
if (!supplementalFieldValuesRead) {
|
|
222
|
-
return supplementalFieldValues;
|
|
223
|
-
}
|
|
224
|
-
const result = {};
|
|
225
|
-
Array.from(supplementalFieldValuesRead).forEach((fieldPath) => {
|
|
226
|
-
if (hasProperty(supplementalFieldValues, fieldPath)) {
|
|
227
|
-
setProperty(
|
|
228
|
-
result,
|
|
229
|
-
fieldPath,
|
|
230
|
-
getProperty(supplementalFieldValues, fieldPath)
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
return result;
|
|
235
|
-
}
|
|
236
208
|
var writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0, prettyPrint) => {
|
|
237
209
|
const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
|
|
238
210
|
if (sharedStateIDs.length > 0) {
|
|
@@ -310,7 +282,6 @@ var createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevS
|
|
|
310
282
|
indent
|
|
311
283
|
)}window.__islands = ${serializeIslandDataForInlineScript(
|
|
312
284
|
islands,
|
|
313
|
-
perServerRequestData,
|
|
314
285
|
indent,
|
|
315
286
|
prettyPrint
|
|
316
287
|
)}${writeSharedStateToJsGlobal(
|
|
@@ -457,12 +428,10 @@ ${consoleLines.join("\n")}
|
|
|
457
428
|
${groupEnd}</script>
|
|
458
429
|
`;
|
|
459
430
|
};
|
|
460
|
-
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath,
|
|
461
|
-
const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
|
|
431
|
+
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
|
|
462
432
|
const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
|
|
463
433
|
environmentConfig,
|
|
464
|
-
entryPointBasePath
|
|
465
|
-
supplementalFieldValues
|
|
434
|
+
entryPointBasePath
|
|
466
435
|
}) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
|
|
467
436
|
let html = await renderStreamToPromise(
|
|
468
437
|
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
@@ -997,7 +966,7 @@ function trackUsage(action) {
|
|
|
997
966
|
eventName: EVENT_NAME,
|
|
998
967
|
action,
|
|
999
968
|
nodeVersion: getNodeVersionData(),
|
|
1000
|
-
version: "0.14.
|
|
969
|
+
version: "0.14.2",
|
|
1001
970
|
os: getPlatform()
|
|
1002
971
|
};
|
|
1003
972
|
const uri = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
|
|
@@ -53,7 +53,6 @@ __export(dist_exports, {
|
|
|
53
53
|
ungatedAtBuildTimeFor: () => ungatedAtBuildTimeFor,
|
|
54
54
|
virtualClientRenderIslandModuleId: () => virtualClientRenderIslandModuleId
|
|
55
55
|
});
|
|
56
|
-
import { hasProperty, setProperty, getProperty } from "dot-prop";
|
|
57
56
|
import path from "path";
|
|
58
57
|
import * as jsxRuntime from "react/jsx-runtime";
|
|
59
58
|
import stream from "stream";
|
|
@@ -101,25 +100,6 @@ function jsonStringifyAndEscapeForInlineJS(input, { baseIndent = 0, jsonIndent =
|
|
|
101
100
|
${indentString}`
|
|
102
101
|
);
|
|
103
102
|
}
|
|
104
|
-
function filterOutUnreadSupplementalFieldValues(supplementalFieldValues, supplementalFieldValuesRead) {
|
|
105
|
-
if (!supplementalFieldValues) {
|
|
106
|
-
return supplementalFieldValues;
|
|
107
|
-
}
|
|
108
|
-
if (!supplementalFieldValuesRead) {
|
|
109
|
-
return supplementalFieldValues;
|
|
110
|
-
}
|
|
111
|
-
const result = {};
|
|
112
|
-
Array.from(supplementalFieldValuesRead).forEach((fieldPath) => {
|
|
113
|
-
if (hasProperty(supplementalFieldValues, fieldPath)) {
|
|
114
|
-
setProperty(
|
|
115
|
-
result,
|
|
116
|
-
fieldPath,
|
|
117
|
-
getProperty(supplementalFieldValues, fieldPath)
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
103
|
function getIslandUrls(roots, viteDevServer) {
|
|
124
104
|
return roots.map((island) => {
|
|
125
105
|
const islandModule = viteDevServer.moduleGraph.getModuleById(
|
|
@@ -230,24 +210,21 @@ function clientIslandEntryPlugin() {
|
|
|
230
210
|
}
|
|
231
211
|
};
|
|
232
212
|
}
|
|
233
|
-
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath,
|
|
213
|
+
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, renderOptions) {
|
|
234
214
|
const componentDebugName = Component.displayName || Component.name;
|
|
235
215
|
return renderOnServer(
|
|
236
216
|
/* @__PURE__ */ jsx2(Component, { ...props }),
|
|
237
217
|
pageUrl,
|
|
238
218
|
environmentConfig,
|
|
239
219
|
entryPointBasePath,
|
|
240
|
-
contextOptions,
|
|
241
220
|
componentDebugName,
|
|
242
221
|
renderOptions
|
|
243
222
|
);
|
|
244
223
|
}
|
|
245
|
-
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath,
|
|
246
|
-
const supplementalFieldValues = contextOptions ? contextOptions.supplementalFieldValues : void 0;
|
|
224
|
+
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
|
|
247
225
|
const renderContext = cmsComponents.createServerRenderContextV2 ? cmsComponents.createServerRenderContextV2(pageUrl, {
|
|
248
226
|
environmentConfig,
|
|
249
|
-
entryPointBasePath
|
|
250
|
-
supplementalFieldValues
|
|
227
|
+
entryPointBasePath
|
|
251
228
|
}) : cmsComponents.createServerRenderContext(pageUrl, environmentConfig);
|
|
252
229
|
let html = await renderStreamToPromise(
|
|
253
230
|
/* @__PURE__ */ jsx2(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
@@ -496,7 +473,7 @@ var init_dist = __esm({
|
|
|
496
473
|
">": "\\u003E",
|
|
497
474
|
"/": "\\u002F"
|
|
498
475
|
};
|
|
499
|
-
serializeIslandDataForInlineScript = (tweakedIslandsArray,
|
|
476
|
+
serializeIslandDataForInlineScript = (tweakedIslandsArray, baseIndent = 0, prettyPrint) => {
|
|
500
477
|
const islandsArrayToSerialize = tweakedIslandsArray.map(
|
|
501
478
|
({
|
|
502
479
|
id,
|
|
@@ -508,7 +485,6 @@ var init_dist = __esm({
|
|
|
508
485
|
priority,
|
|
509
486
|
url,
|
|
510
487
|
sharedStateID,
|
|
511
|
-
supplementalFieldValues,
|
|
512
488
|
wrapperModuleId,
|
|
513
489
|
wrapperUrl
|
|
514
490
|
}) => {
|
|
@@ -531,13 +507,6 @@ var init_dist = __esm({
|
|
|
531
507
|
if (wrapperUrl) {
|
|
532
508
|
output.wrapperUrl = wrapperUrl;
|
|
533
509
|
}
|
|
534
|
-
const filteredSupplementalFieldValues = filterOutUnreadSupplementalFieldValues(
|
|
535
|
-
supplementalFieldValues,
|
|
536
|
-
perServerRequestData.get("supplementalFieldValuesRead")
|
|
537
|
-
);
|
|
538
|
-
if (filteredSupplementalFieldValues) {
|
|
539
|
-
output.supplementalFieldValues = filteredSupplementalFieldValues;
|
|
540
|
-
}
|
|
541
510
|
return output;
|
|
542
511
|
}
|
|
543
512
|
);
|
|
@@ -581,7 +550,6 @@ ${indentString}`);
|
|
|
581
550
|
indent
|
|
582
551
|
)}window.__islands = ${serializeIslandDataForInlineScript(
|
|
583
552
|
islands,
|
|
584
|
-
perServerRequestData,
|
|
585
553
|
indent,
|
|
586
554
|
prettyPrint
|
|
587
555
|
)}${writeSharedStateToJsGlobal(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/cms-dev-server",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.2",
|
|
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.14.
|
|
29
|
+
"@hubspot/cms-components": "^0.14.2",
|
|
30
30
|
"@originjs/vite-plugin-commonjs": "^1.0.3",
|
|
31
31
|
"@storybook/addon-actions": "7.0.7",
|
|
32
32
|
"@storybook/addon-essentials": "7.0.7",
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
"publishConfig": {
|
|
107
107
|
"access": "public"
|
|
108
108
|
},
|
|
109
|
-
"gitHead": "
|
|
109
|
+
"gitHead": "3cdf0bda841f30c17da5f55f6a52288572ba4967"
|
|
110
110
|
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { createServer } from "vite";
|
|
2
|
-
import react from "@vitejs/plugin-react";
|
|
3
|
-
import { isUngatedFor, clientIslandEntryPlugin, resolveIslandPlugin } from "./index-de34229d.js";
|
|
4
|
-
import mkcert from "vite-plugin-mkcert";
|
|
5
|
-
const islandRuntime = 'const HYDRATION_WAITING = "HYDRATION_WAITING";\nconst HYDRATION_PREPARING = "HYDRATION_PREPARING";\nconst HYDRATION_QUEUED = "HYDRATION_QUEUED";\nconst HYDRATED = "HYDRATED";\nlet rootsToProcess;\nlet hydrationQueue = [];\nconst hydrationTypesToAccept = /* @__PURE__ */ new Set(["load", "visible"]);\nlet startHydratingIdleRootsTimeout;\nconst shouldForceSeparateJsForAllIslands = /(&|\\?)forceSeparateIslandJs=true/.test(window.location.search);\nlet scheduledHydrationIndexCtr = 1;\nconst rootsById = /* @__PURE__ */ new Map();\nconst typedWindow = window;\nconst startHydratingIdleRoots = () => {\n hydrationTypesToAccept.add("idle");\n for (const root of rootsToProcess) {\n if (root.hydrationStatus === HYDRATION_WAITING && hydrationTypesToAccept.has(root.hydrateOn)) {\n root.hydrationStatus = HYDRATION_PREPARING;\n waitThenLoadAndHydrateIfNeeded(root, getLoadableModuleFor(root));\n }\n }\n};\nfunction setupIdleCallbackIfNeeded() {\n if (!startHydratingIdleRootsTimeout) {\n if (!window.requestIdleCallback) {\n setTimeout(() => {\n startHydratingIdleRoots();\n }, 1);\n return;\n }\n startHydratingIdleRootsTimeout = requestIdleCallback(\n startHydratingIdleRoots,\n { timeout: 5e3 }\n );\n }\n}\nfunction finishHydratingRootAndScheduleNext(rootAndExtraInfo) {\n rootAndExtraInfo.root.hydrationStatus = HYDRATED;\n hydrationQueue = hydrationQueue.filter(\n (x) => x.root.id !== rootAndExtraInfo.root.id\n );\n const hasOtherRootsToHydrate = hydrationQueue.length > 0;\n if (hasOtherRootsToHydrate) {\n setTimeout(() => hydrateRoot(hydrationQueue[0]), 0);\n } else if (!hasOtherRootsToHydrate && !hydrationTypesToAccept.has("idle")) {\n setupIdleCallbackIfNeeded();\n }\n}\nfunction hydrateRoot(rootAndExtraInfo) {\n const { rootEl, root, IslandModule } = rootAndExtraInfo;\n console.log("Hydrating root", root.id, root.hydrateOn);\n const postHydration = () => {\n finishHydratingRootAndScheduleNext(rootAndExtraInfo);\n };\n const renderableIsland = {\n rootElement: rootEl,\n pageUrl: typedWindow.__hsServerPageUrl,\n basePath: typedWindow.__hsBasePath,\n islands: typedWindow.__islands,\n postHydration,\n island: root,\n index: rootAndExtraInfo.islandScheduledIndex\n };\n const reactRoot = IslandModule.render(renderableIsland);\n rootsById[root.id] = reactRoot;\n}\nfunction pushToHydrationQueue(rootAndExtraInfo) {\n rootAndExtraInfo.root.hydrationStatus = HYDRATION_QUEUED;\n hydrationQueue.push(rootAndExtraInfo);\n if (hydrationQueue.length === 1) {\n hydrateRoot(rootAndExtraInfo);\n }\n}\nfunction loadThenHydrate(root, LoadableIslandModule, rootEl, islandScheduledIndex) {\n LoadableIslandModule().then((IslandModule) => {\n pushToHydrationQueue({\n rootEl,\n root,\n IslandModule,\n islandScheduledIndex\n });\n }).catch((error) => {\n console.error(`Failed to load module for island: ${root.id}`);\n console.error(error);\n });\n}\nfunction waitThenLoadAndHydrateIfNeeded(root, LoadableIslandModule) {\n const rootEl = document.getElementById(root.id);\n const islandScheduledIndex = scheduledHydrationIndexCtr;\n scheduledHydrationIndexCtr += 1;\n if (root.hydrateOn === "visible") {\n onVisible(rootEl, () => {\n loadThenHydrate(root, LoadableIslandModule, rootEl, islandScheduledIndex);\n });\n } else {\n loadThenHydrate(root, LoadableIslandModule, rootEl, islandScheduledIndex);\n }\n}\nfunction getLoadableModuleFor(root) {\n let url = `${window.location.origin}${root.url}`;\n if (shouldForceSeparateJsForAllIslands) {\n url = `${root.url}?cacheBust=${Date.now()}-${root.id}`;\n }\n const LoadableIslandModule = () => import(\n /* @vite-ignore */\n url\n );\n if (!LoadableIslandModule) {\n throw new Error(`Missing island component for ${root.moduleName}`);\n }\n return LoadableIslandModule;\n}\nfunction hydrateIslandRoots() {\n if (rootsToProcess === void 0) {\n rootsToProcess = typedWindow.__islands;\n console.log("Starting to hydrate", rootsToProcess);\n if (shouldForceSeparateJsForAllIslands) {\n console.log(" ... forcibly making every island refetch JS");\n }\n }\n let encounteredAnyNonIdleIslands = false;\n for (const root of rootsToProcess) {\n if (!root.hydrationStatus) {\n root.hydrationStatus = root.hydrationStatus || HYDRATION_WAITING;\n if (hydrationTypesToAccept.has(root.hydrateOn)) {\n encounteredAnyNonIdleIslands = true;\n root.hydrationStatus = HYDRATION_PREPARING;\n waitThenLoadAndHydrateIfNeeded(root, getLoadableModuleFor(root));\n }\n }\n }\n if (rootsToProcess.length > 0 && !encounteredAnyNonIdleIslands) {\n setupIdleCallbackIfNeeded();\n }\n}\nfunction setupIslandHydration() {\n if (document.readyState === "interactive" || document.readyState === "complete") {\n hydrateIslandRoots();\n } else {\n window.addEventListener("DOMContentLoaded", hydrateIslandRoots);\n }\n}\nfunction unmountIsland(islandId) {\n const islandToUnmount = rootsToProcess.find((island) => island.id === islandId);\n if (!islandToUnmount || !rootsById[islandId]) {\n throw new Error(`No known island: ${islandId}`);\n }\n const islandIndex = rootsToProcess.indexOf(islandToUnmount);\n const reactRoot = rootsById[islandId];\n rootsToProcess.splice(islandIndex, 1);\n delete rootsById[islandId];\n console.log("Unmounting island:", islandId);\n reactRoot.unmount();\n}\nconst onVisible = (islandEl, callback) => {\n const observer = new IntersectionObserver((entries) => {\n if (entries.some((entry) => entry.isIntersecting)) {\n observer.disconnect();\n callback();\n }\n return;\n });\n for (let i = 0; i < islandEl.children.length; i++) {\n const child = islandEl.children[i];\n observer.observe(child);\n }\n};\nexport {\n setupIslandHydration,\n unmountIsland\n};\n';
|
|
6
|
-
async function createViteDevServer(webRoot, port, sslEnabled, domainsToProxy = [], jsRenderingGates) {
|
|
7
|
-
const sharedDepsEnabled = isUngatedFor(
|
|
8
|
-
jsRenderingGates,
|
|
9
|
-
"CMS:JSRenderer:SharedDeps"
|
|
10
|
-
);
|
|
11
|
-
const additionalMkcertHosts = domainsToProxy.map((proxyDomain) => [
|
|
12
|
-
`${proxyDomain}.localhost`,
|
|
13
|
-
`${proxyDomain}.hslocal.net`
|
|
14
|
-
]).flat();
|
|
15
|
-
additionalMkcertHosts.push("*.hslocal.net", "hslocal.net");
|
|
16
|
-
const origin = sslEnabled ? `https://hslocal.net:${port}` : `http://hslocal.net:${port}`;
|
|
17
|
-
const viteConfig = {
|
|
18
|
-
appType: "custom",
|
|
19
|
-
server: {
|
|
20
|
-
middlewareMode: true,
|
|
21
|
-
host: "hslocal.net",
|
|
22
|
-
origin,
|
|
23
|
-
https: sslEnabled,
|
|
24
|
-
hmr: {
|
|
25
|
-
protocol: sslEnabled ? "wss" : void 0
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
ssr: {
|
|
29
|
-
// TODO: might need more entries here to get things to resolve through
|
|
30
|
-
// resolveWebRootDepsPlugin
|
|
31
|
-
noExternal: "@hubspot/cms-components"
|
|
32
|
-
},
|
|
33
|
-
resolve: {
|
|
34
|
-
conditions: ["server"],
|
|
35
|
-
dedupe: ["react", "react-dom", "@hubspot/cms-components"]
|
|
36
|
-
},
|
|
37
|
-
optimizeDeps: {
|
|
38
|
-
include: ["react", "react-dom", "react-dom/client"]
|
|
39
|
-
},
|
|
40
|
-
plugins: [
|
|
41
|
-
{
|
|
42
|
-
name: "island-runtime",
|
|
43
|
-
resolveId(id) {
|
|
44
|
-
if (id === "island-runtime") {
|
|
45
|
-
return id;
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
48
|
-
},
|
|
49
|
-
load(id) {
|
|
50
|
-
if (id === "island-runtime") {
|
|
51
|
-
return islandRuntime;
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
sslEnabled ? mkcert({ hosts: additionalMkcertHosts }) : null,
|
|
57
|
-
react(),
|
|
58
|
-
sharedDepsEnabled && clientIslandEntryPlugin(),
|
|
59
|
-
resolveIslandPlugin(jsRenderingGates)
|
|
60
|
-
],
|
|
61
|
-
css: {
|
|
62
|
-
postcss: webRoot
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
return createServer(viteConfig);
|
|
66
|
-
}
|
|
67
|
-
export {
|
|
68
|
-
createViteDevServer as c
|
|
69
|
-
};
|
package/dist/index-de34229d.js
DELETED
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
import path, { basename } from "path";
|
|
2
|
-
import { readFileSync, existsSync, readdirSync, lstatSync } from "fs";
|
|
3
|
-
import { d as createServerRenderContextV2, e as createServerRenderContext, S as ServerRenderContext, j as jsx$1 } from "./index-e4860c0f.js";
|
|
4
|
-
import stream from "stream";
|
|
5
|
-
import { renderToPipeableStream, renderToStaticMarkup } from "react-dom/server";
|
|
6
|
-
import { createHash } from "crypto";
|
|
7
|
-
import { join } from "path/posix";
|
|
8
|
-
import { cloneElement } from "react";
|
|
9
|
-
import "react/jsx-runtime";
|
|
10
|
-
const COMPONENT_EXTENSIONS = [".jsx", ".tsx", ".js", ".ts"];
|
|
11
|
-
const ENTRY_POINTS_PATH = "components/partials/";
|
|
12
|
-
const MODULE_FOLDER_PATH = "components/modules/";
|
|
13
|
-
const VIRTUAL_ISLAND_RUNTIME = "virtual:island-runtime";
|
|
14
|
-
const VIRTUAL_CONFIG_SETUP = "virtual:config-setup";
|
|
15
|
-
const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
16
|
-
const collectCssModules = (modulePathToStartWith, viteServer, cssModulesImported = /* @__PURE__ */ new Set()) => {
|
|
17
|
-
const appModulesForPath = viteServer.moduleGraph.fileToModulesMap.get(
|
|
18
|
-
modulePathToStartWith
|
|
19
|
-
);
|
|
20
|
-
if (!appModulesForPath || appModulesForPath.size === 0) {
|
|
21
|
-
throw new Error(`No modules at: ${modulePathToStartWith}`);
|
|
22
|
-
} else if (appModulesForPath.size > 1) {
|
|
23
|
-
throw new Error(`More than one module at: ${modulePathToStartWith}`);
|
|
24
|
-
}
|
|
25
|
-
const appModule = Array.from(appModulesForPath.values())[0];
|
|
26
|
-
const allServerSideModulesImported = /* @__PURE__ */ new Set();
|
|
27
|
-
const newCssModules = [];
|
|
28
|
-
const moduleQueue = Array.from(appModule.importedModules);
|
|
29
|
-
for (const importedModule of moduleQueue) {
|
|
30
|
-
if (allServerSideModulesImported.has(importedModule.id)) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
allServerSideModulesImported.add(importedModule.id);
|
|
34
|
-
const isCss = CSS_LANGS_RE.test(importedModule.file);
|
|
35
|
-
const moduleModulesToQueue = Array.from(importedModule.importedModules);
|
|
36
|
-
if (isCss && !cssModulesImported.has(importedModule)) {
|
|
37
|
-
cssModulesImported.add(importedModule);
|
|
38
|
-
newCssModules.push(importedModule);
|
|
39
|
-
}
|
|
40
|
-
moduleQueue.push(...moduleModulesToQueue);
|
|
41
|
-
}
|
|
42
|
-
return newCssModules;
|
|
43
|
-
};
|
|
44
|
-
function createPreloadLink(assetPath, basePath = "") {
|
|
45
|
-
if (assetPath && assetPath[0] !== "/") {
|
|
46
|
-
assetPath = `/${assetPath}`;
|
|
47
|
-
}
|
|
48
|
-
if (assetPath.endsWith(".js")) {
|
|
49
|
-
return `<link rel="modulepreload" crossorigin href="${basePath}${assetPath}">`;
|
|
50
|
-
} else if (CSS_LANGS_RE.test(assetPath)) {
|
|
51
|
-
return `<link rel="stylesheet" href="${basePath}${assetPath}?css">`;
|
|
52
|
-
} else if (assetPath.endsWith(".woff")) {
|
|
53
|
-
return ` <link rel="preload" href="${basePath}${assetPath}" as="font" type="font/woff" crossorigin>`;
|
|
54
|
-
} else if (assetPath.endsWith(".woff2")) {
|
|
55
|
-
return ` <link rel="preload" href="${basePath}${assetPath}" as="font" type="font/woff2" crossorigin>`;
|
|
56
|
-
} else if (assetPath.endsWith(".gif")) {
|
|
57
|
-
return ` <link rel="preload" href="${basePath}${assetPath}" as="image" type="image/gif">`;
|
|
58
|
-
} else if (assetPath.endsWith(".jpg") || assetPath.endsWith(".jpeg")) {
|
|
59
|
-
return ` <link rel="preload" href="${basePath}${assetPath}" as="image" type="image/jpeg">`;
|
|
60
|
-
} else if (assetPath.endsWith(".png")) {
|
|
61
|
-
return ` <link rel="preload" href="${basePath}${assetPath}" as="image" type="image/png">`;
|
|
62
|
-
} else {
|
|
63
|
-
throw new Error(`Unknown preload type for ${assetPath}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const collectCssInDev = (modulePathToStartWith, viteServer, cssModulesImported = /* @__PURE__ */ new Set()) => {
|
|
67
|
-
return `${collectCssModules(
|
|
68
|
-
modulePathToStartWith,
|
|
69
|
-
viteServer,
|
|
70
|
-
cssModulesImported
|
|
71
|
-
).map((cssModule) => createPreloadLink(cssModule.url)).join("\n")}
|
|
72
|
-
`;
|
|
73
|
-
};
|
|
74
|
-
const serializeIslandDataToJSON = (tweakedIslandsArray, indent = 0) => {
|
|
75
|
-
const indentString = new Array(indent).fill(" ").join("");
|
|
76
|
-
return `${JSON.stringify(
|
|
77
|
-
tweakedIslandsArray.map(
|
|
78
|
-
({
|
|
79
|
-
id,
|
|
80
|
-
moduleName,
|
|
81
|
-
moduleId,
|
|
82
|
-
props,
|
|
83
|
-
hydrateOn,
|
|
84
|
-
clientOnly,
|
|
85
|
-
priority,
|
|
86
|
-
url,
|
|
87
|
-
sharedStateID
|
|
88
|
-
}) => {
|
|
89
|
-
const output = {
|
|
90
|
-
id,
|
|
91
|
-
moduleName,
|
|
92
|
-
moduleId,
|
|
93
|
-
hydrateOn,
|
|
94
|
-
clientOnly,
|
|
95
|
-
priority,
|
|
96
|
-
props,
|
|
97
|
-
url
|
|
98
|
-
};
|
|
99
|
-
if (sharedStateID) {
|
|
100
|
-
output.sharedStateID = sharedStateID;
|
|
101
|
-
}
|
|
102
|
-
return output;
|
|
103
|
-
}
|
|
104
|
-
),
|
|
105
|
-
null,
|
|
106
|
-
2
|
|
107
|
-
).replace(/\n/gm, `
|
|
108
|
-
${indentString}`)}`;
|
|
109
|
-
};
|
|
110
|
-
const writeSharedStateToJsGlobal = (islands, perServerRequestData, indent = 0) => {
|
|
111
|
-
const indentString = new Array(indent).fill(" ").join("");
|
|
112
|
-
const sharedStateIDs = islands.map((island) => island.sharedStateID).filter((x) => !!x);
|
|
113
|
-
if (sharedStateIDs.length > 0) {
|
|
114
|
-
const stateByID = {};
|
|
115
|
-
sharedStateIDs.forEach(
|
|
116
|
-
(id) => stateByID[id] = perServerRequestData.get(id)
|
|
117
|
-
);
|
|
118
|
-
const stringifiedState = JSON.stringify(stateByID, null, 2);
|
|
119
|
-
return `
|
|
120
|
-
|
|
121
|
-
var newState = ${stringifiedState};
|
|
122
|
-
if(window.__hsSSInit) {
|
|
123
|
-
window.__hsSSInit = Object.assign(window.__hsSSInit, newState);
|
|
124
|
-
} else {
|
|
125
|
-
window.__hsSSInit = newState;
|
|
126
|
-
}`.replace(/\n/gm, `
|
|
127
|
-
${indentString}`);
|
|
128
|
-
}
|
|
129
|
-
return "";
|
|
130
|
-
};
|
|
131
|
-
function getIslandUrls(roots, viteDevServer) {
|
|
132
|
-
return roots.map((island) => {
|
|
133
|
-
const islandModule = viteDevServer.moduleGraph.getModuleById(
|
|
134
|
-
island.moduleId
|
|
135
|
-
);
|
|
136
|
-
if (!islandModule) {
|
|
137
|
-
throw new Error(`Unknown island moduleId: ${island.moduleId}`);
|
|
138
|
-
}
|
|
139
|
-
const tweakedIsland = {
|
|
140
|
-
...island,
|
|
141
|
-
url: islandModule.url
|
|
142
|
-
};
|
|
143
|
-
return tweakedIsland;
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
const createIslandsGlobalJsForClientInDev = (roots, perServerRequestData, viteDevServer, indent) => {
|
|
147
|
-
const islands = getIslandUrls(roots, viteDevServer);
|
|
148
|
-
return `window.__islands = ${serializeIslandDataToJSON(
|
|
149
|
-
islands,
|
|
150
|
-
indent
|
|
151
|
-
)}${writeSharedStateToJsGlobal(islands, perServerRequestData, indent)}`;
|
|
152
|
-
};
|
|
153
|
-
const GATES = [
|
|
154
|
-
"CMS:JSRenderer:SharedDeps",
|
|
155
|
-
"CMS:JSRenderer:GetServerSideProps",
|
|
156
|
-
"CMS:JSRenderer:LocalProxySchemaVersion1",
|
|
157
|
-
"CMS:JSRenderer:GraphQLQueryBuild",
|
|
158
|
-
"CMS:JSRenderer:SeparateIslandRenderOption"
|
|
159
|
-
];
|
|
160
|
-
const ENABLED_FEATURES_GATE_MAP = {
|
|
161
|
-
"cms:jsr:sharedDeps": "CMS:JSRenderer:SharedDeps",
|
|
162
|
-
"cms:jsr:getServerSideProps": "CMS:JSRenderer:GetServerSideProps",
|
|
163
|
-
"cms:jsr:localProxySchemaVersion1": "CMS:JSRenderer:LocalProxySchemaVersion1",
|
|
164
|
-
"cms:jsr:graphqQLQueryBuild": "CMS:JSRenderer:GraphQLQueryBuild",
|
|
165
|
-
"cms:jsr:separateIslandRenderOption": "CMS:JSRenderer:SeparateIslandRenderOption"
|
|
166
|
-
};
|
|
167
|
-
function isUngatedFor(gates, gate) {
|
|
168
|
-
return gates.includes(gate);
|
|
169
|
-
}
|
|
170
|
-
const BUILD_INFO_PATH = "/build-info.json";
|
|
171
|
-
function ungatedAtBuildTimeFor(buildDir, gate) {
|
|
172
|
-
try {
|
|
173
|
-
console.log("loading path", path.join(buildDir, BUILD_INFO_PATH));
|
|
174
|
-
const buildInfo = JSON.parse(
|
|
175
|
-
readFileSync(path.join(buildDir, BUILD_INFO_PATH)).toString()
|
|
176
|
-
);
|
|
177
|
-
return isUngatedFor(buildInfo.gates, gate);
|
|
178
|
-
} catch (e) {
|
|
179
|
-
console.error(`error loading build-info.json, path: ${BUILD_INFO_PATH}`);
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
let viteRoot;
|
|
184
|
-
let viteCommand;
|
|
185
|
-
function resolveIslandPlugin(gates) {
|
|
186
|
-
const sharedDepsEnabled = isUngatedFor(gates, "CMS:JSRenderer:SharedDeps");
|
|
187
|
-
return {
|
|
188
|
-
enforce: "pre",
|
|
189
|
-
name: "resolve-islands",
|
|
190
|
-
configResolved(config) {
|
|
191
|
-
viteRoot = config.root;
|
|
192
|
-
viteCommand = config.command;
|
|
193
|
-
},
|
|
194
|
-
load(id) {
|
|
195
|
-
if (id.endsWith("?island") || id.endsWith("?client")) {
|
|
196
|
-
const [idWithNoParam] = id.split("?");
|
|
197
|
-
const islandModuleImportPath = sharedDepsEnabled ? `${idWithNoParam}?client-entry` : idWithNoParam;
|
|
198
|
-
const componentExtension = path.extname(idWithNoParam);
|
|
199
|
-
const componentFilenameWithNoExtension = path.basename(
|
|
200
|
-
idWithNoParam,
|
|
201
|
-
componentExtension
|
|
202
|
-
);
|
|
203
|
-
const modulePath = idWithNoParam.replace(`${viteRoot}/`, "");
|
|
204
|
-
let moduleId = viteCommand === "serve" ? idWithNoParam : modulePath;
|
|
205
|
-
if (sharedDepsEnabled) {
|
|
206
|
-
moduleId = moduleId.concat("?client-entry");
|
|
207
|
-
}
|
|
208
|
-
return `
|
|
209
|
-
const moduleId = '${moduleId}';
|
|
210
|
-
|
|
211
|
-
const lazyComponent = () => import('${islandModuleImportPath}');
|
|
212
|
-
lazyComponent.moduleName = '${componentFilenameWithNoExtension}';
|
|
213
|
-
lazyComponent.moduleId = moduleId;
|
|
214
|
-
|
|
215
|
-
export default lazyComponent;
|
|
216
|
-
`;
|
|
217
|
-
}
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
const clientRenderIsland = "import type { RenderableIsland } from '@hubspot/cms-components';\nimport {\n ClientRenderContextProvider,\n buildIslandIdentifierPrefix,\n} 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: buildIslandIdentifierPrefix(renderableIsland.island.id),\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";
|
|
223
|
-
const virtualClientRenderIslandModuleId = "virtual:clientRenderIsland.tsx";
|
|
224
|
-
function clientIslandEntryPlugin() {
|
|
225
|
-
return {
|
|
226
|
-
enforce: "pre",
|
|
227
|
-
name: "client-island-entry-plugin",
|
|
228
|
-
resolveId(id) {
|
|
229
|
-
if (id === virtualClientRenderIslandModuleId) {
|
|
230
|
-
return virtualClientRenderIslandModuleId;
|
|
231
|
-
}
|
|
232
|
-
return null;
|
|
233
|
-
},
|
|
234
|
-
load(id) {
|
|
235
|
-
if (id.endsWith("?client-entry")) {
|
|
236
|
-
const [idWithNoParam] = id.split("?");
|
|
237
|
-
return `
|
|
238
|
-
import { clientRenderIsland } from '${virtualClientRenderIslandModuleId}';
|
|
239
|
-
import Component from '${idWithNoParam}';
|
|
240
|
-
|
|
241
|
-
export function render(island) {
|
|
242
|
-
return clientRenderIsland(island, Component)
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export default Component;
|
|
246
|
-
`;
|
|
247
|
-
}
|
|
248
|
-
if (id === virtualClientRenderIslandModuleId) {
|
|
249
|
-
return clientRenderIsland;
|
|
250
|
-
}
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
const jsx = jsx$1;
|
|
256
|
-
const promiseForNewWritableStream = () => {
|
|
257
|
-
const chunks = [];
|
|
258
|
-
const writableStream = new stream.Writable();
|
|
259
|
-
writableStream._write = (chunk, encoding, done) => {
|
|
260
|
-
chunks.push(Buffer.from(chunk));
|
|
261
|
-
done();
|
|
262
|
-
};
|
|
263
|
-
const streamDonePromise = new Promise((resolve, reject) => {
|
|
264
|
-
writableStream.on("error", (error) => {
|
|
265
|
-
reject(error);
|
|
266
|
-
});
|
|
267
|
-
writableStream._final = (done) => {
|
|
268
|
-
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
269
|
-
done();
|
|
270
|
-
};
|
|
271
|
-
});
|
|
272
|
-
return { streamDonePromise, writableStream };
|
|
273
|
-
};
|
|
274
|
-
const renderStreamToPromise = async (reactElements, options) => {
|
|
275
|
-
const { streamDonePromise, writableStream } = promiseForNewWritableStream();
|
|
276
|
-
const {
|
|
277
|
-
pipe
|
|
278
|
-
/* abort */
|
|
279
|
-
} = renderToPipeableStream(reactElements, {
|
|
280
|
-
...options || {},
|
|
281
|
-
onShellReady() {
|
|
282
|
-
},
|
|
283
|
-
onAllReady() {
|
|
284
|
-
pipe(writableStream);
|
|
285
|
-
if (options == null ? void 0 : options.onAllReady) {
|
|
286
|
-
options.onAllReady();
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
return streamDonePromise;
|
|
291
|
-
};
|
|
292
|
-
const scriptTagToLogServerMessages = (messagesForBrowser, groupLabel) => {
|
|
293
|
-
if (!messagesForBrowser) {
|
|
294
|
-
return "";
|
|
295
|
-
}
|
|
296
|
-
const consoleLines = [];
|
|
297
|
-
for (const message of messagesForBrowser) {
|
|
298
|
-
const funcString = message.level === "error" ? "console.error" : "console.warn";
|
|
299
|
-
const argString = message.parameters.map((arg) => JSON.stringify(arg)).join(", ");
|
|
300
|
-
consoleLines.push(` ${funcString}(${argString});`);
|
|
301
|
-
}
|
|
302
|
-
let groupStart = "";
|
|
303
|
-
let groupEnd = "";
|
|
304
|
-
if (groupLabel !== null) {
|
|
305
|
-
groupStart = `
|
|
306
|
-
console.group(${JSON.stringify(groupLabel)});`;
|
|
307
|
-
groupEnd = ` console.groupEnd()
|
|
308
|
-
`;
|
|
309
|
-
}
|
|
310
|
-
return `<script>${groupStart}
|
|
311
|
-
${consoleLines.join("\n")}
|
|
312
|
-
${groupEnd}<\/script>
|
|
313
|
-
`;
|
|
314
|
-
};
|
|
315
|
-
async function renderComponentOnServer(Component, props, pageUrl, environmentConfig, entryPointBasePath, renderOptions) {
|
|
316
|
-
const componentDebugName = Component.displayName || Component.name;
|
|
317
|
-
return renderOnServer(
|
|
318
|
-
/* @__PURE__ */ jsx(Component, { ...props }),
|
|
319
|
-
pageUrl,
|
|
320
|
-
environmentConfig,
|
|
321
|
-
entryPointBasePath,
|
|
322
|
-
componentDebugName,
|
|
323
|
-
renderOptions
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
async function renderOnServer(elements, pageUrl, environmentConfig, entryPointBasePath, debugName, renderOptions) {
|
|
327
|
-
const renderContext = createServerRenderContextV2 ? createServerRenderContextV2(pageUrl, {
|
|
328
|
-
environmentConfig,
|
|
329
|
-
entryPointBasePath
|
|
330
|
-
}) : createServerRenderContext(pageUrl, environmentConfig);
|
|
331
|
-
let html = await renderStreamToPromise(
|
|
332
|
-
/* @__PURE__ */ jsx(ServerRenderContext.Provider, { value: renderContext, children: elements }),
|
|
333
|
-
renderOptions
|
|
334
|
-
);
|
|
335
|
-
if (renderContext.messagesForBrowser.length > 0) {
|
|
336
|
-
html = `${html}${scriptTagToLogServerMessages(
|
|
337
|
-
renderContext.messagesForBrowser,
|
|
338
|
-
`Server messages rendering: ${debugName}`
|
|
339
|
-
)}`;
|
|
340
|
-
}
|
|
341
|
-
return { html, renderContext };
|
|
342
|
-
}
|
|
343
|
-
const getComponentExtension = (componentPath) => {
|
|
344
|
-
const filteredExtensions = COMPONENT_EXTENSIONS.filter(
|
|
345
|
-
(ext) => componentPath.endsWith(ext)
|
|
346
|
-
);
|
|
347
|
-
if (filteredExtensions.length === 1) {
|
|
348
|
-
return filteredExtensions[0];
|
|
349
|
-
}
|
|
350
|
-
return void 0;
|
|
351
|
-
};
|
|
352
|
-
const hasComponentExtension = (componentPath) => {
|
|
353
|
-
return !!getComponentExtension(componentPath);
|
|
354
|
-
};
|
|
355
|
-
const isStorybookStory = (componentPath) => {
|
|
356
|
-
return !!path.basename(componentPath, path.extname(componentPath)).endsWith(".stories");
|
|
357
|
-
};
|
|
358
|
-
const removeComponentExtension = (componentPath) => {
|
|
359
|
-
const ext = getComponentExtension(componentPath);
|
|
360
|
-
if (ext == null) {
|
|
361
|
-
return componentPath;
|
|
362
|
-
}
|
|
363
|
-
return componentPath.slice(0, -1 * ext.length);
|
|
364
|
-
};
|
|
365
|
-
function getEntryPointHash(entryPoint) {
|
|
366
|
-
return createHash("md5").update(entryPoint).digest("hex").slice(0, 6);
|
|
367
|
-
}
|
|
368
|
-
function getEntryPointHashWithIndexSuffix(entryPoint, index) {
|
|
369
|
-
const renderIndexSuffix = index != null ? `i${index}` : "";
|
|
370
|
-
return `${getEntryPointHash(entryPoint)}${renderIndexSuffix}`;
|
|
371
|
-
}
|
|
372
|
-
const COMBINED_REACT_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/react/v18";
|
|
373
|
-
const ISLAND_RUNTIME_CONFIG_BASE_PATH = "https://static.hsappstatic.net/cms-js-static/ex/js/island-runtime/v1";
|
|
374
|
-
function getCombinedReactUrl() {
|
|
375
|
-
const hsEnv = process.env.HS_ENV;
|
|
376
|
-
const fileVersion = hsEnv === "prod" ? `react-combined.mjs` : "react-combined-qa.mjs";
|
|
377
|
-
return `${COMBINED_REACT_BASE_PATH}/${fileVersion}`;
|
|
378
|
-
}
|
|
379
|
-
function getIslandRuntimeConfigUrl() {
|
|
380
|
-
const hsEnv = process.env.HS_ENV;
|
|
381
|
-
const fileVersion = hsEnv === "prod" ? `island-runtime.mjs` : "island-runtime-qa.mjs";
|
|
382
|
-
return `${ISLAND_RUNTIME_CONFIG_BASE_PATH}/${fileVersion}`;
|
|
383
|
-
}
|
|
384
|
-
const findAllComponentsIn = (webRoot, componentsFolder, includeSubdirIndexJS) => {
|
|
385
|
-
const fullComponentsFolderPath = join(webRoot, componentsFolder);
|
|
386
|
-
const componentsByName = {};
|
|
387
|
-
if (!existsSync(fullComponentsFolderPath)) {
|
|
388
|
-
return componentsByName;
|
|
389
|
-
}
|
|
390
|
-
readdirSync(fullComponentsFolderPath).forEach((fileOrFolderName) => {
|
|
391
|
-
const fullPath = join(fullComponentsFolderPath, fileOrFolderName);
|
|
392
|
-
const subdirPath = join(componentsFolder, fileOrFolderName);
|
|
393
|
-
const isDirectory = lstatSync(fullPath).isDirectory();
|
|
394
|
-
if (!isDirectory && hasComponentExtension(fileOrFolderName) && !isStorybookStory(fileOrFolderName)) {
|
|
395
|
-
const subdirPathNoExtension = removeComponentExtension(subdirPath);
|
|
396
|
-
componentsByName[subdirPathNoExtension] = subdirPath;
|
|
397
|
-
} else if (isDirectory && includeSubdirIndexJS) {
|
|
398
|
-
for (const potentialExtension of COMPONENT_EXTENSIONS) {
|
|
399
|
-
const potentialIndexModule = join(
|
|
400
|
-
subdirPath,
|
|
401
|
-
`index${potentialExtension}`
|
|
402
|
-
);
|
|
403
|
-
const fullPotentialPath = join(
|
|
404
|
-
fullPath,
|
|
405
|
-
`index${potentialExtension}`
|
|
406
|
-
);
|
|
407
|
-
if (existsSync(fullPotentialPath)) {
|
|
408
|
-
const moduleIndexPathNoExtension = removeComponentExtension(potentialIndexModule);
|
|
409
|
-
componentsByName[moduleIndexPathNoExtension] = potentialIndexModule;
|
|
410
|
-
break;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
});
|
|
415
|
-
return componentsByName;
|
|
416
|
-
};
|
|
417
|
-
function findAllModulesInRoot(webRoot) {
|
|
418
|
-
const allModuleComponents = findAllComponentsIn(
|
|
419
|
-
webRoot,
|
|
420
|
-
"./components/modules",
|
|
421
|
-
true
|
|
422
|
-
);
|
|
423
|
-
const moduleNames = Object.keys(allModuleComponents).map(
|
|
424
|
-
(moduleSubpath) => moduleSubpath.replace("components/modules/", "").replace("/index", "")
|
|
425
|
-
);
|
|
426
|
-
const moduleSubpaths = Object.keys(allModuleComponents);
|
|
427
|
-
return { moduleNames, moduleSubpaths };
|
|
428
|
-
}
|
|
429
|
-
function findAllPartialsInRoot(webRoot) {
|
|
430
|
-
const allPartialComponents = findAllComponentsIn(
|
|
431
|
-
webRoot,
|
|
432
|
-
"./components/partials",
|
|
433
|
-
false
|
|
434
|
-
);
|
|
435
|
-
const partialSubpaths = Object.keys(allPartialComponents);
|
|
436
|
-
const partialNames = partialSubpaths.map(
|
|
437
|
-
(partialSubpath) => basename(partialSubpath)
|
|
438
|
-
);
|
|
439
|
-
return { partialNames, partialSubpaths };
|
|
440
|
-
}
|
|
441
|
-
function getServerGlobalsToInject(environmentConfig, hsServerPageUrl, hsBasePath) {
|
|
442
|
-
const globals = [
|
|
443
|
-
`window.__hsEnvConfig = ${JSON.stringify(environmentConfig.toJSON())};`
|
|
444
|
-
];
|
|
445
|
-
if (hsServerPageUrl) {
|
|
446
|
-
globals.push(`window.__hsServerPageUrl = '${hsServerPageUrl}';`);
|
|
447
|
-
}
|
|
448
|
-
if (hsBasePath) {
|
|
449
|
-
globals.push(`window.__hsBasePath = '${hsBasePath}';`);
|
|
450
|
-
}
|
|
451
|
-
return `
|
|
452
|
-
<script type="text/javascript">
|
|
453
|
-
${globals.join("\n ")}
|
|
454
|
-
<\/script>
|
|
455
|
-
`;
|
|
456
|
-
}
|
|
457
|
-
function setIn(object, nestedKeysArray, value) {
|
|
458
|
-
let curr = object;
|
|
459
|
-
const finalKey = nestedKeysArray.pop();
|
|
460
|
-
for (let index = 0; index < nestedKeysArray.length; index++) {
|
|
461
|
-
const currentKey = nestedKeysArray[index];
|
|
462
|
-
const nextKey = nestedKeysArray[index + 1];
|
|
463
|
-
if (Number.isInteger(nextKey) || !nextKey && Number.isInteger(finalKey)) {
|
|
464
|
-
if (curr[currentKey] === void 0) {
|
|
465
|
-
curr[currentKey] = [];
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
if (curr[currentKey] === void 0) {
|
|
469
|
-
curr[currentKey] = {};
|
|
470
|
-
}
|
|
471
|
-
curr = curr[currentKey];
|
|
472
|
-
}
|
|
473
|
-
if (value !== void 0) {
|
|
474
|
-
curr[finalKey] = value;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
function renderFieldsToJson(fields) {
|
|
478
|
-
let moduleJson;
|
|
479
|
-
const outputCallback = (callbackJson) => {
|
|
480
|
-
moduleJson = callbackJson;
|
|
481
|
-
};
|
|
482
|
-
renderToStaticMarkup(
|
|
483
|
-
cloneElement(fields, {
|
|
484
|
-
outputCallback
|
|
485
|
-
})
|
|
486
|
-
);
|
|
487
|
-
return moduleJson;
|
|
488
|
-
}
|
|
489
|
-
export {
|
|
490
|
-
COMPONENT_EXTENSIONS,
|
|
491
|
-
CSS_LANGS_RE,
|
|
492
|
-
ENABLED_FEATURES_GATE_MAP,
|
|
493
|
-
ENTRY_POINTS_PATH,
|
|
494
|
-
GATES,
|
|
495
|
-
MODULE_FOLDER_PATH,
|
|
496
|
-
VIRTUAL_CONFIG_SETUP,
|
|
497
|
-
VIRTUAL_ISLAND_RUNTIME,
|
|
498
|
-
clientIslandEntryPlugin,
|
|
499
|
-
collectCssInDev,
|
|
500
|
-
collectCssModules,
|
|
501
|
-
createIslandsGlobalJsForClientInDev,
|
|
502
|
-
findAllComponentsIn,
|
|
503
|
-
findAllModulesInRoot,
|
|
504
|
-
findAllPartialsInRoot,
|
|
505
|
-
getCombinedReactUrl,
|
|
506
|
-
getComponentExtension,
|
|
507
|
-
getEntryPointHash,
|
|
508
|
-
getEntryPointHashWithIndexSuffix,
|
|
509
|
-
getIslandRuntimeConfigUrl,
|
|
510
|
-
getIslandUrls,
|
|
511
|
-
getServerGlobalsToInject,
|
|
512
|
-
hasComponentExtension,
|
|
513
|
-
isStorybookStory,
|
|
514
|
-
isUngatedFor,
|
|
515
|
-
removeComponentExtension,
|
|
516
|
-
renderComponentOnServer,
|
|
517
|
-
renderFieldsToJson,
|
|
518
|
-
renderOnServer,
|
|
519
|
-
renderStreamToPromise,
|
|
520
|
-
resolveIslandPlugin,
|
|
521
|
-
serializeIslandDataToJSON,
|
|
522
|
-
setIn,
|
|
523
|
-
ungatedAtBuildTimeFor,
|
|
524
|
-
virtualClientRenderIslandModuleId
|
|
525
|
-
};
|
package/dist/index-e4860c0f.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { createContext, useRef, useLayoutEffect } from "react";
|
|
2
|
-
import * as jsxRuntime from "react/jsx-runtime";
|
|
3
|
-
import "stream";
|
|
4
|
-
import "react-dom/server";
|
|
5
|
-
const Fragment = jsxRuntime.Fragment;
|
|
6
|
-
const jsx = jsxRuntime.jsx;
|
|
7
|
-
const jsxs = jsxRuntime.jsxs;
|
|
8
|
-
var define_import_meta_env_default = { DEV: false, PROD: true, SSR: true };
|
|
9
|
-
var renderSequenceNum = 1;
|
|
10
|
-
var createNewServerRequestMap = (renderId) => {
|
|
11
|
-
if (import.meta && define_import_meta_env_default && define_import_meta_env_default.DEBUG) {
|
|
12
|
-
return /* @__PURE__ */ new Map([["__tempRenderId", renderId]]);
|
|
13
|
-
}
|
|
14
|
-
return /* @__PURE__ */ new Map();
|
|
15
|
-
};
|
|
16
|
-
var createServerRenderContext = (pageUrl, environmentConfig, sharedServerRequestData) => {
|
|
17
|
-
const renderId = (renderSequenceNum++).toString(16);
|
|
18
|
-
const perServerRequestData = sharedServerRequestData ?? createNewServerRequestMap(renderId);
|
|
19
|
-
return {
|
|
20
|
-
pageUrl,
|
|
21
|
-
environmentConfig,
|
|
22
|
-
islands: [],
|
|
23
|
-
renderId,
|
|
24
|
-
perServerRequestData,
|
|
25
|
-
messagesForBrowser: [],
|
|
26
|
-
// Satisfies ServerRenderContextValueType
|
|
27
|
-
entryPointBasePath: null
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
var createServerRenderContextV2 = (pageUrl, {
|
|
31
|
-
environmentConfig,
|
|
32
|
-
entryPointBasePath,
|
|
33
|
-
sharedServerRequestData
|
|
34
|
-
}) => {
|
|
35
|
-
const renderId = (renderSequenceNum++).toString(16);
|
|
36
|
-
const perServerRequestData = sharedServerRequestData ?? createNewServerRequestMap(renderId);
|
|
37
|
-
return {
|
|
38
|
-
pageUrl,
|
|
39
|
-
environmentConfig,
|
|
40
|
-
islands: [],
|
|
41
|
-
renderId,
|
|
42
|
-
perServerRequestData,
|
|
43
|
-
messagesForBrowser: [],
|
|
44
|
-
entryPointBasePath
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
var createEmptyServerRenderContext = () => createServerRenderContextV2(null, { environmentConfig: null });
|
|
48
|
-
var ServerRenderContext = createContext(
|
|
49
|
-
createEmptyServerRenderContext()
|
|
50
|
-
);
|
|
51
|
-
var createClientRenderContext = (hsServerPageUrl, hsBasePath, islands = []) => {
|
|
52
|
-
return {
|
|
53
|
-
pageUrl: hsServerPageUrl,
|
|
54
|
-
islands,
|
|
55
|
-
island: null,
|
|
56
|
-
hydrationFinished: { current: false },
|
|
57
|
-
entryPointBasePath: hsBasePath
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
var ClientRenderContext = createContext(
|
|
61
|
-
createClientRenderContext(null, null)
|
|
62
|
-
);
|
|
63
|
-
var ClientRenderContextProvider = ({
|
|
64
|
-
children,
|
|
65
|
-
islands,
|
|
66
|
-
island,
|
|
67
|
-
pageUrl,
|
|
68
|
-
basePath,
|
|
69
|
-
onTopLevelHydrationFinish
|
|
70
|
-
}) => {
|
|
71
|
-
const hydrationFinished = useRef(false);
|
|
72
|
-
const contextValue = {
|
|
73
|
-
pageUrl,
|
|
74
|
-
islands,
|
|
75
|
-
hydrationFinished,
|
|
76
|
-
island,
|
|
77
|
-
entryPointBasePath: basePath
|
|
78
|
-
};
|
|
79
|
-
useLayoutEffect(() => {
|
|
80
|
-
if (hydrationFinished.current) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
hydrationFinished.current = true;
|
|
84
|
-
if (onTopLevelHydrationFinish) {
|
|
85
|
-
onTopLevelHydrationFinish();
|
|
86
|
-
}
|
|
87
|
-
}, [onTopLevelHydrationFinish]);
|
|
88
|
-
return /* @__PURE__ */ jsx(ClientRenderContext.Provider, { value: contextValue, children });
|
|
89
|
-
};
|
|
90
|
-
var mergeServerRequestData_internal = (dataA, dataB) => {
|
|
91
|
-
const toMerge = [...dataA, ...dataB];
|
|
92
|
-
if (dataA.has("sharedStateIDs") && dataB.has("sharedStateIDs")) {
|
|
93
|
-
const mergedSet = /* @__PURE__ */ new Set([
|
|
94
|
-
...dataA.get("sharedStateIDs"),
|
|
95
|
-
...dataB.get("sharedStateIDs")
|
|
96
|
-
]);
|
|
97
|
-
toMerge.push(["sharedStateIDs", mergedSet]);
|
|
98
|
-
}
|
|
99
|
-
return new Map(toMerge);
|
|
100
|
-
};
|
|
101
|
-
var UNSET_SHARED_STATE_ID = "hs-basic-shared-state-unset-id";
|
|
102
|
-
var ExistingIslandContext = createContext(null);
|
|
103
|
-
ExistingIslandContext.Provider;
|
|
104
|
-
createContext({
|
|
105
|
-
id: UNSET_SHARED_STATE_ID,
|
|
106
|
-
state: null
|
|
107
|
-
});
|
|
108
|
-
function buildStaticEnvConfig(portalID, hublet, hsEnv, hsDeployed, hsJSRGates) {
|
|
109
|
-
const getPortalID2 = () => portalID;
|
|
110
|
-
const getHubID = getPortalID2;
|
|
111
|
-
const getHublet2 = () => hublet;
|
|
112
|
-
const getInternalHSEnv = () => hsEnv;
|
|
113
|
-
const getIsDeployed2 = () => hsDeployed;
|
|
114
|
-
const getGates = () => hsJSRGates;
|
|
115
|
-
const toJSON = () => ({
|
|
116
|
-
portalID,
|
|
117
|
-
hublet,
|
|
118
|
-
hsEnv,
|
|
119
|
-
hsDeployed,
|
|
120
|
-
hsJSRGates
|
|
121
|
-
});
|
|
122
|
-
const equals = (envConfig) => {
|
|
123
|
-
return portalID === envConfig.getPortalID() && hsEnv === envConfig.getInternalHSEnv() && hublet === envConfig.getHublet() && hsDeployed === envConfig.getIsDeployed();
|
|
124
|
-
};
|
|
125
|
-
return {
|
|
126
|
-
getPortalID: getPortalID2,
|
|
127
|
-
getHubID,
|
|
128
|
-
getHublet: getHublet2,
|
|
129
|
-
getInternalHSEnv,
|
|
130
|
-
getIsDeployed: getIsDeployed2,
|
|
131
|
-
equals,
|
|
132
|
-
getGates,
|
|
133
|
-
toJSON
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
if (import.meta && define_import_meta_env_default && !define_import_meta_env_default.SSR) {
|
|
137
|
-
new URL(window.location.href);
|
|
138
|
-
}
|
|
139
|
-
export {
|
|
140
|
-
ClientRenderContextProvider as C,
|
|
141
|
-
Fragment as F,
|
|
142
|
-
ServerRenderContext as S,
|
|
143
|
-
jsxs as a,
|
|
144
|
-
buildStaticEnvConfig as b,
|
|
145
|
-
createEmptyServerRenderContext as c,
|
|
146
|
-
createServerRenderContextV2 as d,
|
|
147
|
-
createServerRenderContext as e,
|
|
148
|
-
jsx as j,
|
|
149
|
-
mergeServerRequestData_internal as m
|
|
150
|
-
};
|
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
|
-
};
|