More docs

This commit is contained in:
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(', ')}>`; import generateComponentMd from './generate-component-md.mjs';
import generateFunctionMd from './generate-function-md.mjs';
const generateComponentDoc = (docs) => ` import generateTypeMd from './generate-type-md.mjs';
## ${docs.exportName} import generateEnumMd from './generate-enum-md.mjs';
import generateInterfaceMd from './generate-interface-md.mjs';
${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')}
`;
const generateMembersDocs = (children) => children ? ` const generateMembersDocs = (children) => children ? `
- **Members** - **Members**
@ -31,8 +11,13 @@ ${(children)
.join('\n')} .join('\n')}
` : ''; ` : '';
const generateTSDocs = (docs) => ` const generateTSDocs = (docs) => {
## ${docs.name}${docs.typeParameters ? getTypeParamString(docs.typeParameters) : ''} 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 || ''} ${docs.comment?.shortText || ''}
@ -40,6 +25,8 @@ ${docs.comment?.shortText || ''}
${generateMembersDocs(docs.children)} ${generateMembersDocs(docs.children)}
`; `;
}
}
const generateChildren = ( const generateChildren = (
children = [], children = [],
@ -47,7 +34,7 @@ const generateChildren = (
) => children.map((child) => { ) => children.map((child) => {
const componentDocs = components.find((c) => c.exportName === child.name); const componentDocs = components.find((c) => c.exportName === child.name);
if (componentDocs) { if (componentDocs) {
return generateComponentDoc(componentDocs); return generateComponentMd(componentDocs);
} }
return generateTSDocs(child); 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 # @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 ## SbBlock
Displays a Schlechtenburg block either the mode of the schlechtenburg instance. 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 ## 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 ## 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": [ "sources": [
{ {
"fileName": "main.ts", "fileName": "main.ts",
"line": 8, "line": 13,
"character": 13 "character": 13
} }
], ],
@ -26,7 +26,10 @@
"kind": 4096, "kind": 4096,
"kindString": "Call signature", "kindString": "Call signature",
"flags": {}, "flags": {},
"comment": {}, "comment": {
"shortText": "Initializes the Schlechtenburg editor",
"returns": "A set of functions to interact with the live Schlechtenburg instance\n"
},
"parameters": [ "parameters": [
{ {
"id": 3, "id": 3,
@ -34,6 +37,9 @@
"kind": 32768, "kind": 32768,
"kindString": "Parameter", "kindString": "Parameter",
"flags": {}, "flags": {},
"comment": {
"shortText": "The element on which the editor schould be mounted"
},
"type": { "type": {
"type": "union", "type": "union",
"types": [ "types": [
@ -56,6 +62,9 @@
"kind": 32768, "kind": 32768,
"kindString": "Parameter", "kindString": "Parameter",
"flags": {}, "flags": {},
"comment": {
"shortText": "The Schlechtenburg props\n"
},
"type": { "type": {
"type": "reference", "type": "reference",
"name": "ISbMainProps" "name": "ISbMainProps"
@ -76,27 +85,6 @@
"children": [ "children": [
{ {
"id": 6, "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", "name": "getBlock",
"kind": 1024, "kind": 1024,
"kindString": "Property", "kindString": "Property",
@ -104,14 +92,14 @@
"type": { "type": {
"type": "reflection", "type": "reflection",
"declaration": { "declaration": {
"id": 8, "id": 7,
"name": "__type", "name": "__type",
"kind": 65536, "kind": 65536,
"kindString": "Type literal", "kindString": "Type literal",
"flags": {}, "flags": {},
"signatures": [ "signatures": [
{ {
"id": 9, "id": 8,
"name": "__type", "name": "__type",
"kind": 4096, "kind": 4096,
"kindString": "Call signature", "kindString": "Call signature",
@ -141,7 +129,7 @@
} }
}, },
{ {
"id": 14, "id": 13,
"name": "getMode", "name": "getMode",
"kind": 1024, "kind": 1024,
"kindString": "Property", "kindString": "Property",
@ -149,14 +137,14 @@
"type": { "type": {
"type": "reflection", "type": "reflection",
"declaration": { "declaration": {
"id": 15, "id": 14,
"name": "__type", "name": "__type",
"kind": 65536, "kind": 65536,
"kindString": "Type literal", "kindString": "Type literal",
"flags": {}, "flags": {},
"signatures": [ "signatures": [
{ {
"id": 16, "id": 15,
"name": "__type", "name": "__type",
"kind": 4096, "kind": 4096,
"kindString": "Call signature", "kindString": "Call signature",
@ -171,7 +159,7 @@
} }
}, },
{ {
"id": 10, "id": 9,
"name": "setBlock", "name": "setBlock",
"kind": 1024, "kind": 1024,
"kindString": "Property", "kindString": "Property",
@ -179,21 +167,21 @@
"type": { "type": {
"type": "reflection", "type": "reflection",
"declaration": { "declaration": {
"id": 11, "id": 10,
"name": "__type", "name": "__type",
"kind": 65536, "kind": 65536,
"kindString": "Type literal", "kindString": "Type literal",
"flags": {}, "flags": {},
"signatures": [ "signatures": [
{ {
"id": 12, "id": 11,
"name": "__type", "name": "__type",
"kind": 4096, "kind": 4096,
"kindString": "Call signature", "kindString": "Call signature",
"flags": {}, "flags": {},
"parameters": [ "parameters": [
{ {
"id": 13, "id": 12,
"name": "block", "name": "block",
"kind": 32768, "kind": 32768,
"kindString": "Parameter", "kindString": "Parameter",
@ -220,7 +208,7 @@
} }
}, },
{ {
"id": 17, "id": 16,
"name": "setMode", "name": "setMode",
"kind": 1024, "kind": 1024,
"kindString": "Property", "kindString": "Property",
@ -228,21 +216,21 @@
"type": { "type": {
"type": "reflection", "type": "reflection",
"declaration": { "declaration": {
"id": 18, "id": 17,
"name": "__type", "name": "__type",
"kind": 65536, "kind": 65536,
"kindString": "Type literal", "kindString": "Type literal",
"flags": {}, "flags": {},
"signatures": [ "signatures": [
{ {
"id": 19, "id": 18,
"name": "__type", "name": "__type",
"kind": 4096, "kind": 4096,
"kindString": "Call signature", "kindString": "Call signature",
"flags": {}, "flags": {},
"parameters": [ "parameters": [
{ {
"id": 20, "id": 19,
"name": "mode", "name": "mode",
"kind": 32768, "kind": 32768,
"kindString": "Parameter", "kindString": "Parameter",
@ -269,10 +257,9 @@
"kind": 1024, "kind": 1024,
"children": [ "children": [
6, 6,
7, 13,
14, 9,
10, 16
17
] ]
} }
] ]

View file

@ -3,17 +3,18 @@ import { ISbMainProps } from '@schlechtenburg/core';
import getWrapper from './get-wrapper'; 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 ( export const startSchlechtenburg = async (
/**
* The element on which the editor schould be mounted
*/
el:HTMLElement|string, el:HTMLElement|string,
/**
* The schlechtenburg props
*/
props:ISbMainProps, props:ISbMainProps,
) => { ) => {
const { const {
@ -31,7 +32,6 @@ export const startSchlechtenburg = async (
app.mount(el); app.mount(el);
return { return {
app,
getBlock, getBlock,
setBlock, setBlock,
getMode, getMode,