2022-03-15 19:58:11 +00:00
|
|
|
import {
|
|
|
|
onBeforeMount,
|
|
|
|
computed,
|
|
|
|
defineComponent,
|
|
|
|
reactive,
|
|
|
|
ref,
|
|
|
|
} from 'vue';
|
|
|
|
|
|
|
|
import { SbMain, IBlockData, SbMode } from '@schlechtenburg/core';
|
|
|
|
|
|
|
|
import SbLayout from '@schlechtenburg/layout';
|
|
|
|
import SbHeading from '@schlechtenburg/heading';
|
|
|
|
import SbParagraph from '@schlechtenburg/paragraph';
|
|
|
|
import SbImage from '@schlechtenburg/image';
|
|
|
|
|
2022-03-17 17:59:51 +00:00
|
|
|
import exampleData from './example-data';
|
|
|
|
|
|
|
|
import './ExampleEditor.scss';
|
2022-03-15 19:58:11 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
2022-03-17 17:59:51 +00:00
|
|
|
name: 'ExampleEditor',
|
2022-03-15 19:58:11 +00:00
|
|
|
|
|
|
|
setup() {
|
|
|
|
const activeTab = ref('edit');
|
2022-03-17 17:59:51 +00:00
|
|
|
const block: IBlockData<any> = reactive({ ...exampleData });
|
2022-03-15 19:58:11 +00:00
|
|
|
|
|
|
|
const displayedElement = computed(() => {
|
|
|
|
switch (activeTab.value) {
|
|
|
|
case SbMode.Edit:
|
|
|
|
return <SbMain
|
2022-03-17 17:59:51 +00:00
|
|
|
class="example-editor--sb"
|
2022-03-15 19:58:11 +00:00
|
|
|
block={block}
|
|
|
|
onUpdate={(newBlock: IBlockData<any>) => {
|
|
|
|
block.data = newBlock.data;
|
|
|
|
}}
|
|
|
|
availableBlocks={[
|
|
|
|
SbLayout,
|
|
|
|
SbHeading,
|
|
|
|
SbImage,
|
|
|
|
SbParagraph,
|
|
|
|
]}
|
|
|
|
key="edit"
|
|
|
|
mode={SbMode.Edit}
|
|
|
|
/>;
|
|
|
|
case SbMode.Display:
|
|
|
|
return <SbMain
|
2022-03-17 17:59:51 +00:00
|
|
|
class="example-editor--sb"
|
2022-03-15 19:58:11 +00:00
|
|
|
block={block}
|
|
|
|
availableBlocks={[
|
|
|
|
SbLayout,
|
|
|
|
SbHeading,
|
|
|
|
SbImage,
|
|
|
|
SbParagraph,
|
|
|
|
]}
|
|
|
|
key="display"
|
|
|
|
mode={SbMode.Display}
|
|
|
|
/>;
|
|
|
|
case 'data':
|
|
|
|
return <pre><code>{ JSON.stringify(block, null, 2) }</code></pre>;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return () => {
|
2022-03-17 17:59:51 +00:00
|
|
|
return <div class="example-editor">
|
|
|
|
<h2 class="example-editor--title">
|
|
|
|
<span>Try it yourself</span>
|
|
|
|
<select
|
|
|
|
class="example-editor--mode"
|
|
|
|
value={activeTab.value}
|
|
|
|
onChange={($event: Event) => {
|
|
|
|
activeTab.value = ($event.target as HTMLSelectElement).value;
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<option value="edit">Editor mode</option>
|
|
|
|
<option value="display">Display mode</option>
|
|
|
|
<option value="data">JSON Data structure</option>
|
|
|
|
</select>
|
|
|
|
</h2>
|
2022-03-15 19:58:11 +00:00
|
|
|
{displayedElement.value}
|
|
|
|
</div>;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|