Fixed Typescript build

This commit is contained in:
Benjamin Bädorf 2020-05-25 23:10:21 +02:00
parent 517dd91119
commit 354c530610
No known key found for this signature in database
GPG key ID: 4406E80E13CD656C
17 changed files with 131 additions and 152 deletions

View file

@ -16,14 +16,14 @@ steps:
branch: branch:
- master - master
image: appleboy/drone-scp image: appleboy/drone-scp
repo: b12f/bbcom
settings: settings:
host: web5svsvy.wh.hosting.zone host: web5svsvy.wh.hosting.zone
port: 2244 port: 2244
username: username:
from_secret: bbcom_ssh_user from_secret: dev_ssh_user
key: key:
from_secret: bbcom_ssh_key from_secret: dev_ssh_key
source: ./dist/* source: ./dist/*
target: /home/web5svsvy/html/schlechtenburg.b12f.io/ target: /home/web5svsvy/html/schlechtenburg.b12f.io/
strip_components: 1
rm: true rm: true

View file

@ -1,5 +1,6 @@
module.exports = { module.exports = {
presets: [ presets: [
'vca-jsx',
'@vue/cli-plugin-babel/preset', '@vue/cli-plugin-babel/preset',
], ],
}; };

9
package-lock.json generated
View file

@ -3124,6 +3124,15 @@
"babel-plugin-jest-hoist": "^24.9.0" "babel-plugin-jest-hoist": "^24.9.0"
} }
}, },
"babel-preset-vca-jsx": {
"version": "0.3.5",
"resolved": "https://registry.npmjs.org/babel-preset-vca-jsx/-/babel-preset-vca-jsx-0.3.5.tgz",
"integrity": "sha512-UUsTwaUDn2y/7x32dc2veBj4+mqjNOhcxMlHFA4EHZLLxlVWMEFhSYROStpBkmZBy38iw8qFN8+SB9RVlhQ68w==",
"dev": true,
"requires": {
"@babel/plugin-syntax-jsx": "^7.2.0"
}
},
"babel-runtime": { "babel-runtime": {
"version": "6.26.0", "version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz", "resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",

View file

@ -27,6 +27,7 @@
"@vue/eslint-config-airbnb": "^5.0.2", "@vue/eslint-config-airbnb": "^5.0.2",
"@vue/eslint-config-typescript": "^5.0.2", "@vue/eslint-config-typescript": "^5.0.2",
"@vue/test-utils": "1.0.0-beta.31", "@vue/test-utils": "1.0.0-beta.31",
"babel-preset-vca-jsx": "^0.3.5",
"chromedriver": "^80.0.1", "chromedriver": "^80.0.1",
"eslint": "^6.7.2", "eslint": "^6.7.2",
"eslint-plugin-import": "^2.20.2", "eslint-plugin-import": "^2.20.2",

View file

@ -4,6 +4,7 @@ import {
watchEffect, watchEffect,
} from '@vue/composition-api'; } from '@vue/composition-api';
import Schlechtenburg from '@components/Schlechtenburg'; import Schlechtenburg from '@components/Schlechtenburg';
import { BlockData } from './components/TreeElement';
import './App.scss'; import './App.scss';
@ -18,21 +19,24 @@ export default defineComponent({
orientation: 'vertical', orientation: 'vertical',
children: [], children: [],
}, },
}); }) as BlockData;
watchEffect(() => { return () => (
console.log('base block update', block);
});
return { block };
},
render() {
return (
<div id="app"> <div id="app">
<Schlechtenburg vModel={this.block} /> <Schlechtenburg
block={block}
{...{
on: {
update: (newBlock: BlockData) => {
block.name = newBlock.name;
block.blockId = newBlock.blockId;
block.data = newBlock.data;
},
},
}}
/>
<pre><code>{JSON.stringify(this.block, null, 2)}</code></pre> <pre><code>{JSON.stringify(block, null, 2)}</code></pre>
</div> </div>
); );
}, },

View file

@ -8,7 +8,7 @@ import {
import { import {
model, model,
ActiveBlock, ActiveBlock,
BlockProps, BlockData,
BlockDefinition, BlockDefinition,
BlockLibraryDefinition, BlockLibraryDefinition,
BlockLibrary, BlockLibrary,
@ -21,6 +21,11 @@ import SbParagraph from '@user/Paragraph/index';
import SbImage from '@user/Image/index'; import SbImage from '@user/Image/index';
import SbHeading from '@user/Heading/index'; import SbHeading from '@user/Heading/index';
export interface SchlechtenburgProps {
customBlocks: BlockDefinition[];
block: BlockData;
}
export default defineComponent({ export default defineComponent({
name: 'schlechtenburg-main', name: 'schlechtenburg-main',
@ -28,10 +33,10 @@ export default defineComponent({
props: { props: {
customBlocks: { type: (null as unknown) as PropType<BlockDefinition[]>, default: () => [] }, customBlocks: { type: (null as unknown) as PropType<BlockDefinition[]>, default: () => [] },
block: { type: Object, required: true }, block: { type: (null as unknown) as PropType<BlockData>, required: true },
}, },
setup(props: BlockProps) { setup(props, context) {
const activeBlock = ref(null); const activeBlock = ref(null);
provide(ActiveBlock, activeBlock); provide(ActiveBlock, activeBlock);
@ -42,24 +47,21 @@ export default defineComponent({
'sb-heading': SbHeading, 'sb-heading': SbHeading,
...props.customBlocks.reduce( ...props.customBlocks.reduce(
( (
blocks: BlockLibraryDefinition, blocks,
block: BlockLibraryDefinition, block,
) => ({ ...blocks, [block.name]: block }), ) => ({ ...blocks, [block.name]: block }),
{}, {},
), ),
}); });
provide(BlockLibrary, blockLibrary); provide(BlockLibrary, blockLibrary);
},
render() { return () => (
console.log('render base');
return (
<SbBlock <SbBlock
class="sb-main" class="sb-main"
block={this.block} block={props.block}
{...{ {...{
on: { on: {
update: (block: BlockDefinition) => this.$emit('update', block), update: (block: BlockDefinition) => context.emit('update', block),
}, },
}} }}
/> />

View file

@ -22,12 +22,12 @@ export interface BlockLibraryDefinition {
export interface BlockData { export interface BlockData {
name: string; name: string;
blockId: string|number; blockId: string;
data: { [name: string]: any }; data: { [name: string]: any };
} }
export interface BlockProps { export interface BlockProps {
blockId: string|number; blockId: string;
data: { [key: string]: any}; data: { [key: string]: any};
} }
@ -37,7 +37,7 @@ export const model = {
}; };
export const blockProps = { export const blockProps = {
blockId: { type: [String, Number], required: true }, blockId: { type: String, required: true },
data: { type: Object, default: () => ({}) }, data: { type: Object, default: () => ({}) },
}; };
@ -48,10 +48,10 @@ export function useDynamicBlocks() {
return { customBlocks, getBlock }; return { customBlocks, getBlock };
} }
export function useActivation(currentBlockId: string|number) { export function useActivation(currentBlockId: string) {
const activeBlockId: Ref<string|number|null> = inject(ActiveBlock, ref(null)); const activeBlockId: Ref<string|null> = inject(ActiveBlock, ref(null));
const isActive = computed(() => activeBlockId.value === currentBlockId); const isActive = computed(() => activeBlockId.value === currentBlockId);
const activate = (blockId?: string|number|null) => { const activate = (blockId?: string|null) => {
activeBlockId.value = blockId !== undefined ? blockId : currentBlockId; activeBlockId.value = blockId !== undefined ? blockId : currentBlockId;
}; };
const requestActivation = () => { const requestActivation = () => {

View file

@ -16,11 +16,11 @@ export default defineComponent({
name: 'sb-block', name: 'sb-block',
props: { props: {
block: { type: (null as unknown) as PropType<BlockData>, default: false }, block: { type: (null as unknown) as PropType<BlockData>, required: true },
}, },
setup(props, context) { setup(props, context) {
const { isActive, activate, requestActivation } = useActivation(props.block.blockId); const { isActive, activate } = useActivation(props.block.blockId);
const { getBlock } = useDynamicBlocks(); const { getBlock } = useDynamicBlocks();
const classes = computed(() => ({ const classes = computed(() => ({
'sb-block': true, 'sb-block': true,
@ -28,7 +28,6 @@ export default defineComponent({
})); }));
const onChildUpdate = (updated: {[key: string]: any}) => { const onChildUpdate = (updated: {[key: string]: any}) => {
console.log('child update', updated);
context.emit('update', { context.emit('update', {
...props.block, ...props.block,
data: { data: {
@ -38,33 +37,24 @@ export default defineComponent({
}); });
}; };
return { const Block = getBlock(props.block.name).edit as any;
getBlock,
classes,
onChildUpdate,
activate,
};
},
render() { return () => <Block
console.log('render block', this.block); class={classes.value}
const Block = this.getBlock(this.block.name).edit; data={props.block.data}
return <Block block-id={props.block.blockId}
class={this.classes}
data={this.block.data}
block-id={this.block.blockId}
{...{ {...{
attrs: this.$attrs, attrs: context.attrs,
on: { on: {
...this.$listeners, ...context.listeners,
update: this.onChildUpdate, update: onChildUpdate,
'insert-block': (block: BlockDefinition) => this.$emit('insert-block', block), 'insert-block': (block: BlockDefinition) => context.emit('insert-block', block),
'append-block': (block: BlockDefinition) => this.$emit('append-block', block), 'append-block': (block: BlockDefinition) => context.emit('append-block', block),
}, },
nativeOn: { nativeOn: {
click: ($event) => { click: ($event: MouseEvent) => {
$event.stopPropagation(); $event.stopPropagation();
this.activate(); activate();
}, },
}, },
}} }}

View file

@ -1,31 +1,31 @@
import { computed, defineComponent } from '@vue/composition-api'; import { computed, defineComponent } from '@vue/composition-api';
import { useDynamicBlocks } from '../TreeElement'; import {
useDynamicBlocks,
BlockDefinition,
} from '../TreeElement';
import './BlockPicker.scss'; import './BlockPicker.scss';
export default defineComponent({ export default defineComponent({
name: 'sb-block-picker',
props: {}, props: {},
setup() { setup(props, context) {
const { customBlocks } = useDynamicBlocks(); const { customBlocks } = useDynamicBlocks();
const blockList = computed(() => Object.keys(customBlocks).map((key) => customBlocks[key])); const blockList = computed(() => Object.keys(customBlocks).map((key) => customBlocks[key]));
console.log(customBlocks, blockList);
return { blockList }; return () => (
},
render() {
return (
<div class="sb-block-picker"> <div class="sb-block-picker">
{...this.blockList.map((block: BlockDefinition) => ( {...blockList.value.map((block: BlockDefinition) => (
<button <button
type="button" type="button"
{...{ {...{
on: { on: {
click: ($event) => this.$emit('picked-block', { click: () => context.emit('picked-block', {
name: block.name, name: block.name,
blockId: +(new Date()), blockId: `${+(new Date())}`,
data: block.getDefaultData(), data: block.getDefaultData(),
}), }),
}, },

View file

@ -7,13 +7,13 @@ import './BlockPlaceholder.scss';
export default defineComponent({ export default defineComponent({
name: 'sb-block-placeholder', name: 'sb-block-placeholder',
render() { setup(props, context) {
return ( return () => (
<div class="sb-block-placeholder"> <div class="sb-block-placeholder">
<BlockPicker <BlockPicker
{...{ {...{
on: { on: {
'picked-block': (block: BlockDefinition) => this.$emit('insert-block', block), 'picked-block': (block: BlockDefinition) => context.emit('insert-block', block),
}, },
}} }}
/> />

View file

@ -5,10 +5,10 @@ import './Toolbar.scss';
export default defineComponent({ export default defineComponent({
name: 'sb-toolbar', name: 'sb-toolbar',
render() { setup(props, context) {
return ( return () => (
<div class="sb-toolbar"> <div class="sb-toolbar">
{this.$slots.default} {context.slots.default()}
</div> </div>
); );
}, },

View file

@ -0,0 +1 @@
export default {};

View file

@ -9,7 +9,6 @@ import {
import { import {
model, model,
blockProps, blockProps,
useActivation,
} from '@components/TreeElement'; } from '@components/TreeElement';
import SbToolbar from '@internal/Toolbar'; import SbToolbar from '@internal/Toolbar';
@ -61,16 +60,7 @@ export default defineComponent({
} }
}; };
return { return () => (
localData,
fileInput,
selectImage,
onImageSelect,
};
},
render() {
return (
<div class="sb-image"> <div class="sb-image">
<SbToolbar> <SbToolbar>
Image Edit Image Edit
@ -80,17 +70,17 @@ export default defineComponent({
style="display: none;" style="display: none;"
{...{ {...{
on: { on: {
input: this.onImageSelect, input: onImageSelect,
}, },
}} }}
/> />
</SbToolbar> </SbToolbar>
{this.localData.src {localData.src
? <img src={this.localData.src} alt={this.localData.alt} /> ? <img src={localData.src} alt={localData.alt} />
: <button : <button
{...{ {...{
on: { on: {
click: this.selectImage, click: selectImage,
}, },
}} }}
>Select Image</button> >Select Image</button>

View file

@ -8,10 +8,8 @@ import {
import { import {
model, model,
blockProps, blockProps,
useDynamicBlocks,
useActivation, useActivation,
BlockData, BlockData,
BlockDefinition,
} from '@components/TreeElement'; } from '@components/TreeElement';
import SbBlock from '@internal/Block'; import SbBlock from '@internal/Block';
@ -40,8 +38,7 @@ export default defineComponent({
}, },
setup(props: LayoutProps, context) { setup(props: LayoutProps, context) {
const { getBlock } = useDynamicBlocks(); const { activate } = useActivation(props.blockId);
const { isActive, activate } = useActivation(props.blockId);
const localData: LayoutData = reactive({ const localData: LayoutData = reactive({
orientation: props.data.orientation, orientation: props.data.orientation,
@ -64,7 +61,7 @@ export default defineComponent({
}); });
}; };
const onChildUpdate = (child, updated) => { const onChildUpdate = (child: BlockData, updated: BlockData) => {
const index = localData.children.indexOf(child); const index = localData.children.indexOf(child);
context.emit('update', { context.emit('update', {
children: [ children: [
@ -99,44 +96,28 @@ export default defineComponent({
activate(block.blockId); activate(block.blockId);
}; };
return { return () => (
isActive, <div class={classes.value}>
activate,
classes,
onChildUpdate,
toggleOrientation,
localData,
getBlock,
appendBlock,
insertBlock,
};
},
render() {
console.log('render layout');
return (
<div class={this.classes}>
<SbToolbar slot="toolbar"> <SbToolbar slot="toolbar">
<button <button
type="button" type="button"
{...{ {...{
on: { on: {
click: this.toggleOrientation, click: toggleOrientation,
}, },
}} }}
>{this.localData.orientation}</button> >{localData.orientation}</button>
</SbToolbar> </SbToolbar>
{...this.localData.children.map((child, index) => ( {...localData.children.map((child, index) => (
<SbBlock <SbBlock
key={child.id} key={child.blockId}
block={child} block={child}
{...{ {...{
on: { on: {
update: (updated) => this.onChildUpdate(child, updated), update: (updated: BlockData) => onChildUpdate(child, updated),
'insert-block': (block: BlockDefinition) => this.insertBlock(index, block), 'insert-block': (block: BlockData) => insertBlock(index, block),
'append-block': this.appendBlock, 'append-block': appendBlock,
}, },
}} }}
/> />
@ -145,7 +126,7 @@ export default defineComponent({
<SbBlockPlaceholder <SbBlockPlaceholder
{...{ {...{
on: { on: {
'insert-block': this.appendBlock, 'insert-block': appendBlock,
}, },
}} }}
/> />

View file

@ -1,11 +1,11 @@
import { import {
BlockProps, BlockProps,
BlockDefinition, BlockData,
} from '@components/TreeElement'; } from '@components/TreeElement';
export interface LayoutData { export interface LayoutData {
orientation: string; orientation: string;
children: BlockDefinition[]; children: BlockData[];
} }
export interface LayoutProps extends BlockProps { export interface LayoutProps extends BlockProps {

View file

@ -38,13 +38,15 @@ export default defineComponent({
}, },
setup(props: ParagraphProps, context) { setup(props: ParagraphProps, context) {
const localData = reactive({ const localData = (reactive({
value: props.data.value, value: props.data.value,
align: props.data.align, align: props.data.align,
focused: false, focused: false,
}); }) as any) as {
value: string;
console.log(localData); align: string;
focused: boolean;
};
const inputEl: Ref<null|HTMLElement> = ref(null); const inputEl: Ref<null|HTMLElement> = ref(null);
@ -61,7 +63,6 @@ export default defineComponent({
}); });
watch(() => props.data, () => { watch(() => props.data, () => {
console.log('props update paragraph');
localData.value = props.data.value; localData.value = props.data.value;
localData.align = props.data.align; localData.align = props.data.align;
if (inputEl.value) { if (inputEl.value) {
@ -70,7 +71,7 @@ export default defineComponent({
}); });
const onTextUpdate = ($event: InputEvent) => { const onTextUpdate = ($event: InputEvent) => {
localData.value = $event.target.innerHTML; localData.value = ($event.target as HTMLElement).innerHTML;
}; };
const classes = computed(() => ({ const classes = computed(() => ({
@ -79,6 +80,10 @@ export default defineComponent({
[`sb-paragraph_align-${localData.align}`]: true, [`sb-paragraph_align-${localData.align}`]: true,
})); }));
const setAlignment = ($event: Event) => {
context.emit('update', { align: ($event.target as HTMLSelectElement).value });
};
const onFocus = () => { const onFocus = () => {
localData.focused = true; localData.focused = true;
}; };
@ -93,7 +98,7 @@ export default defineComponent({
const onKeypress = ($event: KeyboardEvent) => { const onKeypress = ($event: KeyboardEvent) => {
if ($event.key === 'Enter') { if ($event.key === 'Enter') {
const blockId = +(new Date()); const blockId = `${+(new Date())}`;
context.emit('insert-block', { context.emit('insert-block', {
blockId, blockId,
name: 'sb-paragraph', name: 'sb-paragraph',
@ -106,37 +111,32 @@ export default defineComponent({
} }
}; };
return { return () => (
classes, <div class={classes.value}>
localData,
onTextUpdate,
onFocus,
onBlur,
onKeypress,
inputEl,
};
},
render() {
return (
<div class="sb-paragraph">
<SbToolbar> <SbToolbar>
<select vModel={this.localData.align}> <select
value={localData.align}
{...{
on: {
change: setAlignment,
},
}}
>
<option>left</option> <option>left</option>
<option>center</option> <option>center</option>
<option>right</option> <option>right</option>
</select> </select>
</SbToolbar> </SbToolbar>
<p <p
class={this.classes} class="sb-paragraph__input"
ref="inputEl" ref={inputEl}
contenteditable contenteditable
{...{ {...{
on: { on: {
input: this.onTextUpdate, input: onTextUpdate,
focus: this.onFocus, focus: onFocus,
blur: this.onBlur, blur: onBlur,
keypress: this.onKeypress, keypress: onKeypress,
}, },
}} }}
></p> ></p>

View file

@ -3,8 +3,8 @@
width: 100%; width: 100%;
&_align { &_align {
&-left { text-align: left; } &-left { .sb-paragraph__input { text-align: left; } }
&-right { text-align: right; } &-right { .sb-paragraph__input { text-align: right; } }
&-center { text-align: center; } &-center { .sb-paragraph__input { text-align: center; } }
} }
} }