@stencil/dev-server 5.0.0-alpha.30 → 5.0.0-alpha.32

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.
Files changed (2) hide show
  1. package/dist/index.mjs +29 -5
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -544,8 +544,11 @@ const generateDevPreview = (buildResults, filterDirPath) => {
544
544
  h1 { font-size: 1rem; font-weight: 500; margin: 0 0 2rem; color: color-mix(in oklab, CanvasText 90%, Canvas 10%); }
545
545
  .component { border: 1px solid color-mix(in oklab, CanvasText 20%, Canvas 80%); border-radius: 6px; margin-bottom: 1.5rem; overflow: hidden; }
546
546
  .component-header { padding: 0.5rem 1rem; background: color-mix(in oklab, CanvasText 5%, Canvas 95%); font-family: monospace; font-size: 0.875rem; }
547
+ .component-description { margin: 0; padding: 0.75rem 1rem 0; font-size: 0.875rem; color: color-mix(in oklab, CanvasText 70%, Canvas 30%); }
547
548
  .component-preview { padding: 1.5rem; }
548
549
  .component-preview + .component-preview { border-top: 1px dashed color-mix(in oklab, CanvasText 20%, Canvas 80%); }
550
+ .preview-note { margin: 0.75rem 0 0; font-size: 0.8125rem; color: color-mix(in oklab, CanvasText 50%, Canvas 50%); }
551
+ .preview-note code { font-size: 0.8125rem; }
549
552
  </style>
550
553
  ${[loaderUrl ? ` <script type="module" src="${loaderUrl}"><\/script>` : "", ...globalCssUrls.map((url) => ` <link rel="stylesheet" href="${url}">`)].filter(Boolean).join("\n")}
551
554
  </head>
@@ -557,12 +560,17 @@ ${sections.join("\n")}
557
560
  };
558
561
  const renderComponentSection = (component) => {
559
562
  const snippets = getUsageSnippets(component);
560
- const previews = snippets.length > 0 ? snippets.map((html) => ` <div class="component-preview">\n ${html}\n </div>`).join("\n") : ` <div class="component-preview"><${component.tagName}></${component.tagName}></div>`;
563
+ const previews = snippets.length > 0 ? snippets.map((html) => ` <div class="component-preview">\n ${html}\n </div>`).join("\n") : ` <div class="component-preview">
564
+ <${component.tagName}></${component.tagName}>
565
+ <p class="preview-note">No demos found - add usage examples to <code>usage/*.md</code> (fenced &#96;&#96;&#96;html&#96;&#96;&#96; blocks) to customize this preview.</p>
566
+ </div>`;
567
+ const description = component.docs.text.trim() ? `\n <p class="component-description">${escapeHtml(component.docs.text.trim())}</p>` : "";
561
568
  return ` <div class="component">
562
- <div class="component-header">&lt;${component.tagName}&gt;</div>
569
+ <div class="component-header">&lt;${component.tagName}&gt;</div>${description}
563
570
  ${previews}
564
571
  </div>`;
565
572
  };
573
+ const escapeHtml = (unsafe) => unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
566
574
  const getUsageSnippets = (component) => {
567
575
  const usageDir = path.join(path.dirname(component.sourceFilePath), "usage");
568
576
  try {
@@ -1053,9 +1061,7 @@ async function serveDirectoryIndex(devServerConfig, serverCtx, req, res) {
1053
1061
  if (!req.pathname.endsWith("/")) return serverCtx.serve302(req, res, req.pathname + "/");
1054
1062
  try {
1055
1063
  const dirFilePaths = await serverCtx.sys.readDir(req.filePath);
1056
- const hasTsx = dirFilePaths.some((f) => f.endsWith(".tsx"));
1057
- const hasHtml = dirFilePaths.some((f) => f.endsWith(".html") || f.endsWith(".htm"));
1058
- if (hasTsx && !hasHtml) return serveDevPreview(devServerConfig, serverCtx, req, res, req.filePath);
1064
+ if (dirFilePaths.some((f) => f.endsWith(".tsx")) && !await hasNestedHtmlFile(serverCtx.sys, dirFilePaths)) return serveDevPreview(devServerConfig, serverCtx, req, res, req.filePath);
1059
1065
  if (req.pathname === "/" || req.pathname === devServerConfig.basePath) {
1060
1066
  const srcPath = path.join(req.filePath, "src");
1061
1067
  try {
@@ -1083,6 +1089,24 @@ async function serveDirectoryIndex(devServerConfig, serverCtx, req, res) {
1083
1089
  return serverCtx.serve404(req, res, "serveDirectoryIndex");
1084
1090
  }
1085
1091
  }
1092
+ /**
1093
+ * Recursively checks a directory (and its subdirectories) for any .html/.htm file.
1094
+ * Used to decide whether the auto-generated component preview should be shown, or
1095
+ * the default file-listing view (since a nested html file likely means a custom
1096
+ * preview/demo page already exists somewhere in the tree).
1097
+ * @param sys The dev server's compiler system, used to read directories and stat files.
1098
+ * @param dirFilePaths The full paths of entries in the directory to check.
1099
+ * @returns true if an html file exists at this level or in any subdirectory.
1100
+ */
1101
+ async function hasNestedHtmlFile(sys, dirFilePaths) {
1102
+ const subDirPaths = [];
1103
+ for (const filePath of dirFilePaths) {
1104
+ if (filePath.endsWith(".html") || filePath.endsWith(".htm")) return true;
1105
+ if ((await sys.stat(filePath)).isDirectory) subDirPaths.push(filePath);
1106
+ }
1107
+ for (const subDirPath of subDirPaths) if (await hasNestedHtmlFile(sys, await sys.readDir(subDirPath))) return true;
1108
+ return false;
1109
+ }
1086
1110
  async function serveDevPreview(devServerConfig, serverCtx, req, res, filterDirPath) {
1087
1111
  try {
1088
1112
  const buildResults = await serverCtx.getBuildResults();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/dev-server",
3
- "version": "5.0.0-alpha.30",
3
+ "version": "5.0.0-alpha.32",
4
4
  "description": "Development server for Stencil with DOM-based HMR",
5
5
  "keywords": [
6
6
  "dev server",
@@ -46,10 +46,10 @@
46
46
  "typescript": ">5.0.0 <7.0.0",
47
47
  "vitest": "^4.1.10",
48
48
  "vitest-environment-stencil": "^1.14.0",
49
- "@stencil/core": "5.0.0-alpha.30"
49
+ "@stencil/core": "5.0.0-alpha.32"
50
50
  },
51
51
  "peerDependencies": {
52
- "@stencil/core": "^5.0.0 || 5.0.0-alpha.30"
52
+ "@stencil/core": "^5.0.0 || 5.0.0-alpha.32"
53
53
  },
54
54
  "volta": {
55
55
  "extends": "../../package.json"