2020-05-28 20:16:35 +00:00
|
|
|
import debounce from 'lodash-es/debounce';
|
|
|
|
import {
|
|
|
|
watch,
|
|
|
|
reactive,
|
|
|
|
computed,
|
2020-12-27 21:32:43 +00:00
|
|
|
defineAsyncComponent,
|
|
|
|
} from 'vue';
|
2020-05-28 20:16:35 +00:00
|
|
|
import {
|
|
|
|
useBlockSizing,
|
2020-12-27 21:32:43 +00:00
|
|
|
} from '/@components/TreeElement';
|
2020-05-28 20:16:35 +00:00
|
|
|
|
|
|
|
import SbButton from './Button';
|
|
|
|
|
|
|
|
import './BlockOrdering.scss';
|
|
|
|
|
2020-12-27 21:32:43 +00:00
|
|
|
export default defineAsyncComponent({
|
2020-05-28 20:16:35 +00:00
|
|
|
name: 'sb-block-ordering',
|
|
|
|
|
|
|
|
props: {
|
|
|
|
sortable: {
|
|
|
|
type: String,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
eventRemoveBlock: { type: Function, default: () => {} },
|
|
|
|
eventMoveUp: { type: Function, default: () => {} },
|
|
|
|
eventMoveDown: { type: Function, default: () => {} },
|
|
|
|
},
|
|
|
|
|
|
|
|
setup(props) {
|
|
|
|
const styles = reactive({
|
|
|
|
top: '',
|
|
|
|
right: '',
|
|
|
|
});
|
|
|
|
|
|
|
|
const classes = computed(() => ({
|
|
|
|
'sb-block-ordering': true,
|
|
|
|
[`sb-block-ordering_${props.sortable}`]: !!props.sortable,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const { editorDimensions, blockDimensions } = useBlockSizing();
|
|
|
|
const resetStyles = debounce(() => {
|
|
|
|
if (!editorDimensions.value || !blockDimensions.value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const right = editorDimensions.value.width - blockDimensions.value.left;
|
|
|
|
styles.top = `${blockDimensions.value.top}px`;
|
|
|
|
styles.right = `${right}px`;
|
|
|
|
});
|
|
|
|
watch(editorDimensions, resetStyles);
|
|
|
|
watch(blockDimensions, resetStyles);
|
|
|
|
watch(() => props.sortable, resetStyles);
|
|
|
|
|
|
|
|
return () => (
|
|
|
|
<div
|
|
|
|
class={classes.value}
|
|
|
|
style={styles}
|
2020-05-28 20:55:03 +00:00
|
|
|
onClick={($event: MouseEvent) => $event.stopPropagation()}
|
2020-05-28 20:16:35 +00:00
|
|
|
>
|
|
|
|
<SbButton onClick={props.eventMoveUp}>{props.sortable === 'vertical' ? '↑' : '←'}</SbButton>
|
|
|
|
<SbButton onClick={props.eventRemoveBlock}>x</SbButton>
|
|
|
|
<SbButton onClick={props.eventMoveDown}>{props.sortable === 'vertical' ? '↓' : '→'}</SbButton>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|