|
@@ -11,7 +11,7 @@ export const View = defineComponent({
|
|
|
layout: any<Layout>(),
|
|
|
},
|
|
|
setup(props, { slots }) {
|
|
|
- const { store, actions } = useEditor();
|
|
|
+ const { store, actions, helper } = useEditor();
|
|
|
const viewRef = ref<HTMLElement>();
|
|
|
const state = reactive({
|
|
|
compId: "",
|
|
@@ -20,16 +20,47 @@ export const View = defineComponent({
|
|
|
const compEl = viewRef.value;
|
|
|
state.compId = compEl?.getAttribute("data-id") || "";
|
|
|
});
|
|
|
+
|
|
|
+ function createStyle(): any {
|
|
|
+ const style: any = {};
|
|
|
+ const { textAlign, offsetY, zIndex } = props.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 (zIndex) {
|
|
|
+ style["zIndex"] = zIndex;
|
|
|
+ }
|
|
|
+ return style;
|
|
|
+ }
|
|
|
+
|
|
|
+ function createContentStyle() {
|
|
|
+ const style: any = {};
|
|
|
+ const { background, layout } = props;
|
|
|
+ const [w, h] = (layout?.size as number[]) || [];
|
|
|
+ if (background?.image) {
|
|
|
+ style["backgroundImage"] = `url(${background.image})`;
|
|
|
+ } else if (background?.color) {
|
|
|
+ style["backgroundColor"] = background.color;
|
|
|
+ }
|
|
|
+ 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
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ return style;
|
|
|
+ }
|
|
|
+
|
|
|
return () => {
|
|
|
const isComp = state.compId;
|
|
|
const isSelected = store.isEditMode && store.currCompId === state.compId;
|
|
|
|
|
|
- const styleObj: any = {};
|
|
|
- if (props.background?.image) {
|
|
|
- styleObj["backgroundImage"] = `url(${props.background.image})`;
|
|
|
- } else if (props.background?.color) {
|
|
|
- styleObj["backgroundColor"] = props.background.color;
|
|
|
- }
|
|
|
const bgOpts = Object.values(omit(props.background, ["image", "color"]));
|
|
|
const bgClasses = bgOpts.length ? `bg-${bgOpts.join(" bg-")}` : "";
|
|
|
|
|
@@ -41,7 +72,7 @@ export const View = defineComponent({
|
|
|
store.isEditMode && isSelected && "view_selected",
|
|
|
bgClasses,
|
|
|
]}
|
|
|
- style={styleObj}
|
|
|
+ style={createStyle()}
|
|
|
onClick={
|
|
|
state.compId
|
|
|
? () => {
|
|
@@ -51,7 +82,9 @@ export const View = defineComponent({
|
|
|
: undefined
|
|
|
}
|
|
|
>
|
|
|
- {slots.default?.()}
|
|
|
+ <div class={viewContainerStyle} style={createContentStyle()}>
|
|
|
+ {slots.default?.()}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
);
|
|
|
};
|
|
@@ -88,3 +121,9 @@ const viewStyle = css`
|
|
|
position: relative;
|
|
|
}
|
|
|
`;
|
|
|
+
|
|
|
+const viewContainerStyle = css`
|
|
|
+ display: inline-block;
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+`;
|