fix(editor,stage,ui,runtime): 流式布局下,height自动设置成auto

fix #298
This commit is contained in:
roymondchen 2022-08-30 17:37:39 +08:00 committed by jia000
parent 9e167474a2
commit 2201fbe80c
19 changed files with 163 additions and 63 deletions

View File

@ -31,7 +31,7 @@
<template #props-panel> <template #props-panel>
<slot name="props-panel"> <slot name="props-panel">
<props-panel ref="propsPanel" @mounted="(instance: any) => $emit('props-panel-mounted', instance)"> <props-panel @mounted="(instance: any) => $emit('props-panel-mounted', instance)">
<template #props-panel-header> <template #props-panel-header>
<slot name="props-panel-header"></slot> <slot name="props-panel-header"></slot>
</template> </template>

View File

@ -2,9 +2,9 @@
<div class="`m-editor-props-panel"> <div class="`m-editor-props-panel">
<slot name="props-panel-header"></slot> <slot name="props-panel-header"></slot>
<m-form <m-form
ref="configForm"
:class="`m-editor-props-panel ${propsPanelSize}`" :class="`m-editor-props-panel ${propsPanelSize}`"
:popper-class="`m-editor-props-panel-popper ${propsPanelSize}`" :popper-class="`m-editor-props-panel-popper ${propsPanelSize}`"
ref="configForm"
:size="propsPanelSize" :size="propsPanelSize"
:init-values="values" :init-values="values"
:config="curFormConfig" :config="curFormConfig"
@ -13,21 +13,18 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { computed, defineComponent, getCurrentInstance, inject, onMounted, ref, watchEffect } from 'vue'; import { computed, getCurrentInstance, inject, onMounted, ref, watchEffect } from 'vue';
import { ElMessage } from 'element-plus'; import { ElMessage } from 'element-plus';
import type { FormValue, MForm } from '@tmagic/form'; import type { FormValue, MForm } from '@tmagic/form';
import type { MNode } from '@tmagic/schema'; import type { MNode } from '@tmagic/schema';
import type StageCore from '@tmagic/stage';
import type { Services } from '../type'; import type { Services } from '../type';
export default defineComponent({ const emit = defineEmits(['mounted']);
name: 'm-editor-props-panel',
emits: ['mounted'],
setup(props, { emit }) {
const internalInstance = getCurrentInstance(); const internalInstance = getCurrentInstance();
const values = ref<FormValue>({}); const values = ref<FormValue>({});
const configForm = ref<InstanceType<typeof MForm>>(); const configForm = ref<InstanceType<typeof MForm>>();
@ -35,6 +32,8 @@ export default defineComponent({
const curFormConfig = ref<any>([]); const curFormConfig = ref<any>([]);
const services = inject<Services>('services'); const services = inject<Services>('services');
const node = computed(() => services?.editorService.get<MNode | null>('node')); const node = computed(() => services?.editorService.get<MNode | null>('node'));
const propsPanelSize = computed(() => services?.uiService.get('propsPanelSize') || 'small');
const stage = computed(() => services?.editorService.get<StageCore>('stage'));
const init = async () => { const init = async () => {
if (!node.value) { if (!node.value) {
@ -54,13 +53,13 @@ export default defineComponent({
emit('mounted', internalInstance); emit('mounted', internalInstance);
}); });
return { watchEffect(() => {
values, if (configForm.value && stage.value) {
configForm, configForm.value.formState.stage = stage.value;
curFormConfig, }
propsPanelSize: computed(() => services?.uiService.get('propsPanelSize') || 'small'), });
async submit() { const submit = async () => {
try { try {
const values = await configForm.value?.submitForm(); const values = await configForm.value?.submitForm();
services?.editorService.update(values); services?.editorService.update(values);
@ -74,8 +73,7 @@ export default defineComponent({
dangerouslyUseHTMLString: true, dangerouslyUseHTMLString: true,
}); });
} }
},
}; };
},
}); defineExpose({ submit });
</script> </script>

View File

@ -519,6 +519,7 @@ export default class StageDragResize extends EventEmitter {
const isAbsolute = this.mode === Mode.ABSOLUTE; const isAbsolute = this.mode === Mode.ABSOLUTE;
const isFixed = this.mode === Mode.FIXED; const isFixed = this.mode === Mode.FIXED;
const isSortable = this.mode === Mode.SORTABLE;
let { moveableOptions = {} } = this.core.config; let { moveableOptions = {} } = this.core.config;
@ -573,7 +574,7 @@ export default class StageDragResize extends EventEmitter {
// 设置0的话无法移动到left为0所以只能设置为-1 // 设置0的话无法移动到left为0所以只能设置为-1
left: -1, left: -1,
right: this.container.clientWidth - 1, right: this.container.clientWidth - 1,
bottom: this.container.clientHeight, bottom: isSortable ? undefined : this.container.clientHeight,
...(moveableOptions.bounds || {}), ...(moveableOptions.bounds || {}),
}, },
...options, ...options,

View File

@ -9,3 +9,7 @@
opacity: .1; opacity: .1;
pointer-events: none; pointer-events: none;
} }
.magic-ui-container.magic-layout-relative {
min-height: 50px;
}

