|
@@ -1,38 +1,43 @@
|
|
|
import { css } from "@linaria/core";
|
|
|
import { omit, upperFirst } from "lodash";
|
|
|
import { defineComponent } from "vue";
|
|
|
-import { any, string } from "vue-types";
|
|
|
+import { string } from "vue-types";
|
|
|
import { useEditor } from "../../..";
|
|
|
-import { Background, Layout } from "../../../typings";
|
|
|
+import { DesignComp } from "../../../defines/DesignTemp/DesignComp";
|
|
|
|
|
|
export const View = defineComponent({
|
|
|
props: {
|
|
|
compId: string(),
|
|
|
- background: any<Background>(),
|
|
|
- layout: any<Layout>(),
|
|
|
},
|
|
|
setup(props, { slots }) {
|
|
|
const { store, actions, helper } = useEditor();
|
|
|
+ const comp =
|
|
|
+ (props.compId && store.designCompMap.get(props.compId)) ||
|
|
|
+ new DesignComp();
|
|
|
|
|
|
function createStyle(): any {
|
|
|
const style: any = {};
|
|
|
- const { textAlign, offsetY, zIndex } = props.layout || {};
|
|
|
+ const { textAlign, margin, zIndex } = comp.layout || {};
|
|
|
if (textAlign) {
|
|
|
style.textAlign = textAlign;
|
|
|
}
|
|
|
- if (offsetY) {
|
|
|
- style[`margin` + ((offsetY as number) > 0 ? "Top" : "Bottom")] =
|
|
|
- helper.designToNaturalSize(Math.abs(offsetY as number) * -1);
|
|
|
- }
|
|
|
+ // if (offsetY) {
|
|
|
+ // style[`margin` + ((offsetY as number) > 0 ? "Top" : "Bottom")] =
|
|
|
+ // helper.designToNaturalSize(Math.abs(offsetY as number) * -1);
|
|
|
+ // }
|
|
|
if (zIndex) {
|
|
|
style["zIndex"] = zIndex;
|
|
|
}
|
|
|
+
|
|
|
+ if (margin) {
|
|
|
+ style.margin = margin;
|
|
|
+ }
|
|
|
return style;
|
|
|
}
|
|
|
|
|
|
function createContentStyle() {
|
|
|
const style: any = {};
|
|
|
- const { background, layout } = props;
|
|
|
+ const { background, layout } = comp;
|
|
|
const [w, h] = (layout?.size as number[]) || [];
|
|
|
if (background) {
|
|
|
Object.entries(background).forEach(([key, value]) => {
|
|
@@ -41,16 +46,18 @@ export const View = defineComponent({
|
|
|
}
|
|
|
style["background" + upperFirst(key)] = value;
|
|
|
});
|
|
|
- console.log(style, background);
|
|
|
+ }
|
|
|
+ if (layout?.padding) {
|
|
|
+ style.padding = layout.padding;
|
|
|
}
|
|
|
|
|
|
if (w) style["width"] = helper.designToNaturalSize(w);
|
|
|
if (h) style["height"] = helper.designToNaturalSize(h);
|
|
|
- if (layout?.offsetX) {
|
|
|
- style["marginLeft"] = helper.designToNaturalSize(
|
|
|
- layout.offsetX as number
|
|
|
- );
|
|
|
- }
|
|
|
+ // if (layout?.offsetX) {
|
|
|
+ // style["marginLeft"] = helper.designToNaturalSize(
|
|
|
+ // layout.offsetX as number
|
|
|
+ // );
|
|
|
+ // }
|
|
|
|
|
|
return style;
|
|
|
}
|
|
@@ -59,22 +66,23 @@ export const View = defineComponent({
|
|
|
const isComp = !!props.compId;
|
|
|
const isSelected = isComp && store.currCompId === props.compId;
|
|
|
|
|
|
- const bgOpts = Object.values(omit(props.background, ["image", "color"]));
|
|
|
+ const bgOpts = Object.values(omit(comp.background, ["image", "color"]));
|
|
|
const bgClasses = bgOpts.length ? `bg-${bgOpts.join(" bg-")}` : "";
|
|
|
|
|
|
return isComp ? (
|
|
|
<div
|
|
|
class={[
|
|
|
- store.isEditMode && viewStyle,
|
|
|
+ viewStyle,
|
|
|
store.isEditMode && isSelected && "view_selected",
|
|
|
bgClasses,
|
|
|
]}
|
|
|
style={createStyle()}
|
|
|
- onClick={
|
|
|
- isComp && !isSelected
|
|
|
- ? () => actions.pickCurrComp(props.compId as string)
|
|
|
- : undefined
|
|
|
- }
|
|
|
+ onClick={(e) => {
|
|
|
+ e.stopPropagation();
|
|
|
+ if (isComp && !isSelected) {
|
|
|
+ actions.pickCurrComp(props.compId as string);
|
|
|
+ }
|
|
|
+ }}
|
|
|
>
|
|
|
<div class="view_content" style={createContentStyle()}>
|
|
|
{slots.default?.()}
|
|
@@ -89,10 +97,7 @@ export const View = defineComponent({
|
|
|
|
|
|
const viewStyle = css`
|
|
|
position: relative;
|
|
|
-
|
|
|
- > * {
|
|
|
- pointer-events: none;
|
|
|
- }
|
|
|
+ font-size: 0;
|
|
|
|
|
|
.view_content {
|
|
|
display: inline-block;
|
|
@@ -106,15 +111,7 @@ const viewStyle = css`
|
|
|
}
|
|
|
|
|
|
&.view_selected {
|
|
|
- > * {
|
|
|
- pointer-events: auto;
|
|
|
- }
|
|
|
-
|
|
|
- &::after {
|
|
|
- display: none;
|
|
|
- }
|
|
|
-
|
|
|
- .view_content {
|
|
|
+ > .view_content {
|
|
|
outline: 1px solid @inf-primary-color;
|
|
|
}
|
|
|
|