Added fixes

This commit is contained in:
Benjamin Bädorf 2020-05-27 20:36:46 +02:00
parent f408114fc7
commit 141bc04505
No known key found for this signature in database
GPG key ID: 4406E80E13CD656C
8 changed files with 77 additions and 51 deletions

View file

@ -3,7 +3,7 @@
display: flex; display: flex;
align-items: stretch; align-items: stretch;
justify-items: stretch; justify-items: stretch;
min-height: 50px; height: auto;
> * > .sb-toolbar { > * > .sb-toolbar {
opacity: 0; opacity: 0;
@ -16,6 +16,7 @@
> * > .sb-toolbar { > * > .sb-toolbar {
opacity: 1; opacity: 1;
pointer-events: all; pointer-events: all;
outline: 1px solid var(--grey-2);
} }
} }
} }

View file

@ -17,6 +17,7 @@ interface BlockProps {
eventUpdate: (b?: Block) => void; eventUpdate: (b?: Block) => void;
eventInsertBlock: (b?: Block) => void; eventInsertBlock: (b?: Block) => void;
eventAppendBlock: (b?: Block) => void; eventAppendBlock: (b?: Block) => void;
eventRemoveBlock: () => void;
} }
export default defineComponent({ export default defineComponent({
@ -30,6 +31,7 @@ export default defineComponent({
eventUpdate: { type: Function, default: () => {} }, eventUpdate: { type: Function, default: () => {} },
eventInsertBlock: { type: Function, default: () => {} }, eventInsertBlock: { type: Function, default: () => {} },
eventAppendBlock: { type: Function, default: () => {} }, eventAppendBlock: { type: Function, default: () => {} },
eventRemoveBlock: { type: Function, default: () => {} },
}, },
setup(props: BlockProps, context) { setup(props: BlockProps, context) {
@ -51,7 +53,6 @@ export default defineComponent({
}; };
const BlockComponent = getBlock(props.block.name) as any; const BlockComponent = getBlock(props.block.name) as any;
if (mode.value === SbMode.Display) { if (mode.value === SbMode.Display) {
return () => ( return () => (
<BlockComponent <BlockComponent
@ -70,13 +71,16 @@ export default defineComponent({
eventUpdate={onChildUpdate} eventUpdate={onChildUpdate}
eventInsertBlock={props.eventInsertBlock} eventInsertBlock={props.eventInsertBlock}
eventAppendBlock={props.eventAppendBlock} eventAppendBlock={props.eventAppendBlock}
onClick={($event: MouseEvent) => { eventRemoveBlock={props.eventRemoveBlock}
$event.stopPropagation();
activate();
}}
{...{ {...{
attrs: context.attrs, attrs: context.attrs,
on: context.listeners, nativeOn: {
click: ($event: MouseEvent) => {
$event.stopPropagation();
activate();
},
...context.listeners,
},
}} }}
/> />
</div>); </div>);

View file

@ -1,2 +1,11 @@
.sb-block-picker { .sb-block-picker {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
&__add-button {
padding: 24px 32px;
}
} }

View file

@ -34,10 +34,9 @@ export default defineComponent({
}; };
return () => ( return () => (
<div <div class="sb-block-picker">
class="sb-block-picker"
>
<SbButton <SbButton
class="sb-block-picker__add-button"
type="button" type="button"
onClick={($event: MouseEvent) => { onClick={($event: MouseEvent) => {
open.value = true; open.value = true;

View file

@ -12,6 +12,7 @@ import {
} from '@components/TreeElement'; } from '@components/TreeElement';
import SbToolbar from '@internal/Toolbar'; import SbToolbar from '@internal/Toolbar';
import SbButton from '@internal/Button';
import { import {
getDefaultData, getDefaultData,
@ -41,8 +42,6 @@ export default defineComponent({
alt: props.data.alt, alt: props.data.alt,
}); });
console.log(props);
const fileInput: Ref<null|HTMLInputElement> = ref(null); const fileInput: Ref<null|HTMLInputElement> = ref(null);
watch(() => props.data, () => { watch(() => props.data, () => {
@ -73,28 +72,19 @@ export default defineComponent({
return () => ( return () => (
<div class="sb-image"> <div class="sb-image">
<SbToolbar> <SbToolbar>
Image Edit {localData.src
? <SbButton onClick={selectImage}>Change Image</SbButton>
: null}
<input <input
type="file" type="file"
ref="fileInput" ref="fileInput"
style="display: none;" style="display: none;"
{...{ onInput={onImageSelect}
on: {
input: onImageSelect,
},
}}
/> />
</SbToolbar> </SbToolbar>
{localData.src {localData.src
? <img src={localData.src} alt={localData.alt} /> ? <img src={localData.src} alt={localData.alt} />
: <button : <SbButton onClick={selectImage}>Select Image</SbButton>}
{...{
on: {
click: selectImage,
},
}}
>Select Image</button>
}
</div> </div>
); );
}, },

View file

@ -1,9 +1,10 @@
.sb-image { .sb-image {
max-width: 100%;
max-height: 100%;
img { @at-root {
max-width: 100%; & > img,
max-height: 100%; img#{&} {
width: 100%;
height: auto;
}
} }
} }

View file

@ -65,6 +65,9 @@ export default defineComponent({
const onChildUpdate = (child: Block, updated: Block) => { const onChildUpdate = (child: Block, updated: Block) => {
const index = localData.children.indexOf(child); const index = localData.children.indexOf(child);
if (index === -1) {
return;
}
props.eventUpdate({ props.eventUpdate({
children: [ children: [
...localData.children.slice(0, index), ...localData.children.slice(0, index),
@ -78,26 +81,35 @@ export default defineComponent({
}; };
const appendBlock = (block: Block) => { const appendBlock = (block: Block) => {
props.eventUpdate({ localData.children = [
children: [ ...localData.children,
...localData.children, block,
block, ];
], props.eventUpdate({ children: [...localData.children] });
});
activate(block.blockId); activate(block.blockId);
}; };
const insertBlock = (index: number, block: Block) => { const insertBlock = (index: number, block: Block) => {
props.eventUpdate({ localData.children = [
children: [ ...localData.children.slice(0, index + 1),
...localData.children.slice(0, index + 1), block,
block, ...localData.children.slice(index + 1),
...localData.children.slice(index + 1), ];
], props.eventUpdate({ children: [...localData.children] });
});
activate(block.blockId); activate(block.blockId);
}; };
const removeBlock = (index: number) => {
localData.children = [
...localData.children.slice(0, index),
...localData.children.slice(index + 1),
];
props.eventUpdate({ children: [...localData.children] });
const newActiveIndex = Math.max(index - 1, 0);
activate(localData.children[newActiveIndex].blockId);
};
return () => ( return () => (
<div class={classes.value}> <div class={classes.value}>
<SbToolbar slot="toolbar"> <SbToolbar slot="toolbar">
@ -118,6 +130,7 @@ export default defineComponent({
eventUpdate={(updated: Block) => onChildUpdate(child, updated)} eventUpdate={(updated: Block) => onChildUpdate(child, updated)}
eventInsertBlock={(block: Block) => insertBlock(index, block)} eventInsertBlock={(block: Block) => insertBlock(index, block)}
eventAppendBlock={appendBlock} eventAppendBlock={appendBlock}
eventRemoveBlock={() => removeBlock(index)}
/> />
))} ))}

View file

@ -29,6 +29,7 @@ interface ParagraphProps extends BlockProps {
data: ParagraphData; data: ParagraphData;
eventUpdate: (b?: ParagraphData) => void; eventUpdate: (b?: ParagraphData) => void;
eventInsertBlock: (b?: BlockData) => void; eventInsertBlock: (b?: BlockData) => void;
eventRemoveBlock: () => void;
} }
export default defineComponent({ export default defineComponent({
@ -44,6 +45,7 @@ export default defineComponent({
}, },
eventUpdate: { type: Function, default: () => {} }, eventUpdate: { type: Function, default: () => {} },
eventInsertBlock: { type: Function, default: () => {} }, eventInsertBlock: { type: Function, default: () => {} },
eventRemoveBlock: { type: Function, default: () => {} },
}, },
setup(props: ParagraphProps) { setup(props: ParagraphProps) {
@ -61,16 +63,21 @@ export default defineComponent({
const { isActive, activate } = useActivation(props.blockId); const { isActive, activate } = useActivation(props.blockId);
const focusInput = () => {
if (inputEl.value && isActive.value) {
inputEl.value.focus();
}
};
onMounted(() => { onMounted(() => {
focusInput();
if (inputEl.value) { if (inputEl.value) {
inputEl.value.innerHTML = localData.value; inputEl.value.innerHTML = localData.value;
if (isActive.value) {
inputEl.value.focus();
}
} }
}); });
watch(isActive, focusInput);
watch(() => props.data, () => { watch(() => props.data, () => {
localData.value = props.data.value; localData.value = props.data.value;
localData.align = props.data.align; localData.align = props.data.align;
@ -110,8 +117,8 @@ export default defineComponent({
activate(null); activate(null);
}; };
const onKeypress = ($event: KeyboardEvent) => { const onKeyup = ($event: KeyboardEvent) => {
if ($event.key === 'Enter') { if ($event.key === 'Enter' && !$event.shiftKey) {
const blockId = `${+(new Date())}`; const blockId = `${+(new Date())}`;
props.eventInsertBlock({ props.eventInsertBlock({
blockId, blockId,
@ -122,6 +129,8 @@ export default defineComponent({
activate(blockId); activate(blockId);
$event.preventDefault(); $event.preventDefault();
} else if ($event.key === 'Backspace' && localData.value === '') {
props.eventRemoveBlock();
} }
}; };
@ -144,7 +153,7 @@ export default defineComponent({
onInput={onTextUpdate} onInput={onTextUpdate}
onFocus={onFocus} onFocus={onFocus}
onBlur={onBlur} onBlur={onBlur}
onKeypress={onKeypress} onKeyup={onKeyup}
></p> ></p>
</div> </div>
); );