Initial api docs in vitepress

This commit is contained in:
Benjamin Bädorf 2022-03-21 01:53:25 +01:00
parent 4f870c63a6
commit fdb8ffcf2d
No known key found for this signature in database
GPG key ID: 4406E80E13CD656C
20 changed files with 122 additions and 66 deletions

View file

@ -15,7 +15,12 @@ export default defineConfig({
text: 'API',
activeMatch: `^/api/`,
items: [
{ text: '@schlechtenburg/standalone', link: '/api/@schlechtenburg/standalone' },
{ text: '@schlechtenburg/core', link: '/api/@schlechtenburg/core' },
{ text: '@schlechtenburg/layout', link: '/api/@schlechtenburg/layout' },
{ text: '@schlechtenburg/heading', link: '/api/@schlechtenburg/heading' },
{ text: '@schlechtenburg/paragraph', link: '/api/@schlechtenburg/paragraph' },
{ text: '@schlechtenburg/image', link: '/api/@schlechtenburg/image' },
],
},
],
@ -34,7 +39,12 @@ export default defineConfig({
{
text: 'API',
children: [
{ text: 'Core', link: '/api/core' },
{ text: '@schlechtenburg/standalone', link: '/api/@schlechtenburg/standalone' },
{ text: '@schlechtenburg/core', link: '/api/@schlechtenburg/core' },
{ text: '@schlechtenburg/layout', link: '/api/@schlechtenburg/layout' },
{ text: '@schlechtenburg/heading', link: '/api/@schlechtenburg/heading' },
{ text: '@schlechtenburg/paragraph', link: '/api/@schlechtenburg/paragraph' },
{ text: '@schlechtenburg/image', link: '/api/@schlechtenburg/image' },
],
}
],

View file

@ -0,0 +1,6 @@
<script setup>
import Package from '../Package'
</script>
<Package name="@schlechtenburg/core" />

View file

@ -0,0 +1,6 @@
<script setup>
import Package from '../Package'
</script>
<Package name="@schlechtenburg/heading" />

View file

@ -0,0 +1,6 @@
<script setup>
import Package from '../Package'
</script>
<Package name="@schlechtenburg/image" />

View file

@ -0,0 +1,6 @@
<script setup>
import Package from '../Package'
</script>
<Package name="@schlechtenburg/layout" />

View file

@ -0,0 +1,6 @@
<script setup>
import Package from '../Package'
</script>
<Package name="@schlechtenburg/paragraph" />

View file

@ -0,0 +1,6 @@
<script setup>
import Package from '../Package'
</script>
<Package name="@schlechtenburg/standalone" />

View file

@ -1,21 +1,28 @@
import { defineComponent } from 'vue';
import { useRoute } from 'vue-router';
import { ComponentDoc } from 'vue-docgen-api';
import { DeclarationReflection } from 'typedoc';
import { getByName } from '../docs';
import ComponentDocs from '../ComponentDocs';
import TsDocs from '../TsDocs';
import { getShortPackageName } from './package';
import ComponentDocs from './ComponentDocs';
import TSDocs from './TSDocs';
import './Package.scss';
export default defineComponent({
name: 'Package',
setup() {
const route = useRoute();
const packageName = route.params.package;
const docs = getByName(Array.isArray(packageName) ? packageName[0] : packageName);
props: {
name: {
type: String,
required: true,
},
},
setup(props) {
const packageName = props.name;
const docs = getByName(getShortPackageName(Array.isArray(packageName) ? packageName[0] : packageName));
if (!docs) {
return () => <div>Unknown package name {packageName}</div>;
}
@ -31,7 +38,7 @@ export default defineComponent({
return <ComponentDocs docs={componentDocs}></ComponentDocs>
}
return <TsDocs docs={child}></TsDocs>
return <TSDocs docs={child}></TSDocs>
})}
</main>;
},

View file

@ -7,12 +7,12 @@ import {
TypeParameterReflection,
} from 'typedoc';
import './TsDocs.scss';
import './TSDocs.scss';
const getTypeParamString = (params: TypeParameterReflection[]) => `<${params.map(p => p.name).join(', ')}>`;
export default defineComponent({
name: 'TsDocs',
name: 'TSDocs',
props: {
docs: {

View file

@ -5,14 +5,14 @@ import ExampleStandaloneEditor from '../ExampleStandaloneEditor'
# Examples
## Vue Component without wrapper
## As a View Component
This documentation website already uses Vue under the hood, so Schlechtenburg can just imported as
any other component:
<ExampleEditor></ExampleEditor>
## Wrapped with Vue
## Standalone
`@schlechtenburg/standalone` gives you a wrapped version of the editor in case you don't have Vue
already installed in your application

View file

@ -1,11 +0,0 @@
import { defineComponent } from 'vue';
import './Introduction.scss';
export default defineComponent({
name: 'Introduction',
setup() {
return () => <div class="introduction">Introduction</div>;
},
});

View file

@ -1,12 +0,0 @@
export default [
{
name: 'home',
path: '/',
component: () => import('./pages/Introduction'),
},
{
name: 'package',
path: '/@schlechtenburg/:package',
component: () => import('./pages/Package'),
},
]

View file

@ -1,6 +1,7 @@
import {
defineComponent,
ref,
Ref,
PropType,
} from 'vue'
import {
@ -9,17 +10,17 @@ import {
SbMain,
SbMode,
OnUpdateBlockCb,
ISbMainProps,
} from '@schlechtenburg/core';
/**
*
*/
export default function getWrapper({
block,
mode,
availableBlocks,
}) {
return defineComponent({
export default function getWrapper() {
const refBlock: Ref<IBlockData<any>|null> = ref(null);
const refMode = ref(SbMode.View);
const SchlechtenburgWrapper = defineComponent({
name: 'SchlechtenburgWrapper',
props: {
@ -47,15 +48,39 @@ export default function getWrapper({
},
},
setup(props) {
const refBlock = ref({ ...block });
const refMode = ref({ ...block });
setup(props: ISbMainProps) {
refBlock.value = { ...(props.block) };
refMode.value = props.mode;
if (!refBlock.value) {
return () => <div class="sb-message sb-message_error">An Error occurred</div>;
}
return () => <SbMain
block={refBlock}
block={refBlock.value as IBlockData<any>}
availableBlocks={props.availableBlocks}
mode={mode}
mode={refMode.value}
onUpdate={(newBlock: IBlockData<any>) => {
refBlock.value = { ...newBlock };
}}
/>
}
});
return {
SchlechtenburgWrapper,
getBlock() {
return refBlock.value;
},
setBlock(block: IBlockData<any>) {
refBlock.value = { ...block };
},
getMode() {
return refMode.value;
},
setMode(mode: SbMode) {
refMode.value = mode;
},
};
}

View file

@ -1,11 +1,6 @@
import {
createApp,
} from 'vue'
import {
ISbMainProps,
IBlockData,
SbMain,
} from '@schlechtenburg/core';
import { createApp } from 'vue'
import { ISbMainProps } from '@schlechtenburg/core';
import getWrapper from './get-wrapper';
/**
*
@ -21,19 +16,25 @@ export const startSchlechtenburg = async (
*/
props:ISbMainProps,
) => {
let block = { ...props.block };
const app = createApp(SbMain, {
...props,
onUpdate: (update: IBlockData<any>) => {
block = update;
props.onUpdate(update);
},
}as unknown as Record<string, unknown>);
const {
SchlechtenburgWrapper,
getBlock,
setBlock,
getMode,
setMode,
} = getWrapper();
const app = createApp(
SchlechtenburgWrapper,
{ ...props, } as unknown as Record<string, unknown>,
);
app.mount(el);
return {
getBlock() {
return block;
},
app,
getBlock,
setBlock,
getMode,
setMode,
};
}