@constela/start 1.2.17 → 1.2.19

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.
@@ -82,6 +82,13 @@ function wrapHtml(content, hydrationScript, head, options) {
82
82
  /from\s+['"]@constela\/runtime['"]/g,
83
83
  `from '${options.runtimePath}'`
84
84
  );
85
+ if (options?.importMap && Object.keys(options.importMap).length > 0) {
86
+ const importMapJson = JSON.stringify({ imports: options.importMap }, null, 2);
87
+ importMapScript = `<script type="importmap">
88
+ ${importMapJson}
89
+ </script>
90
+ `;
91
+ }
85
92
  } else if (options?.importMap && Object.keys(options.importMap).length > 0) {
86
93
  const importMapJson = JSON.stringify({ imports: options.importMap }, null, 2);
87
94
  importMapScript = `<script type="importmap">
@@ -2,7 +2,7 @@ import {
2
2
  generateHydrationScript,
3
3
  renderPage,
4
4
  wrapHtml
5
- } from "./chunk-PUTC5BCP.js";
5
+ } from "./chunk-7YAQ4TPR.js";
6
6
 
7
7
  // src/router/file-router.ts
8
8
  import fg from "fast-glob";
@@ -2467,6 +2467,12 @@ function applyLayout(pageView, layoutView, namedSlots) {
2467
2467
  }
2468
2468
  function extractMdxContentSlot2(loadedData, dataSourceName, routeParams) {
2469
2469
  const dataSource = loadedData[dataSourceName];
2470
+ if (dataSource && typeof dataSource === "object" && !Array.isArray(dataSource)) {
2471
+ if ("content" in dataSource) {
2472
+ return { "mdx-content": dataSource.content };
2473
+ }
2474
+ return void 0;
2475
+ }
2470
2476
  if (!Array.isArray(dataSource)) {
2471
2477
  return void 0;
2472
2478
  }
@@ -2651,6 +2657,55 @@ async function processLayouts(pageInfo, layoutsDir, routeParams = {}) {
2651
2657
  };
2652
2658
  }
2653
2659
  }
2660
+ let mergedState = {};
2661
+ for (let i = layoutChain.length - 1; i >= 0; i--) {
2662
+ const layout = layoutChain[i];
2663
+ if (layout?.state) {
2664
+ mergedState = {
2665
+ ...mergedState,
2666
+ ...layout.state
2667
+ };
2668
+ }
2669
+ }
2670
+ if (pageInfo.page.state) {
2671
+ mergedState = {
2672
+ ...mergedState,
2673
+ ...pageInfo.page.state
2674
+ };
2675
+ }
2676
+ let mergedActionsMap = /* @__PURE__ */ new Map();
2677
+ for (let i = layoutChain.length - 1; i >= 0; i--) {
2678
+ const layout = layoutChain[i];
2679
+ if (layout?.actions && Array.isArray(layout.actions)) {
2680
+ for (const action of layout.actions) {
2681
+ const actionDef = action;
2682
+ mergedActionsMap.set(actionDef.name, action);
2683
+ }
2684
+ }
2685
+ }
2686
+ if (pageInfo.page.actions && Array.isArray(pageInfo.page.actions)) {
2687
+ for (const action of pageInfo.page.actions) {
2688
+ const actionDef = action;
2689
+ mergedActionsMap.set(actionDef.name, action);
2690
+ }
2691
+ }
2692
+ const mergedActions = Array.from(mergedActionsMap.values());
2693
+ let mergedLifecycle;
2694
+ for (let i = layoutChain.length - 1; i >= 0; i--) {
2695
+ const layout = layoutChain[i];
2696
+ if (layout?.lifecycle) {
2697
+ mergedLifecycle = {
2698
+ ...mergedLifecycle,
2699
+ ...layout.lifecycle
2700
+ };
2701
+ }
2702
+ }
2703
+ if (pageInfo.page.lifecycle) {
2704
+ mergedLifecycle = {
2705
+ ...mergedLifecycle,
2706
+ ...pageInfo.page.lifecycle
2707
+ };
2708
+ }
2654
2709
  let namedSlots;
2655
2710
  let effectiveRouteParams = routeParams;
2656
2711
  if (!routeParams["slug"] && pageInfo.page.route?.path) {
@@ -2701,6 +2756,9 @@ async function processLayouts(pageInfo, layoutsDir, routeParams = {}) {
2701
2756
  const normalizedLayoutView = normalizeViewNode(structuredClone(layout.view));
2702
2757
  currentView = applyLayout(currentView, normalizedLayoutView, namedSlots);
2703
2758
  }
2759
+ if (namedSlots && Object.keys(namedSlots).length > 0) {
2760
+ currentView = replaceSlot(currentView, currentView, namedSlots);
2761
+ }
2704
2762
  const layoutParams = pageInfo.page.route?.layoutParams;
2705
2763
  if (layoutParams && Object.keys(layoutParams).length > 0) {
2706
2764
  currentView = substituteLayoutParamsInNode(currentView, layoutParams);
@@ -2716,12 +2774,15 @@ async function processLayouts(pageInfo, layoutsDir, routeParams = {}) {
2716
2774
  page: {
2717
2775
  ...pageInfo.page,
2718
2776
  view: currentView,
2719
- route: updatedRoute
2777
+ route: updatedRoute,
2778
+ state: Object.keys(mergedState).length > 0 ? mergedState : void 0,
2779
+ actions: mergedActions.length > 0 ? mergedActions : void 0,
2780
+ lifecycle: mergedLifecycle
2720
2781
  }
2721
2782
  };
2722
2783
  return updatedPageInfo;
2723
2784
  }
2724
- async function renderPageToHtml(program, params, runtimePath, cssPath) {
2785
+ async function renderPageToHtml(program, params, runtimePath, cssPath, externalImports) {
2725
2786
  const normalizedProgram = {
2726
2787
  ...program,
2727
2788
  view: normalizeViewNode(structuredClone(program.view))
@@ -2739,7 +2800,19 @@ async function renderPageToHtml(program, params, runtimePath, cssPath) {
2739
2800
  };
2740
2801
  const cssLinkTag = cssPath ? `<link rel="stylesheet" href="${cssPath}">` : void 0;
2741
2802
  const hydrationScript = generateHydrationScript(normalizedProgram, void 0, routeContext);
2742
- return wrapHtml(content, hydrationScript, cssLinkTag, runtimePath ? { runtimePath } : void 0);
2803
+ const wrapOptions = {};
2804
+ if (runtimePath) {
2805
+ wrapOptions.runtimePath = runtimePath;
2806
+ }
2807
+ if (externalImports && Object.keys(externalImports).length > 0) {
2808
+ wrapOptions.importMap = externalImports;
2809
+ }
2810
+ return wrapHtml(
2811
+ content,
2812
+ hydrationScript,
2813
+ cssLinkTag,
2814
+ Object.keys(wrapOptions).length > 0 ? wrapOptions : void 0
2815
+ );
2743
2816
  }
2744
2817
  async function copyPublicDir(publicDir, outDir, generatedFiles) {
2745
2818
  if (!existsSync8(publicDir)) {
@@ -2847,15 +2920,39 @@ async function build2(options) {
2847
2920
  for (const pathEntry of staticPathsResult) {
2848
2921
  const params = pathEntry.params;
2849
2922
  const outputPath = paramsToOutputPath(route.pattern, params, outDir);
2850
- let processedPageInfo = pageInfo;
2923
+ let boundPageInfo = pageInfo;
2924
+ if (pathEntry.data && pageInfo.page.getStaticPaths?.source) {
2925
+ const source = pageInfo.page.getStaticPaths.source;
2926
+ const sourceName = typeof source === "string" ? source : source.name;
2927
+ if (sourceName) {
2928
+ boundPageInfo = {
2929
+ ...pageInfo,
2930
+ loadedData: {
2931
+ ...pageInfo.loadedData,
2932
+ [sourceName]: pathEntry.data
2933
+ // Replace array with current item
2934
+ }
2935
+ };
2936
+ }
2937
+ }
2938
+ let processedPageInfo = boundPageInfo;
2851
2939
  if (layoutsDir) {
2852
- processedPageInfo = await processLayouts(pageInfo, layoutsDir, params);
2940
+ processedPageInfo = await processLayouts(boundPageInfo, layoutsDir, params);
2853
2941
  }
2854
2942
  const program = await convertToCompiledProgram(processedPageInfo);
2855
- const html = await renderPageToHtml(program, params, runtimePath, cssPath);
2943
+ const html = await renderPageToHtml(program, params, runtimePath, cssPath, processedPageInfo.page.externalImports);
2856
2944
  await mkdir2(dirname5(outputPath), { recursive: true });
2857
2945
  await writeFile(outputPath, html, "utf-8");
2858
2946
  generatedFiles.push(outputPath);
2947
+ const slugValue = params["slug"];
2948
+ if (slugValue && (slugValue === "index" || slugValue.endsWith("/index"))) {
2949
+ const parentOutputPath = join9(dirname5(dirname5(outputPath)), "index.html");
2950
+ if (!generatedFiles.includes(parentOutputPath)) {
2951
+ await mkdir2(dirname5(parentOutputPath), { recursive: true });
2952
+ await writeFile(parentOutputPath, html, "utf-8");
2953
+ generatedFiles.push(parentOutputPath);
2954
+ }
2955
+ }
2859
2956
  let routePath = route.pattern;
2860
2957
  for (const [key, value] of Object.entries(params)) {
2861
2958
  routePath = routePath.replace(`:${key}`, value);
@@ -2882,7 +2979,7 @@ async function build2(options) {
2882
2979
  pageInfo = await processLayouts(pageInfo, layoutsDir, {});
2883
2980
  }
2884
2981
  const program = await convertToCompiledProgram(pageInfo);
2885
- const html = await renderPageToHtml(program, {}, runtimePath, cssPath);
2982
+ const html = await renderPageToHtml(program, {}, runtimePath, cssPath, pageInfo.page.externalImports);
2886
2983
  await mkdir2(dirname5(outputPath), { recursive: true });
2887
2984
  await writeFile(outputPath, html, "utf-8");
2888
2985
  generatedFiles.push(outputPath);
package/dist/cli/index.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  createDevServer,
4
4
  loadConfig,
5
5
  resolveConfig
6
- } from "../chunk-CRQMVEYP.js";
7
- import "../chunk-PUTC5BCP.js";
6
+ } from "../chunk-JOQOX3XZ.js";
7
+ import "../chunk-7YAQ4TPR.js";
8
8
 
9
9
  // src/cli/index.ts
10
10
  import { Command } from "commander";
package/dist/index.js CHANGED
@@ -23,12 +23,12 @@ import {
23
23
  transformCsv,
24
24
  transformMdx,
25
25
  transformYaml
26
- } from "./chunk-CRQMVEYP.js";
26
+ } from "./chunk-JOQOX3XZ.js";
27
27
  import {
28
28
  generateHydrationScript,
29
29
  renderPage,
30
30
  wrapHtml
31
- } from "./chunk-PUTC5BCP.js";
31
+ } from "./chunk-7YAQ4TPR.js";
32
32
 
33
33
  // src/build/ssg.ts
34
34
  import { mkdir, writeFile } from "fs/promises";
@@ -2,7 +2,7 @@ import {
2
2
  generateHydrationScript,
3
3
  renderPage,
4
4
  wrapHtml
5
- } from "../chunk-PUTC5BCP.js";
5
+ } from "../chunk-7YAQ4TPR.js";
6
6
  export {
7
7
  generateHydrationScript,
8
8
  renderPage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/start",
3
- "version": "1.2.17",
3
+ "version": "1.2.19",
4
4
  "description": "Meta-framework for Constela applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -43,11 +43,11 @@
43
43
  "postcss": "^8.5.0",
44
44
  "@tailwindcss/postcss": "^4.0.0",
45
45
  "tailwindcss": "^4.0.0",
46
+ "@constela/compiler": "0.7.1",
46
47
  "@constela/core": "0.7.0",
47
- "@constela/runtime": "0.10.2",
48
48
  "@constela/router": "8.0.0",
49
- "@constela/compiler": "0.7.1",
50
- "@constela/server": "3.0.1"
49
+ "@constela/server": "3.0.1",
50
+ "@constela/runtime": "0.10.2"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/mdast": "^4.0.4",