Add component API to docs (ex: props, events, slots)

This commit is contained in:
venashial
2022-03-16 23:34:56 -07:00
parent 5a5f817e59
commit a0e05115a3
15 changed files with 877 additions and 41 deletions

View File

@@ -2,8 +2,11 @@ import {mdsvex} from 'mdsvex';
import mdsvexConfig from './mdsvex.config.js';
import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';
import sveltePreprocess from 'svelte-preprocess';
import Icons from 'unplugin-icons/vite';
import svelteSvg from '@poppanator/sveltekit-svg';
import {parse} from 'sveltedoc-parser'
import * as svelte from 'svelte/compiler'
/** @type {import('@sveltejs/kit').Config} */
const config = {
@@ -25,6 +28,34 @@ const config = {
compiler: 'svelte',
defaultClass: 'icon',
}),
{
name: "sveltedoc-parser",
async transform(src, id) {
const query = id.split('?')[1]
if ((query || '').includes('raw&api')) {
const raw = JSON.parse(src.split('export default ')[1])
let {code} = await svelte.preprocess(raw, sveltePreprocess(), {
filename: id
})
const data = await parse({
fileContent: code,
encoding: 'ascii',
features: ['data', 'computed', 'events', 'slots'],
ignoredVisibilities: ['private'],
includeSourceLocations: true,
version: 3
})
return {
code: `export default ${JSON.stringify(data)}`,
map: null
}
}
}
},
],
},
},