@constela/start 1.2.16 → 1.2.17
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.
|
@@ -2462,8 +2462,25 @@ async function loadLayout2(layoutName, layoutsDir) {
|
|
|
2462
2462
|
throw new Error(`Invalid JSON in layout file: ${layoutPath}`);
|
|
2463
2463
|
}
|
|
2464
2464
|
}
|
|
2465
|
-
function applyLayout(pageView, layoutView) {
|
|
2466
|
-
return replaceSlot(layoutView, pageView);
|
|
2465
|
+
function applyLayout(pageView, layoutView, namedSlots) {
|
|
2466
|
+
return replaceSlot(layoutView, pageView, namedSlots);
|
|
2467
|
+
}
|
|
2468
|
+
function extractMdxContentSlot2(loadedData, dataSourceName, routeParams) {
|
|
2469
|
+
const dataSource = loadedData[dataSourceName];
|
|
2470
|
+
if (!Array.isArray(dataSource)) {
|
|
2471
|
+
return void 0;
|
|
2472
|
+
}
|
|
2473
|
+
const slug = routeParams["slug"] || "index";
|
|
2474
|
+
const item = dataSource.find(
|
|
2475
|
+
(entry) => typeof entry === "object" && entry !== null && "slug" in entry && entry.slug === slug
|
|
2476
|
+
);
|
|
2477
|
+
if (!item || typeof item !== "object" || !("content" in item)) {
|
|
2478
|
+
return void 0;
|
|
2479
|
+
}
|
|
2480
|
+
return { "mdx-content": item.content };
|
|
2481
|
+
}
|
|
2482
|
+
function isEventHandler(value) {
|
|
2483
|
+
return typeof value === "object" && value !== null && "event" in value && typeof value.event === "string" && "action" in value && typeof value.action === "string";
|
|
2467
2484
|
}
|
|
2468
2485
|
function normalizeProps(props) {
|
|
2469
2486
|
if (!props || typeof props !== "object") {
|
|
@@ -2473,6 +2490,8 @@ function normalizeProps(props) {
|
|
|
2473
2490
|
for (const [key, value] of Object.entries(props)) {
|
|
2474
2491
|
if (value && typeof value === "object" && "expr" in value) {
|
|
2475
2492
|
normalized[key] = value;
|
|
2493
|
+
} else if (isEventHandler(value)) {
|
|
2494
|
+
normalized[key] = value;
|
|
2476
2495
|
} else if (value !== void 0 && value !== null) {
|
|
2477
2496
|
normalized[key] = { expr: "lit", value };
|
|
2478
2497
|
}
|
|
@@ -2579,18 +2598,25 @@ function substituteLayoutParamsInNode(node, layoutParams) {
|
|
|
2579
2598
|
}
|
|
2580
2599
|
return result;
|
|
2581
2600
|
}
|
|
2582
|
-
function replaceSlot(node, content) {
|
|
2601
|
+
function replaceSlot(node, content, namedSlots) {
|
|
2583
2602
|
if (!node || typeof node !== "object") {
|
|
2584
2603
|
return node;
|
|
2585
2604
|
}
|
|
2586
2605
|
const nodeObj = node;
|
|
2587
2606
|
if (nodeObj["kind"] === "slot") {
|
|
2588
|
-
|
|
2607
|
+
const slotName = nodeObj["name"];
|
|
2608
|
+
if (slotName && namedSlots && slotName in namedSlots) {
|
|
2609
|
+
return namedSlots[slotName];
|
|
2610
|
+
}
|
|
2611
|
+
if (!slotName || slotName === "default") {
|
|
2612
|
+
return content;
|
|
2613
|
+
}
|
|
2614
|
+
return node;
|
|
2589
2615
|
}
|
|
2590
2616
|
if (Array.isArray(nodeObj["children"])) {
|
|
2591
2617
|
return {
|
|
2592
2618
|
...nodeObj,
|
|
2593
|
-
children: nodeObj["children"].map((child) => replaceSlot(child, content))
|
|
2619
|
+
children: nodeObj["children"].map((child) => replaceSlot(child, content, namedSlots))
|
|
2594
2620
|
};
|
|
2595
2621
|
}
|
|
2596
2622
|
return node;
|
|
@@ -2608,7 +2634,7 @@ async function collectLayoutChain(layoutName, layoutsDir, visited = /* @__PURE__
|
|
|
2608
2634
|
}
|
|
2609
2635
|
return chain;
|
|
2610
2636
|
}
|
|
2611
|
-
async function processLayouts(pageInfo, layoutsDir) {
|
|
2637
|
+
async function processLayouts(pageInfo, layoutsDir, routeParams = {}) {
|
|
2612
2638
|
const layoutName = pageInfo.page.route?.layout;
|
|
2613
2639
|
if (!layoutName || !layoutsDir) {
|
|
2614
2640
|
return pageInfo;
|
|
@@ -2625,10 +2651,55 @@ async function processLayouts(pageInfo, layoutsDir) {
|
|
|
2625
2651
|
};
|
|
2626
2652
|
}
|
|
2627
2653
|
}
|
|
2654
|
+
let namedSlots;
|
|
2655
|
+
let effectiveRouteParams = routeParams;
|
|
2656
|
+
if (!routeParams["slug"] && pageInfo.page.route?.path) {
|
|
2657
|
+
const pathSegments = pageInfo.page.route.path.split("/").filter(Boolean);
|
|
2658
|
+
const lastSegment = pathSegments[pathSegments.length - 1];
|
|
2659
|
+
if (lastSegment && !lastSegment.startsWith(":")) {
|
|
2660
|
+
effectiveRouteParams = { ...routeParams, slug: lastSegment };
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
if (pageInfo.loadedData && Object.keys(pageInfo.loadedData).length > 0) {
|
|
2664
|
+
for (const dataSourceName of Object.keys(pageInfo.loadedData)) {
|
|
2665
|
+
const slots = extractMdxContentSlot2(pageInfo.loadedData, dataSourceName, effectiveRouteParams);
|
|
2666
|
+
if (slots) {
|
|
2667
|
+
namedSlots = namedSlots ? { ...namedSlots, ...slots } : slots;
|
|
2668
|
+
break;
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
if (!namedSlots && pageInfo.resolvedImports && Object.keys(pageInfo.resolvedImports).length > 0) {
|
|
2673
|
+
for (const importName of Object.keys(pageInfo.resolvedImports)) {
|
|
2674
|
+
const slots = extractMdxContentSlot2(
|
|
2675
|
+
pageInfo.resolvedImports,
|
|
2676
|
+
importName,
|
|
2677
|
+
effectiveRouteParams
|
|
2678
|
+
);
|
|
2679
|
+
if (slots) {
|
|
2680
|
+
namedSlots = slots;
|
|
2681
|
+
break;
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
const pageWithImportData = pageInfo.page;
|
|
2686
|
+
if (!namedSlots && pageWithImportData.importData && Object.keys(pageWithImportData.importData).length > 0) {
|
|
2687
|
+
for (const importName of Object.keys(pageWithImportData.importData)) {
|
|
2688
|
+
const slots = extractMdxContentSlot2(
|
|
2689
|
+
pageWithImportData.importData,
|
|
2690
|
+
importName,
|
|
2691
|
+
effectiveRouteParams
|
|
2692
|
+
);
|
|
2693
|
+
if (slots) {
|
|
2694
|
+
namedSlots = slots;
|
|
2695
|
+
break;
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2628
2699
|
let currentView = pageInfo.page.view;
|
|
2629
2700
|
for (const layout of layoutChain) {
|
|
2630
2701
|
const normalizedLayoutView = normalizeViewNode(structuredClone(layout.view));
|
|
2631
|
-
currentView = applyLayout(currentView, normalizedLayoutView);
|
|
2702
|
+
currentView = applyLayout(currentView, normalizedLayoutView, namedSlots);
|
|
2632
2703
|
}
|
|
2633
2704
|
const layoutParams = pageInfo.page.route?.layoutParams;
|
|
2634
2705
|
if (layoutParams && Object.keys(layoutParams).length > 0) {
|
|
@@ -2773,13 +2844,14 @@ async function build2(options) {
|
|
|
2773
2844
|
if (!staticPathsResult || staticPathsResult.length === 0) {
|
|
2774
2845
|
continue;
|
|
2775
2846
|
}
|
|
2776
|
-
if (layoutsDir) {
|
|
2777
|
-
pageInfo = await processLayouts(pageInfo, layoutsDir);
|
|
2778
|
-
}
|
|
2779
2847
|
for (const pathEntry of staticPathsResult) {
|
|
2780
2848
|
const params = pathEntry.params;
|
|
2781
2849
|
const outputPath = paramsToOutputPath(route.pattern, params, outDir);
|
|
2782
|
-
|
|
2850
|
+
let processedPageInfo = pageInfo;
|
|
2851
|
+
if (layoutsDir) {
|
|
2852
|
+
processedPageInfo = await processLayouts(pageInfo, layoutsDir, params);
|
|
2853
|
+
}
|
|
2854
|
+
const program = await convertToCompiledProgram(processedPageInfo);
|
|
2783
2855
|
const html = await renderPageToHtml(program, params, runtimePath, cssPath);
|
|
2784
2856
|
await mkdir2(dirname5(outputPath), { recursive: true });
|
|
2785
2857
|
await writeFile(outputPath, html, "utf-8");
|
|
@@ -2792,11 +2864,22 @@ async function build2(options) {
|
|
|
2792
2864
|
routes.push(routePath);
|
|
2793
2865
|
}
|
|
2794
2866
|
} else {
|
|
2795
|
-
const outputPath = getOutputPath(relPathFromRoutesDir, outDir);
|
|
2796
2867
|
const loader = new JsonPageLoader(projectRoot, { routesDir: absoluteRoutesDir });
|
|
2797
2868
|
let pageInfo = await loader.loadPage(relPathFromProjectRoot);
|
|
2869
|
+
let outputPath;
|
|
2870
|
+
if (pageInfo.page.route?.path) {
|
|
2871
|
+
const routePath = pageInfo.page.route.path;
|
|
2872
|
+
const relativePath = routePath.startsWith("/") ? routePath.slice(1) : routePath;
|
|
2873
|
+
if (relativePath === "" || relativePath === "/") {
|
|
2874
|
+
outputPath = join9(outDir, "index.html");
|
|
2875
|
+
} else {
|
|
2876
|
+
outputPath = join9(outDir, relativePath, "index.html");
|
|
2877
|
+
}
|
|
2878
|
+
} else {
|
|
2879
|
+
outputPath = getOutputPath(relPathFromRoutesDir, outDir);
|
|
2880
|
+
}
|
|
2798
2881
|
if (layoutsDir) {
|
|
2799
|
-
pageInfo = await processLayouts(pageInfo, layoutsDir);
|
|
2882
|
+
pageInfo = await processLayouts(pageInfo, layoutsDir, {});
|
|
2800
2883
|
}
|
|
2801
2884
|
const program = await convertToCompiledProgram(pageInfo);
|
|
2802
2885
|
const html = await renderPageToHtml(program, {}, runtimePath, cssPath);
|
package/dist/cli/index.js
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/start",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.17",
|
|
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",
|
|
47
46
|
"@constela/core": "0.7.0",
|
|
47
|
+
"@constela/runtime": "0.10.2",
|
|
48
48
|
"@constela/router": "8.0.0",
|
|
49
|
-
"@constela/
|
|
50
|
-
"@constela/
|
|
49
|
+
"@constela/compiler": "0.7.1",
|
|
50
|
+
"@constela/server": "3.0.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/mdast": "^4.0.4",
|