diff --git a/packages/core/lib/blocks.ts b/packages/core/lib/blocks.ts
index c25c949..4b0a2be 100644
--- a/packages/core/lib/blocks.ts
+++ b/packages/core/lib/blocks.ts
@@ -1,10 +1,18 @@
import { Component } from 'vue';
+export interface BlockTree {
+ name: string;
+ icon?: string;
+ children?: BlockTree[];
+}
+
export interface BlockDefinition {
name: string;
+ icon?: string;
getDefaultData: any;
edit: Component;
display: Component;
+ getChildren?: (block: Block) => Block[],
}
export interface BlockLibraryDefinition {
diff --git a/packages/core/lib/components/Block.tsx b/packages/core/lib/components/Block.tsx
index 2e62b01..e47dc41 100644
--- a/packages/core/lib/components/Block.tsx
+++ b/packages/core/lib/components/Block.tsx
@@ -73,7 +73,7 @@ export const SbBlock = defineComponent({
};
return () => {
- const BlockComponent = getBlock(props.block.name) as any;
+ const BlockComponent = getBlock(props.block.name)?.[mode.value] as any;
if (!BlockComponent) {
const MissingBlock = SbMissingBlock[mode.value];
@@ -84,12 +84,10 @@ export const SbBlock = defineComponent({
}
if (mode.value === SbMode.Display) {
- return () => (
-
- );
+ return ;
}
return
(
Missing block: {props.name}
diff --git a/packages/core/lib/components/ContextMenu.scss b/packages/core/lib/components/ContextMenu.scss
index e69de29..6630898 100644
--- a/packages/core/lib/components/ContextMenu.scss
+++ b/packages/core/lib/components/ContextMenu.scss
@@ -0,0 +1,18 @@
+.sb-context {
+ position: relative;
+}
+
+.sb-context-menu {
+ display: none;
+ flex-direction: column;
+ background: var(--grey-0);
+ border: 1px solid var(--grey-3);
+ top: 100%;
+ left: 0;
+ margin: 0;
+ z-index: var(--z-context-menu);
+
+ &[open] {
+ display: flex;
+ }
+}
diff --git a/packages/core/lib/components/ContextMenu.tsx b/packages/core/lib/components/ContextMenu.tsx
index b909200..fc62850 100644
--- a/packages/core/lib/components/ContextMenu.tsx
+++ b/packages/core/lib/components/ContextMenu.tsx
@@ -23,28 +23,33 @@ export const SbContextMenu = defineComponent({
setup(props: ContextMenuProps, context) {
const opened = ref(false);
- const close = () => { opened.value = false; }
+ const open = () => { opened.value = true; };
+ const close = () => { opened.value = false; };
const closeOnEscape = ($event: KeyboardEvent) => {
if ($event.key === 'Escape') {
close();
}
};
- const open = () => {
- opened.value = true;
- document.addEventListener('click', close);
- document.addEventListener('keypress', closeOnEscape);
- }
- const toggle = () => { opened.value = !opened.value; }
+ const toggle = () => { opened.value ? close() : open() };
- watch(opened, () => {
- if (!opened.value) {
- document.removeEventListener('click', close);
- document.removeEventListener('keypress', closeOnEscape);
+ watch(opened, (curr, prev) => {
+ if (curr === prev) {
+ return;
+ }
+
+ if (!curr) {
+ document.body.removeEventListener('click', close);
+ document.body.removeEventListener('keypress', closeOnEscape);
+ } else {
+ setTimeout(() => {
+ document.body.addEventListener('click', close);
+ document.body.addEventListener('keypress', closeOnEscape);
+ });
}
});
return () => (
-