|
@@ -1,25 +1,18 @@
|
|
|
import { css } from "@linaria/core";
|
|
|
import { omit } from "lodash";
|
|
|
-import { defineComponent, onMounted, reactive, ref } from "vue";
|
|
|
-import { any } from "vue-types";
|
|
|
+import { defineComponent } from "vue";
|
|
|
+import { any, string } from "vue-types";
|
|
|
import { useEditor } from "../../..";
|
|
|
import { Background, Layout } from "../../../typings";
|
|
|
|
|
|
export const View = defineComponent({
|
|
|
props: {
|
|
|
+ compId: string(),
|
|
|
background: any<Background>(),
|
|
|
layout: any<Layout>(),
|
|
|
},
|
|
|
setup(props, { slots }) {
|
|
|
const { store, actions, helper } = useEditor();
|
|
|
- const viewRef = ref<HTMLElement>();
|
|
|
- const state = reactive({
|
|
|
- compId: "",
|
|
|
- });
|
|
|
- onMounted(() => {
|
|
|
- const compEl = viewRef.value;
|
|
|
- state.compId = compEl?.getAttribute("data-id") || "";
|
|
|
- });
|
|
|
|
|
|
function createStyle(): any {
|
|
|
const style: any = {};
|
|
@@ -58,34 +51,32 @@ export const View = defineComponent({
|
|
|
}
|
|
|
|
|
|
return () => {
|
|
|
- const isComp = state.compId;
|
|
|
- const isSelected = store.isEditMode && store.currCompId === state.compId;
|
|
|
+ const isComp = !!props.compId;
|
|
|
+ const isSelected = isComp && store.currCompId === props.compId;
|
|
|
|
|
|
const bgOpts = Object.values(omit(props.background, ["image", "color"]));
|
|
|
const bgClasses = bgOpts.length ? `bg-${bgOpts.join(" bg-")}` : "";
|
|
|
|
|
|
- return (
|
|
|
+ return isComp ? (
|
|
|
<div
|
|
|
- ref={viewRef}
|
|
|
class={[
|
|
|
- store.isEditMode && isComp ? viewStyle : "view_inside",
|
|
|
+ store.isEditMode && viewStyle,
|
|
|
store.isEditMode && isSelected && "view_selected",
|
|
|
bgClasses,
|
|
|
]}
|
|
|
style={createStyle()}
|
|
|
onClick={
|
|
|
- state.compId
|
|
|
- ? () => {
|
|
|
- if (state.compId !== store.currCompId)
|
|
|
- actions.pickCurrComp(state.compId);
|
|
|
- }
|
|
|
+ isComp && !isSelected
|
|
|
+ ? () => actions.pickCurrComp(props.compId as string)
|
|
|
: undefined
|
|
|
}
|
|
|
>
|
|
|
- <div class={viewContainerStyle} style={createContentStyle()}>
|
|
|
+ <div class="view_content" style={createContentStyle()}>
|
|
|
{slots.default?.()}
|
|
|
</div>
|
|
|
</div>
|
|
|
+ ) : (
|
|
|
+ <div class="view_inside">{slots.default?.()}</div>
|
|
|
);
|
|
|
};
|
|
|
},
|
|
@@ -93,24 +84,34 @@ export const View = defineComponent({
|
|
|
|
|
|
const viewStyle = css`
|
|
|
position: relative;
|
|
|
- &:hover {
|
|
|
- outline: 1px dashed @inf-primary-color;
|
|
|
- }
|
|
|
|
|
|
> * {
|
|
|
pointer-events: none;
|
|
|
}
|
|
|
|
|
|
- &.view_selected {
|
|
|
- outline: 1px solid @inf-primary-color;
|
|
|
+ .view_content {
|
|
|
+ display: inline-block;
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+
|
|
|
+ &:hover {
|
|
|
+ outline: 1px dashed @inf-primary-color;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ &.view_selected {
|
|
|
> * {
|
|
|
pointer-events: auto;
|
|
|
}
|
|
|
+
|
|
|
&::after {
|
|
|
display: none;
|
|
|
}
|
|
|
|
|
|
+ .view_content {
|
|
|
+ outline: 1px solid @inf-primary-color;
|
|
|
+ }
|
|
|
+
|
|
|
.view_inside:hover {
|
|
|
outline: 1px dashed @inf-primary-color;
|
|
|
outline-offset: -1px;
|
|
@@ -121,9 +122,3 @@ const viewStyle = css`
|
|
|
position: relative;
|
|
|
}
|
|
|
`;
|
|
|
-
|
|
|
-const viewContainerStyle = css`
|
|
|
- display: inline-block;
|
|
|
- width: 100%;
|
|
|
- height: 100%;
|
|
|
-`;
|