More docs

master
Benjamin Bädorf 2022-03-22 23:02:56 +01:00
parent 7142cb40d7
commit 649957c544
No known key found for this signature in database
GPG Key ID: 4406E80E13CD656C
13 changed files with 140 additions and 242 deletions

View File

@ -0,0 +1,23 @@
export default (docs) => `
## ${docs.exportName}
${docs.description || ''}
- **Type**: \`Component\`
### Props
${(docs.props || []).map(prop => `
#### ${prop.name}
${prop.description || ''}
${prop.type ? `
- **Type** \`${prop.type.name}\`
` : ''}
${prop.defaultValue ? `
- **Default value** \`${prop.defaultValue.value}\`
` : ''}
`).join('\n')}
`;

View File

@ -0,0 +1,2 @@
export default (docs) => `
`;

View File

@ -0,0 +1,19 @@
import generateLibName from './generate-lib-name.mjs';
import generateTypeMd from './generate-type-md.mjs';
const generateParameterMd = (params) => params && params.length ? `
- **Parameters**
${params.map(param => `
- **${param.name}** \`${generateTypeMd(param.type)}\`
${param.comment?.shortText}
`)}
` : '';
export default (docs) => `
${generateLibName(docs)}
${docs.comment?.shortText || ''}
${generateParameterMd(docs.parameters)}
`;

View File

@ -0,0 +1,2 @@
export default (docs) => `
`;

View File

@ -0,0 +1,5 @@
const getTypeParamString = (params) => `<${params.map(p => p.name).join(', ')}>`;
export default (docs) => `
## ${docs.name}${docs.typeParameters ? getTypeParamString(docs.typeParameters) : ''}
`;

View File

@ -1,28 +1,8 @@
const getTypeParamString = (params) => `<${params.map(p => p.name).join(', ')}>`;
const generateComponentDoc = (docs) => `
## ${docs.exportName}
${docs.description || ''}
- **Type**: \`Component\`
### Props
${(docs.props || []).map(prop => `
#### ${prop.name}
${prop.description || ''}
${prop.type ? `
- **Type** \`${prop.type.name}\`
` : ''}
${prop.defaultValue ? `
- **Default value** \`${prop.defaultValue.value}\`
` : ''}
`).join('\n')}
`;
import generateComponentMd from './generate-component-md.mjs';
import generateFunctionMd from './generate-function-md.mjs';
import generateTypeMd from './generate-type-md.mjs';
import generateEnumMd from './generate-enum-md.mjs';
import generateInterfaceMd from './generate-interface-md.mjs';
const generateMembersDocs = (children) => children ? `
- **Members**
@ -31,8 +11,13 @@ ${(children)
.join('\n')}
` : '';
const generateTSDocs = (docs) => `
## ${docs.name}${docs.typeParameters ? getTypeParamString(docs.typeParameters) : ''}
const generateTSDocs = (docs) => {
switch (docs.kindString) {
case 'Function': return generateFunctionMd(docs.signatures[0]); // There are currently no functions with multiple sigs
case 'Enumeration': return generateEnumMd(docs);
case 'Interface': return generateInterfaceMd(docs);
case 'Type alias': return generateTypeMd(docs);
default: return `
${docs.comment?.shortText || ''}
@ -40,6 +25,8 @@ ${docs.comment?.shortText || ''}
${generateMembersDocs(docs.children)}
`;
}
}
const generateChildren = (
children = [],
@ -47,7 +34,7 @@ const generateChildren = (
) => children.map((child) => {
const componentDocs = components.find((c) => c.exportName === child.name);
if (componentDocs) {
return generateComponentDoc(componentDocs);
return generateComponentMd(componentDocs);
}
return generateTSDocs(child);

View File

@ -0,0 +1,2 @@
export default (docs) => `
`;

View File

@ -0,0 +1,9 @@
const generateTypeMd = (docs) => {
if (docs.type === 'union') {
return docs.types.map(type => generateTypeMd(type)).join('|');
}
return docs.name;
};
export default generateTypeMd;

View File

@ -0,0 +1,2 @@
export default (docs) => `
`;

View File

@ -1,157 +1,5 @@
# @schlechtenburg/core
## SbMode
The mode the Schlechtenburg editor is currently in
- **Type** `Enumeration`
- **Members**
- **Edit**: `undefined`
- **View**: `undefined`
## IBlockData<T>
Schlechtenburg inputs and outputs a plain JS Object that can be JSON stringified. This is the
interface type for that data structure. `T` will be the data type of the specific block being
- **Type** `Interface`
- **Members**
- **data**: `T`
- **id**: `string`
- **name**: `string`
## IBlockDefinition<T>
Any Block that you create
- **Type** `Interface`
- **Members**
- **edit**: `Component`
- **getDefaultData**: `T`
- **icon**: `string`
- **name**: `string`
- **view**: `Component`
## IBlockLibrary
Schlechtenburg maintains a library of blocks that are available
- **Type** `Interface`
## IBlockProps<T>
Any Block that you create
- **Type** `Interface`
- **Members**
- **blockId**: `string`
- **data**: `T`
- **onActivateNext**: `OnActivateNextCb`
- **onActivatePrevious**: `OnActivatePreviousCb`
- **onAppendBlock**: `OnAppendBlockCb`
- **onPrependBlock**: `OnPrependBlockCb`
- **onRemoveSelf**: `OnRemoveSelfCb`
- **onUpdate**: `OnUpdateSelfCb`
## ISbMainProps
- **Type** `Interface`
- **Members**
- **availableBlocks**: `undefined`
- **block**: `IBlockData`
- **mode**: `SbMode`
- **onUpdate**: `OnUpdateBlockCb`
## ITreeNode
Schlechtenburg keeps track of the rendered block tree.
This is useful for e.g. the tree select component in the editor header.
- **Type** `Interface`
- **Members**
- **children**: `undefined`
- **icon**: `string`
- **id**: `string`
- **name**: `string`
## OnActivateNextCb
- **Type** `Type alias`
## OnActivatePreviousCb
- **Type** `Type alias`
## OnAppendBlockCb
- **Type** `Type alias`
## OnPrependBlockCb
- **Type** `Type alias`
## OnRemoveSelfCb
- **Type** `Type alias`
## OnUpdateBlockCb
- **Type** `Type alias`
## OnUpdateSelfCb<T>
- **Type** `Type alias`
## SbBlock
Displays a Schlechtenburg block either the mode of the schlechtenburg instance.
@ -367,7 +215,6 @@ A button in the schlechtenburg theme
## SbMain
@ -395,7 +242,6 @@ Toolbar in the schlechtenburg theme
## SymActiveBlock
@ -403,7 +249,6 @@ Toolbar in the schlechtenburg theme
## SymBlockDimensions
@ -411,7 +256,6 @@ Toolbar in the schlechtenburg theme
## SymBlockLibrary
@ -419,7 +263,6 @@ Toolbar in the schlechtenburg theme
## SymEditorDimensions
@ -427,7 +270,6 @@ Toolbar in the schlechtenburg theme
## SymMode
@ -435,7 +277,6 @@ Toolbar in the schlechtenburg theme
## blockProps
@ -443,7 +284,6 @@ Toolbar in the schlechtenburg theme
## model
@ -451,11 +291,14 @@ Toolbar in the schlechtenburg theme
## generateBlockId
- **Type** `Function`
- **Params**
@ -463,7 +306,9 @@ Toolbar in the schlechtenburg theme
- **Type** `Function`
- **Params**
@ -471,7 +316,9 @@ Toolbar in the schlechtenburg theme
- **Type** `Function`
- **Params**
@ -479,7 +326,9 @@ Toolbar in the schlechtenburg theme
- **Type** `Function`
- **Params**
@ -487,4 +336,6 @@ Toolbar in the schlechtenburg theme
- **Type** `Function`
- **Params**

View File

@ -3,5 +3,14 @@
## startSchlechtenburg
Initializes the Schlechtenburg editor
- **Type** `Function`
- **Parameters**
- **el** `string|HTMLElement`
The element on which the editor schould be mounted
,
- **props** `ISbMainProps`
The Schlechtenburg props

View File

@ -15,7 +15,7 @@
"sources": [
{
"fileName": "main.ts",
"line": 8,
"line": 13,
"character": 13
}
],
@ -26,7 +26,10 @@
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"comment": {},
"comment": {
"shortText": "Initializes the Schlechtenburg editor",
"returns": "A set of functions to interact with the live Schlechtenburg instance\n"
},
"parameters": [
{
"id": 3,
@ -34,6 +37,9 @@
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"comment": {
"shortText": "The element on which the editor schould be mounted"
},
"type": {
"type": "union",
"types": [
@ -56,6 +62,9 @@
"kind": 32768,
"kindString": "Parameter",
"flags": {},
"comment": {
"shortText": "The Schlechtenburg props\n"
},
"type": {
"type": "reference",
"name": "ISbMainProps"
@ -76,27 +85,6 @@
"children": [
{
"id": 6,
"name": "app",
"kind": 1024,
"kindString": "Property",
"flags": {},
"type": {
"type": "reference",
"typeArguments": [
{
"type": "reference",
"qualifiedName": "Element",
"package": "typescript",
"name": "Element"
}
],
"qualifiedName": "App",
"package": "@vue/runtime-core",
"name": "App"
}
},
{
"id": 7,
"name": "getBlock",
"kind": 1024,
"kindString": "Property",
@ -104,14 +92,14 @@
"type": {
"type": "reflection",
"declaration": {
"id": 8,
"id": 7,
"name": "__type",
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"signatures": [
{
"id": 9,
"id": 8,
"name": "__type",
"kind": 4096,
"kindString": "Call signature",
@ -141,7 +129,7 @@
}
},
{
"id": 14,
"id": 13,
"name": "getMode",
"kind": 1024,
"kindString": "Property",
@ -149,14 +137,14 @@
"type": {
"type": "reflection",
"declaration": {
"id": 15,
"id": 14,
"name": "__type",
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"signatures": [
{
"id": 16,
"id": 15,
"name": "__type",
"kind": 4096,
"kindString": "Call signature",
@ -171,7 +159,7 @@
}
},
{
"id": 10,
"id": 9,
"name": "setBlock",
"kind": 1024,
"kindString": "Property",
@ -179,21 +167,21 @@
"type": {
"type": "reflection",
"declaration": {
"id": 11,
"id": 10,
"name": "__type",
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"signatures": [
{
"id": 12,
"id": 11,
"name": "__type",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"parameters": [
{
"id": 13,
"id": 12,
"name": "block",
"kind": 32768,
"kindString": "Parameter",
@ -220,7 +208,7 @@
}
},
{
"id": 17,
"id": 16,
"name": "setMode",
"kind": 1024,
"kindString": "Property",
@ -228,21 +216,21 @@
"type": {
"type": "reflection",
"declaration": {
"id": 18,
"id": 17,
"name": "__type",
"kind": 65536,
"kindString": "Type literal",
"flags": {},
"signatures": [
{
"id": 19,
"id": 18,
"name": "__type",
"kind": 4096,
"kindString": "Call signature",
"flags": {},
"parameters": [
{
"id": 20,
"id": 19,
"name": "mode",
"kind": 32768,
"kindString": "Parameter",
@ -269,10 +257,9 @@
"kind": 1024,
"children": [
6,
7,
14,
10,
17
13,
9,
16
]
}
]

View File

@ -3,17 +3,18 @@ import { ISbMainProps } from '@schlechtenburg/core';
import getWrapper from './get-wrapper';
/**
* Initializes the Schlechtenburg editor
*
* @param el The element on which the editor schould be mounted
* @param props The Schlechtenburg props
*
* @returns A set of functions to interact with the live Schlechtenburg instance
*
* @See ISbMainProps
* @See SbMain
*/
export const startSchlechtenburg = async (
/**
* The element on which the editor schould be mounted
*/
el:HTMLElement|string,
/**
* The schlechtenburg props
*/
props:ISbMainProps,
) => {
const {
@ -31,7 +32,6 @@ export const startSchlechtenburg = async (
app.mount(el);
return {
app,
getBlock,
setBlock,
getMode,