Comparing version 1.0.0-alpha.11 to 1.0.0-alpha.12
@@ -22,3 +22,3 @@ import { BlockContent, Code, DefinitionContent } from "mdast"; | ||
type: "section"; | ||
query: string; | ||
title: string; | ||
depth: number; | ||
@@ -25,0 +25,0 @@ parent: HikeSection | null; |
import { readFile } from "./code/extract-annotations.js"; | ||
const DEFAULT_BLOCKS_NAME = "blocks"; | ||
const DEFAULT_CODE_NAME = "code"; | ||
const DEFAULT_IMAGES_NAME = "image"; | ||
const DEFAULT_VALUE_NAME = "value"; | ||
export async function listToSection(hikeElement, mdxPath) { | ||
@@ -12,3 +16,3 @@ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; | ||
depth: 0, | ||
query: "", | ||
title: "", | ||
parent: null, | ||
@@ -26,3 +30,3 @@ children: [], | ||
} | ||
const { name, query, multi } = parseHeading(child); | ||
const { name, title, multi } = parseHeading(child); | ||
const section = { | ||
@@ -36,3 +40,3 @@ type: "section", | ||
name, | ||
query, | ||
title, | ||
multi, | ||
@@ -55,3 +59,3 @@ index: !multi | ||
else if (child.type === "code" && ((_g = child.meta) === null || _g === void 0 ? void 0 : _g.trim().startsWith("!"))) { | ||
const { name = "code", multi, query } = parseName(child.meta || ""); | ||
const { name = DEFAULT_CODE_NAME, multi, title, } = parseName(child.meta || ""); | ||
const value = await parseCodeValue(child, mdxPath); | ||
@@ -67,3 +71,3 @@ parent.children.push({ | ||
lang: child.lang, | ||
meta: query, | ||
meta: title, | ||
// parentPath: mdxPath, | ||
@@ -73,3 +77,3 @@ }); | ||
else if ( | ||
//  | ||
//  | ||
child.type === "paragraph" && | ||
@@ -80,3 +84,3 @@ child.children.length === 1 && | ||
const img = child.children[0]; | ||
const { name = "image", query, multi } = parseName(img.alt || ""); | ||
const { name = DEFAULT_IMAGES_NAME, title, multi, } = parseName(img.alt || ""); | ||
parent.children.push({ | ||
@@ -89,3 +93,3 @@ type: "image", | ||
: undefined, | ||
alt: query, | ||
alt: title, | ||
title: img.title || "", | ||
@@ -102,3 +106,3 @@ url: img.url, | ||
values.forEach((value) => { | ||
const { name = "value", multi, query } = parseName(value); | ||
const { name = DEFAULT_VALUE_NAME, multi, title } = parseName(value); | ||
parent.children.push({ | ||
@@ -111,3 +115,3 @@ type: "quote", | ||
: undefined, | ||
value: query, | ||
value: title, | ||
}); | ||
@@ -135,6 +139,6 @@ }); | ||
const name = content === null || content === void 0 ? void 0 : content.split(/\s+/)[0]; | ||
const query = content === null || content === void 0 ? void 0 : content.slice(name.length).trim(); | ||
const title = content === null || content === void 0 ? void 0 : content.slice(name.length).trim(); | ||
return { | ||
name: name || undefined, | ||
query, | ||
title, | ||
multi, | ||
@@ -152,6 +156,6 @@ }; | ||
const name = content === null || content === void 0 ? void 0 : content.split(/\s+/)[0]; | ||
const query = content === null || content === void 0 ? void 0 : content.slice(name.length).trim(); | ||
const title = content === null || content === void 0 ? void 0 : content.slice(name.length).trim(); | ||
return { | ||
name: name || "steps", | ||
query, | ||
name: name || DEFAULT_BLOCKS_NAME, | ||
title, | ||
multi, | ||
@@ -158,0 +162,0 @@ }; |
@@ -20,3 +20,3 @@ import { getObjectAttribute } from "./estree.js"; | ||
children: newPath, | ||
query: section.query, | ||
title: section.title, | ||
_data: section._data, | ||
@@ -23,0 +23,0 @@ }; |
@@ -61,3 +61,3 @@ "use client"; | ||
function hikeToTree(section, path, name) { | ||
const { query, children, code = [], ...rest } = section; | ||
const { title, children, code = [], ...rest } = section; | ||
const nodePath = path ? path + "." + name : name; | ||
@@ -72,7 +72,7 @@ const kids = codeToChildren(code, nodePath); | ||
children: kids, | ||
content: (_jsxs(_Fragment, { children: [_jsx(Property, { name: "query", children: _jsx("pre", { children: query }) }), _jsx(Property, { name: "children", children: children }), kids.map((kid, i) => (_jsx(Property, { name: kid.name, children: _jsx("pre", { children: `[${kid.children.length} items]` }) }, i)))] })), | ||
content: (_jsxs(_Fragment, { children: [_jsx(Property, { name: "title", children: _jsx("pre", { children: title }) }), _jsx(Property, { name: "children", children: children }), kids.map((kid, i) => (_jsx(Property, { name: kid.name, children: _jsx("pre", { children: `[${kid.children.length} items]` }) }, i)))] })), | ||
}; | ||
} | ||
function sectionToTree(section, path, name) { | ||
const { query, children, code = [], ...rest } = section; | ||
const { title, children, code = [], ...rest } = section; | ||
const nodePath = path; | ||
@@ -87,3 +87,3 @@ const kids = codeToChildren(code, nodePath); | ||
children: kids, | ||
content: (_jsxs(_Fragment, { children: [_jsx(Property, { name: "query", children: query }), _jsx(Property, { name: "children", children: children }), kids.map((kid, i) => (_jsx(Property, { name: kid.name, children: _jsx("pre", { children: `[${kid.children.length} items]` }) }, i)))] })), | ||
content: (_jsxs(_Fragment, { children: [_jsx(Property, { name: "title", children: title }), _jsx(Property, { name: "children", children: children }), kids.map((kid, i) => (_jsx(Property, { name: kid.name, children: _jsx("pre", { children: `[${kid.children.length} items]` }) }, i)))] })), | ||
}; | ||
@@ -114,5 +114,5 @@ } | ||
name: name, | ||
children: list.map((item, i) => sectionToTree(item, `${nodePath}[${i}]`, `${i}: ${item.query}`)), | ||
content: (_jsx(_Fragment, { children: list.map((item, i) => (_jsx(Property, { name: `[${i}]`, children: `!${name} ${item.query}` }, i))) })), | ||
children: list.map((item, i) => sectionToTree(item, `${nodePath}[${i}]`, `${i}: ${item.title}`)), | ||
content: (_jsx(_Fragment, { children: list.map((item, i) => (_jsx(Property, { name: `[${i}]`, children: `!${name} ${item.title}` }, i))) })), | ||
}; | ||
} |
/// <reference types="react" /> | ||
import { ZodTypeDef, z } from "zod"; | ||
export declare const Block: z.ZodObject<{ | ||
query: z.ZodString; | ||
title: z.ZodString; | ||
children: z.ZodArray<z.ZodType<import("react").ReactNode, ZodTypeDef, import("react").ReactNode>, "many">; | ||
}, "strip", z.ZodTypeAny, { | ||
children: import("react").ReactNode[]; | ||
query: string; | ||
title: string; | ||
}, { | ||
children: import("react").ReactNode[]; | ||
query: string; | ||
title: string; | ||
}>; | ||
@@ -27,15 +27,15 @@ export declare const Code: z.ZodObject<{ | ||
export declare const Image: z.ZodObject<{ | ||
src: z.ZodString; | ||
url: z.ZodString; | ||
alt: z.ZodString; | ||
title: z.ZodString; | ||
}, "strip", z.ZodTypeAny, { | ||
title: string; | ||
alt: string; | ||
url: string; | ||
}, { | ||
title: string; | ||
src: string; | ||
}, { | ||
alt: string; | ||
title: string; | ||
src: string; | ||
url: string; | ||
}>; | ||
export declare function parse<Output, Def extends ZodTypeDef, Input>(content: unknown, Schema: z.ZodType<Output, Def, Input>): Output; | ||
//# sourceMappingURL=schema.d.ts.map |
import { z } from "zod"; | ||
export const Block = z.object({ | ||
query: z.string(), | ||
title: z.string(), | ||
children: z.array(z.custom()), | ||
@@ -12,3 +12,3 @@ }); | ||
export const Image = z.object({ | ||
src: z.string(), | ||
url: z.string(), | ||
alt: z.string(), | ||
@@ -15,0 +15,0 @@ title: z.string(), |
{ | ||
"name": "codehike", | ||
"version": "1.0.0-alpha.11", | ||
"version": "1.0.0-alpha.12", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
106884
2499