View File

@ -37,7 +37,7 @@ const Container: React.FC<ContainerProps> = ({ config, id }) => {
return ( return (
<div <div
id={`${id || config.id || ''}`} id={`${id || config.id || ''}`}
className={`magic-ui-container${config.className ? ` ${config.className}` : ''}`} className={`magic-ui-container magic-layout-${config.layout}${config.className ? ` ${config.className}` : ''}`}
style={app.transformStyle(config.style || {})} style={app.transformStyle(config.style || {})}
> >
{config.items?.map((item: MComponent | MContainer) => { {config.items?.map((item: MComponent | MContainer) => {

View File

@ -26,5 +26,16 @@ export default [
{ value: 'absolute', text: '绝对定位' }, { value: 'absolute', text: '绝对定位' },
{ value: 'relative', text: '流式布局' }, { value: 'relative', text: '流式布局' },
], ],
onChange: (formState: any, v: string, { model }: any) => {
if (!model.style) return v;
if (v === 'relative') {
model.style.height = 'auto';
} else {
const el = formState.stage?.renderer?.contentWindow.document.getElementById(model.id);
if (el) {
model.style.height = el.getBoundingClientRect().height;
}
}
},
}, },
]; ];

View File

@ -39,7 +39,9 @@ const Page: React.FC<PageProps> = ({ config }) => {
return ( return (
<div <div
id={`${config.id || ''}`} id={`${config.id || ''}`}
className={`magic-ui-page magic-ui-container${config.className ? ` ${config.className}` : ''}`} className={`magic-ui-page magic-ui-container magic-layout-${config.layout}${
config.className ? ` ${config.className}` : ''
}`}
style={app.transformStyle(config.style || {})} style={app.transformStyle(config.style || {})}
> >
{config.items?.map((item: MComponent | MContainer) => { {config.items?.map((item: MComponent | MContainer) => {

View File

@ -36,5 +36,16 @@ export default [
{ value: 'absolute', text: '绝对定位' }, { value: 'absolute', text: '绝对定位' },
{ value: 'relative', text: '流式布局' }, { value: 'relative', text: '流式布局' },
], ],
onChange: (formState: any, v: string, { model }: any) => {
if (!model.style) return v;
if (v === 'relative') {
model.style.height = 'auto';
} else {
const el = formState.stage?.renderer?.contentWindow.document.getElementById(model.id);
if (el) {
model.style.height = el.getBoundingClientRect().height;
}
}
},
}, },
]; ];

View File

@ -2,7 +2,7 @@
<div <div
v-if="display()" v-if="display()"
:id="config.id" :id="config.id"
:class="`magic-ui-container${config.className ? ` ${config.className}` : ''}`" :class="`magic-ui-container magic-layout-${config.layout}${config.className ? ` ${config.className}` : ''}`"
:style="style" :style="style"
> >
<slot></slot> <slot></slot>

View File

@ -26,5 +26,16 @@ export default [
{ value: 'absolute', text: '绝对定位' }, { value: 'absolute', text: '绝对定位' },
{ value: 'relative', text: '流式布局' }, { value: 'relative', text: '流式布局' },
], ],
onChange: (formState: any, v: string, { model }: any) => {
if (!model.style) return v;
if (v === 'relative') {
model.style.height = 'auto';
} else {
const el = formState.stage?.renderer?.contentWindow.document.getElementById(model.id);
if (el) {
model.style.height = el.getBoundingClientRect().height;
}
}
},
}, },
]; ];

View File

@ -16,4 +16,10 @@
* limitations under the License. * limitations under the License.
*/ */
export default {}; export default {
items: [],
style: {
width: '375',
height: '100',
},
};

View File

@ -1,7 +1,9 @@
<template> <template>
<div <div
:id="config.id" :id="config.id"
:class="`magic-ui-page magic-ui-container${config.className ? ` ${config.className}` : ''}`" :class="`magic-ui-page magic-ui-container magic-layout-${config.layout}${
config.className ? ` ${config.className}` : ''
}`"
:style="style" :style="style"
> >
<slot></slot> <slot></slot>

View File

@ -36,5 +36,16 @@ export default [
{ value: 'absolute', text: '绝对定位' }, { value: 'absolute', text: '绝对定位' },
{ value: 'relative', text: '流式布局' }, { value: 'relative', text: '流式布局' },
], ],
onChange: (formState: any, v: string, { model }: any) => {
if (!model.style) return v;
if (v === 'relative') {
model.style.height = 'auto';
} else {
const el = formState.stage?.renderer?.contentWindow.document.getElementById(model.id);
if (el) {
model.style.height = el.getBoundingClientRect().height;
}
}
},
}, },
]; ];

View File

@ -2,7 +2,7 @@
<div <div
v-if="display()" v-if="display()"
:id="`${config.id || ''}`" :id="`${config.id || ''}`"
:class="`magic-ui-container${config.className ? ` ${config.className}` : ''}`" :class="`magic-ui-container magic-layout-${config.layout}${config.className ? ` ${config.className}` : ''}`"
:style="style" :style="style"
> >
<slot></slot> <slot></slot>

View File

@ -26,5 +26,16 @@ export default [
{ value: 'absolute', text: '绝对定位' }, { value: 'absolute', text: '绝对定位' },
{ value: 'relative', text: '流式布局' }, { value: 'relative', text: '流式布局' },
], ],
onChange: (formState: any, v: string, { model }: any) => {
if (!model.style) return v;
if (v === 'relative') {
model.style.height = 'auto';
} else {
const el = formState.stage?.renderer?.contentWindow.document.getElementById(model.id);
if (el) {
model.style.height = el.getBoundingClientRect().height;
}
}
},
}, },
]; ];

View File

@ -36,5 +36,16 @@ export default [
{ value: 'absolute', text: '绝对定位' }, { value: 'absolute', text: '绝对定位' },
{ value: 'relative', text: '流式布局' }, { value: 'relative', text: '流式布局' },
], ],
onChange: (formState: any, v: string, { model }: any) => {
if (!model.style) return v;
if (v === 'relative') {
model.style.height = 'auto';
} else {
const el = formState.stage?.renderer?.contentWindow.document.getElementById(model.id);
if (el) {
model.style.height = el.getBoundingClientRect().height;
}
}
},
}, },
]; ];

View File

@ -1,7 +1,9 @@
<template> <template>
<div <div
:id="`${config.id || ''}`" :id="`${config.id || ''}`"
:class="`magic-ui-page magic-ui-container${config.className ? ` ${config.className}` : ''}`" :class="`magic-ui-page magic-ui-container magic-layout-${config.layout}${
config.className ? ` ${config.className}` : ''
}`"
:style="style" :style="style"
> >
<slot></slot> <slot></slot>

View File

@ -67,10 +67,14 @@ export default defineComponent({
add({ config, parentId }: UpdateData) { add({ config, parentId }: UpdateData) {
console.log('add config', config); console.log('add config', config);
if (!root.value) throw new Error('error'); if (!root.value) throw new Error('error');
if (!selectedId.value) throw new Error('error'); if (!selectedId.value) throw new Error('error');
if (!parentId) throw new Error('error');
const parent = getNodePath(parentId, [root.value]).pop(); const parent = getNodePath(parentId, [root.value]).pop();
if (!parent) throw new Error('未找到父节点'); if (!parent) throw new Error('未找到父节点');
if (parent.id !== selectedId.value) { if (parent.id !== selectedId.value) {
const index = parent.items?.findIndex((child: MNode) => child.id === selectedId.value); const index = parent.items?.findIndex((child: MNode) => child.id === selectedId.value);
parent.items?.splice(index + 1, 0, config); parent.items?.splice(index + 1, 0, config);
@ -82,11 +86,16 @@ export default defineComponent({
update({ config, parentId }: UpdateData) { update({ config, parentId }: UpdateData) {
console.log('update config', config); console.log('update config', config);
if (!root.value) throw new Error('error'); if (!root.value) throw new Error('error');
const node = getNodePath(config.id, [root.value]).pop(); const node = getNodePath(config.id, [root.value]).pop();
const parent = getNodePath(parentId, [root.value]).pop();
if (!node) throw new Error('未找到目标节点'); if (!node) throw new Error('未找到目标节点');
if (!parentId) throw new Error('error');
const parent = getNodePath(parentId, [root.value]).pop();
if (!parent) throw new Error('未找到父节点'); if (!parent) throw new Error('未找到父节点');
const index = parent.items?.findIndex((child: MNode) => child.id === node.id); const index = parent.items?.findIndex((child: MNode) => child.id === node.id);
parent.items.splice(index, 1, reactive(config)); parent.items.splice(index, 1, reactive(config));
}, },

View File

@ -67,8 +67,11 @@ export default defineComponent({
add({ config, parentId }: UpdateData) { add({ config, parentId }: UpdateData) {
console.log('add config', config); console.log('add config', config);
if (!root.value) throw new Error('error'); if (!root.value) throw new Error('error');
if (!selectedId.value) throw new Error('error'); if (!selectedId.value) throw new Error('error');
if (!parentId) throw new Error('error');
const parent = getNodePath(parentId, [root.value]).pop(); const parent = getNodePath(parentId, [root.value]).pop();
if (!parent) throw new Error('未找到父节点'); if (!parent) throw new Error('未找到父节点');
if (parent.id !== selectedId.value) { if (parent.id !== selectedId.value) {
@ -82,9 +85,13 @@ export default defineComponent({
update({ config, parentId }: UpdateData) { update({ config, parentId }: UpdateData) {
console.log('update config', config); console.log('update config', config);
if (!root.value) throw new Error('error'); if (!root.value) throw new Error('error');
const node = getNodePath(config.id, [root.value]).pop(); const node = getNodePath(config.id, [root.value]).pop();
if (!parentId) throw new Error('error');
const parent = getNodePath(parentId, [root.value]).pop(); const parent = getNodePath(parentId, [root.value]).pop();
if (!node) throw new Error('未找到目标节点'); if (!node) throw new Error('未找到目标节点');
if (!parent) throw new Error('未找到父节点'); if (!parent) throw new Error('未找到父节点');
const index = parent.items?.findIndex((child: MNode) => child.id === node.id); const index = parent.items?.findIndex((child: MNode) => child.id === node.id);
@ -93,10 +100,13 @@ export default defineComponent({
remove({ id, parentId }: RemoveData) { remove({ id, parentId }: RemoveData) {
if (!root.value) throw new Error('error'); if (!root.value) throw new Error('error');
const node = getNodePath(id, [root.value]).pop(); const node = getNodePath(id, [root.value]).pop();
if (!node) throw new Error('未找到目标元素'); if (!node) throw new Error('未找到目标元素');
const parent = getNodePath(parentId, [root.value]).pop(); const parent = getNodePath(parentId, [root.value]).pop();
if (!parent) throw new Error('未找到父元素'); if (!parent) throw new Error('未找到父元素');
const index = parent.items?.findIndex((child: MNode) => child.id === node.id); const index = parent.items?.findIndex((child: MNode) => child.id === node.id);
parent.items.splice(index, 1); parent.items.splice(index, 1);
}, },