@hubspot/cms-dev-server 1.2.75 → 1.2.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1650,7 +1650,7 @@ function trackUsage(action) {
1650
1650
  eventName: EVENT_NAME,
1651
1651
  action,
1652
1652
  nodeVersion: getNodeVersionData(),
1653
- version: "1.2.75",
1653
+ version: "1.2.77",
1654
1654
  os: getPlatform()
1655
1655
  };
1656
1656
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -3092,6 +3092,7 @@ function extractRelevantCss(cssText) {
3092
3092
 
3093
3093
  // src/lib/renderModulePreview.ts
3094
3094
  import jsdom from "jsdom";
3095
+ var DEFAULT_SECTION_VARIANT = "section1";
3095
3096
  var _webDefaultStylesCss = null;
3096
3097
  function getWebDefaultStylesCss(metaUrl) {
3097
3098
  if (_webDefaultStylesCss === null) {
@@ -3344,6 +3345,7 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3344
3345
  const themeVariablesCss = filteredCss ? `<style data-hs-styles="theme-variables">${filteredCss}</style>` : "";
3345
3346
  const webDefaultStylesCss = meta.editor_version === "2.0" ? getWebDefaultStylesCss(import.meta.url) : "";
3346
3347
  const globalStylesCss = [themeVariablesCss, webDefaultStylesCss].filter(Boolean).join("\n");
3348
+ const sectionVariant = filteredCss ? DEFAULT_SECTION_VARIANT : void 0;
3347
3349
  const renderResult = await renderComponentForPlaceholder(
3348
3350
  0,
3349
3351
  localRenderPlaceholders[0],
@@ -3355,7 +3357,7 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3355
3357
  projectName,
3356
3358
  projectComponentPath
3357
3359
  );
3358
- return { ...renderResult, globalStylesCss };
3360
+ return { ...renderResult, globalStylesCss, sectionVariant };
3359
3361
  }
3360
3362
 
3361
3363
  // src/routes/partial.ts
@@ -4296,7 +4298,8 @@ async function modulePreviewRouteHandler(request, response) {
4296
4298
  cssNeeded,
4297
4299
  renderContext,
4298
4300
  inlineAssets,
4299
- globalStylesCss
4301
+ globalStylesCss,
4302
+ sectionVariant
4300
4303
  } = await renderLocalProjectModulePreview(
4301
4304
  moduleName,
4302
4305
  authedPortalId,
@@ -4324,6 +4327,7 @@ async function modulePreviewRouteHandler(request, response) {
4324
4327
  jsRenderingGates
4325
4328
  );
4326
4329
  const fullHeightCss = fullHeightPreview ? `<style>html,body{height:100%;width:100%;margin:0}#root{height:100%;width:100%}</style>` : "";
4330
+ const bodyHtml = sectionVariant ? `<div data-section-variant="${sectionVariant}">${renderedHtml}</div>` : renderedHtml;
4327
4331
  const html = addScriptInjectionBootstrapper(
4328
4332
  htmlShell.replace(
4329
4333
  "<!--headend-->",
@@ -4333,7 +4337,7 @@ async function modulePreviewRouteHandler(request, response) {
4333
4337
  cssNeeded,
4334
4338
  ...inlineAssets.map((inlineAsset) => inlineAsset.html)
4335
4339
  ].join("\n")
4336
- ).replace(`<!--ssr-outlet-->`, renderedHtml),
4340
+ ).replace(`<!--ssr-outlet-->`, bodyHtml),
4337
4341
  request.query
4338
4342
  );
4339
4343
  response.status(200).set({ "Content-Type": "text/html" }).end(html);
@@ -5427,6 +5431,7 @@ var fieldTypeNameByType = {
5427
5431
  textalignment: "TextAlignmentFieldType",
5428
5432
  text: "TextFieldType",
5429
5433
  url: "UrlFieldType",
5434
+ variantselection: "VariantSelectionFieldType",
5430
5435
  videoplayer: "VideoFieldType",
5431
5436
  workflow: "WorkflowFieldType"
5432
5437
  };
@@ -5542,7 +5547,7 @@ function getFieldTypes(fields) {
5542
5547
  if (field.children) {
5543
5548
  const childrenResult = getFieldTypes(field.children);
5544
5549
  imports.push(...childrenResult.imports);
5545
- if (childrenResult.types.length) {
5550
+ if (childrenResult.types.length || field.type === "GroupFieldType") {
5546
5551
  const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
5547
5552
  const { type: type2, imports: newImports2 } = buildTypeFromField(
5548
5553
  field,
@@ -73,7 +73,9 @@ var startHydratingIdleRootsTimeout;
73
73
  var shouldForceSeparateJsForAllIslands = /(&|\?)forceSeparateIslandJs=true/.test(window.location.search);
74
74
  var scheduledHydrationIndexCtr = 1;
75
75
  var rootsById = /* @__PURE__ */ new Map();
76
+ var rootsByElement = /* @__PURE__ */ new WeakMap();
76
77
  var scheduledElements = /* @__PURE__ */ new WeakSet();
78
+ var unmountedElements = /* @__PURE__ */ new WeakSet();
77
79
  var typedWindow = window;
78
80
  function findIslandElements(islandId) {
79
81
  if (typeof CSS !== "undefined" && CSS.escape) {
@@ -87,6 +89,18 @@ function findIslandElements(islandId) {
87
89
  document.querySelectorAll("[data-hs-island]")
88
90
  ).filter((el) => el.id === islandId);
89
91
  }
92
+ function findModuleWrapperElements(moduleId) {
93
+ if (typeof CSS !== "undefined" && CSS.escape) {
94
+ return Array.from(
95
+ document.querySelectorAll(
96
+ `[data-hs-module-id="${CSS.escape(moduleId)}"]`
97
+ )
98
+ );
99
+ }
100
+ return Array.from(
101
+ document.querySelectorAll("[data-hs-module-id]")
102
+ ).filter((el) => el.getAttribute("data-hs-module-id") === moduleId);
103
+ }
90
104
  function prepareAndScheduleRoot(root) {
91
105
  root.hydrationStatus = "HYDRATION_PREPARING";
92
106
  waitThenLoadAndHydrateIfNeeded(
@@ -150,8 +164,15 @@ function hydrateRoot(entry) {
150
164
  index: entry.islandScheduledIndex
151
165
  };
152
166
  const reactRoot = IslandModule.render(renderableIsland);
167
+ if (unmountedElements.has(rootEl)) {
168
+ unmountedElements.delete(rootEl);
169
+ reactRoot == null ? void 0 : reactRoot.unmount();
170
+ finishHydratingRootAndScheduleNext(entry);
171
+ return;
172
+ }
153
173
  const existingRoots = rootsById.get(root.id) || [];
154
174
  rootsById.set(root.id, [...existingRoots, reactRoot]);
175
+ rootsByElement.set(rootEl, reactRoot);
155
176
  }
156
177
  function pushToHydrationQueue(entry) {
157
178
  entry.root.hydrationStatus = "HYDRATION_QUEUED";
@@ -276,7 +297,41 @@ function unmountIsland(islandId) {
276
297
  reactRoot.unmount();
277
298
  }
278
299
  }
300
+ function unmountIslandsForModule(moduleId) {
301
+ const moduleEls = findModuleWrapperElements(moduleId);
302
+ if (moduleEls.length === 0) {
303
+ console.warn(`unmountIslandsForModule: No known module: ${moduleId}`);
304
+ return;
305
+ }
306
+ const islandEls = moduleEls.flatMap(
307
+ (moduleEl) => Array.from(moduleEl.querySelectorAll("[data-hs-island]"))
308
+ );
309
+ if (islandEls.length === 0) {
310
+ return;
311
+ }
312
+ console.log("Unmounting islands for module:", moduleId);
313
+ for (const el of islandEls) {
314
+ hydrationQueue = hydrationQueue.filter((entry) => entry.rootEl !== el);
315
+ scheduledElements.add(el);
316
+ unmountedElements.add(el);
317
+ const reactRoot = rootsByElement.get(el);
318
+ if (!reactRoot) {
319
+ continue;
320
+ }
321
+ rootsByElement.delete(el);
322
+ const remainingRoots = (rootsById.get(el.id) || []).filter(
323
+ (root) => root !== reactRoot
324
+ );
325
+ if (remainingRoots.length > 0) {
326
+ rootsById.set(el.id, remainingRoots);
327
+ } else {
328
+ rootsById.delete(el.id);
329
+ }
330
+ reactRoot.unmount();
331
+ }
332
+ }
279
333
  export {
280
334
  setupIslandHydration,
281
- unmountIsland
335
+ unmountIsland,
336
+ unmountIslandsForModule
282
337
  };
package/dist/run.js CHANGED
@@ -2255,7 +2255,7 @@ function trackUsage(action) {
2255
2255
  eventName: EVENT_NAME,
2256
2256
  action,
2257
2257
  nodeVersion: getNodeVersionData(),
2258
- version: "1.2.75",
2258
+ version: "1.2.77",
2259
2259
  os: getPlatform()
2260
2260
  };
2261
2261
  const url3 = isAuthedWithPersonalAccessKey ? DEV_SERVER_USAGE_ENDPOINT_AUTHENTICATED : DEV_SERVER_USAGE_ENDPOINT;
@@ -3697,6 +3697,7 @@ function extractRelevantCss(cssText) {
3697
3697
 
3698
3698
  // src/lib/renderModulePreview.ts
3699
3699
  import jsdom from "jsdom";
3700
+ var DEFAULT_SECTION_VARIANT = "section1";
3700
3701
  var _webDefaultStylesCss = null;
3701
3702
  function getWebDefaultStylesCss(metaUrl) {
3702
3703
  if (_webDefaultStylesCss === null) {
@@ -3949,6 +3950,7 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3949
3950
  const themeVariablesCss = filteredCss ? `<style data-hs-styles="theme-variables">${filteredCss}</style>` : "";
3950
3951
  const webDefaultStylesCss = meta.editor_version === "2.0" ? getWebDefaultStylesCss(import.meta.url) : "";
3951
3952
  const globalStylesCss = [themeVariablesCss, webDefaultStylesCss].filter(Boolean).join("\n");
3953
+ const sectionVariant = filteredCss ? DEFAULT_SECTION_VARIANT : void 0;
3952
3954
  const renderResult = await renderComponentForPlaceholder(
3953
3955
  0,
3954
3956
  localRenderPlaceholders[0],
@@ -3960,7 +3962,7 @@ async function renderLocalProjectModulePreview(moduleName, authedPortalId, authe
3960
3962
  projectName,
3961
3963
  projectComponentPath
3962
3964
  );
3963
- return { ...renderResult, globalStylesCss };
3965
+ return { ...renderResult, globalStylesCss, sectionVariant };
3964
3966
  }
3965
3967
 
3966
3968
  // src/routes/partial.ts
@@ -4901,7 +4903,8 @@ async function modulePreviewRouteHandler(request, response) {
4901
4903
  cssNeeded,
4902
4904
  renderContext,
4903
4905
  inlineAssets,
4904
- globalStylesCss
4906
+ globalStylesCss,
4907
+ sectionVariant
4905
4908
  } = await renderLocalProjectModulePreview(
4906
4909
  moduleName,
4907
4910
  authedPortalId,
@@ -4929,6 +4932,7 @@ async function modulePreviewRouteHandler(request, response) {
4929
4932
  jsRenderingGates
4930
4933
  );
4931
4934
  const fullHeightCss = fullHeightPreview ? `<style>html,body{height:100%;width:100%;margin:0}#root{height:100%;width:100%}</style>` : "";
4935
+ const bodyHtml = sectionVariant ? `<div data-section-variant="${sectionVariant}">${renderedHtml}</div>` : renderedHtml;
4932
4936
  const html = addScriptInjectionBootstrapper(
4933
4937
  htmlShell.replace(
4934
4938
  "<!--headend-->",
@@ -4938,7 +4942,7 @@ async function modulePreviewRouteHandler(request, response) {
4938
4942
  cssNeeded,
4939
4943
  ...inlineAssets.map((inlineAsset) => inlineAsset.html)
4940
4944
  ].join("\n")
4941
- ).replace(`<!--ssr-outlet-->`, renderedHtml),
4945
+ ).replace(`<!--ssr-outlet-->`, bodyHtml),
4942
4946
  request.query
4943
4947
  );
4944
4948
  response.status(200).set({ "Content-Type": "text/html" }).end(html);
@@ -6096,6 +6100,7 @@ var fieldTypeNameByType = {
6096
6100
  textalignment: "TextAlignmentFieldType",
6097
6101
  text: "TextFieldType",
6098
6102
  url: "UrlFieldType",
6103
+ variantselection: "VariantSelectionFieldType",
6099
6104
  videoplayer: "VideoFieldType",
6100
6105
  workflow: "WorkflowFieldType"
6101
6106
  };
@@ -6211,7 +6216,7 @@ function getFieldTypes(fields) {
6211
6216
  if (field.children) {
6212
6217
  const childrenResult = getFieldTypes(field.children);
6213
6218
  imports.push(...childrenResult.imports);
6214
- if (childrenResult.types.length) {
6219
+ if (childrenResult.types.length || field.type === "GroupFieldType") {
6215
6220
  const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
6216
6221
  const { type: type2, imports: newImports2 } = buildTypeFromField(
6217
6222
  field,
@@ -318,6 +318,7 @@ var fieldTypeNameByType = {
318
318
  textalignment: "TextAlignmentFieldType",
319
319
  text: "TextFieldType",
320
320
  url: "UrlFieldType",
321
+ variantselection: "VariantSelectionFieldType",
321
322
  videoplayer: "VideoFieldType",
322
323
  workflow: "WorkflowFieldType"
323
324
  };
@@ -433,7 +434,7 @@ function getFieldTypes(fields) {
433
434
  if (field.children) {
434
435
  const childrenResult = getFieldTypes(field.children);
435
436
  imports.push(...childrenResult.imports);
436
- if (childrenResult.types.length) {
437
+ if (childrenResult.types.length || field.type === "GroupFieldType") {
437
438
  const subType = ts.factory.createTypeLiteralNode(childrenResult.types);
438
439
  const { type: type2, imports: newImports2 } = buildTypeFromField(
439
440
  field,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hubspot/cms-dev-server",
3
- "version": "1.2.75",
3
+ "version": "1.2.77",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {
@@ -29,7 +29,7 @@
29
29
  "@babel/parser": "^7.25.3",
30
30
  "@babel/traverse": "^7.25.3",
31
31
  "@babel/types": "^7.25.2",
32
- "@hubspot/cms-components": "^1.2.75",
32
+ "@hubspot/cms-components": "^1.2.77",
33
33
  "@hubspot/local-dev-lib": "5.10.1",
34
34
  "@inquirer/select": "^2.0.0",
35
35
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -1,4 +1,5 @@
1
1
  import { Gate } from '@hubspot/cms-js-internal';
2
+ export declare const DEFAULT_SECTION_VARIANT = "section1";
2
3
  export declare function signGetUrl(authedPortalId: number, unsignedUrl: string): Promise<string>;
3
4
  export declare function signedGet(authedPortalId: number, unsignedUrl: string, headers: Record<string, string>, gates: Gate[]): Promise<string>;
4
5
  export declare function renderRemoteModulePreview(modulePath: string, authedPortalId: any, authedEnv: any, cookieValue: any, gates: Gate[]): Promise<{
@@ -8,6 +9,7 @@ export declare function renderRemoteModulePreview(modulePath: string, authedPort
8
9
  export declare function signUrl(authedPortalId: number, unsignedUrl: string, requestBody: any): Promise<string>;
9
10
  export declare function renderLocalProjectModulePreview(moduleName: string, authedPortalId: any, authedEnv: any, authedHublet: any, webRoot: any, viteServer: any, jsRenderingGates: any, projectName: any, projectComponentPath: any, fullOriginalUrl: any, cookieValue: any, fieldOverrides?: {}): Promise<{
10
11
  globalStylesCss: string;
12
+ sectionVariant: string;
11
13
  html: string;
12
14
  inlineAssets?: import("@hubspot/cms-js-internal").InlineAsset[];
13
15
  cssNeeded: string;
@@ -1,8 +0,0 @@
1
- export declare function debugAuthContext(
2
- authedPortalId: number,
3
- cookieValue: string
4
- ): Promise<void>;
5
- export declare function compareUrls(
6
- originalUrl: string,
7
- signedUrl: string
8
- ): void;
@@ -1,2 +0,0 @@
1
- export declare function getLocalComponentsPath(): string;
2
- export declare function shouldUseLocalComponents(): boolean;
@@ -1,18 +0,0 @@
1
- import { ViteDevServer } from 'vite';
2
- /**
3
- * Processes HTML to find remote assets and replace with Vite-managed URLs
4
- */
5
- export declare function processRemoteAssets(
6
- html: string,
7
- viteServer: ViteDevServer
8
- ): Promise<string>;
9
- /**
10
- * Vite plugin to handle remote assets
11
- */
12
- export declare function remoteAssetsPlugin(): {
13
- name: string;
14
- apply: 'serve';
15
- configResolved(config: any): void;
16
- resolveId(id: string): string;
17
- load(id: string): Promise<string>;
18
- };
@@ -1,2 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- export declare function hubspotStaticAssetsPlugin(): Plugin;
@@ -1,10 +0,0 @@
1
- import { ViteDevServer, Plugin } from 'vite';
2
- /**
3
- * Create a self-contained plugin with proper caching
4
- */
5
- export declare function remoteAssetsPlugin(): Plugin & {
6
- processRemoteAssets: (
7
- html: string,
8
- viteServer: ViteDevServer
9
- ) => Promise<string>;
10
- };
@@ -1,6 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- /**
3
- * Plugin that provides URL signing capabilities
4
- * Uses internal signing mechanisms when available, with fallback for public environments
5
- */
6
- export default function requestSigningPlugin(): Plugin;
@@ -1,13 +0,0 @@
1
- import { Request, Response, NextFunction } from 'express';
2
- export declare function handleGetModulePages(
3
- req: Request,
4
- res: Response,
5
- next: NextFunction
6
- ): Promise<Response<any, Record<string, any>>>;
7
- export declare function handleOpenFile(
8
- req: Request,
9
- res: Response,
10
- next: NextFunction
11
- ): Response<any, Record<string, any>>;
12
- export declare function createAppServerRoutes(): import('express-serve-static-core').Router;
13
- export default createAppServerRoutes;
@@ -1,7 +0,0 @@
1
- import { Request, Response } from 'express';
2
- declare const homeRouteHandler: (
3
- request: Request,
4
- response: Response,
5
- next: Function
6
- ) => Promise<void>;
7
- export default homeRouteHandler;