Skip to content

Commit

Permalink
fix(editor): 已经配置了的样式无法删除
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Jan 17, 2025
1 parent e9c6a3b commit e8461f9
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 28 deletions.
5 changes: 4 additions & 1 deletion packages/editor/src/fields/StyleSetter/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ defineOptions({
name: 'MFieldsStyleSetter',
});
defineProps<FieldProps<StyleSchema>>();
const props = defineProps<FieldProps<StyleSchema>>();
const emit = defineEmits<{
change: [v: any, eventData: ContainerChangeEventData];
Expand Down Expand Up @@ -64,6 +64,9 @@ const collapseValue = shallowRef(
);
const change = (v: any, eventData: ContainerChangeEventData) => {
eventData.changeRecords?.forEach((record) => {
record.propPath = `${props.name}.${record.propPath}`;
});
emit('change', v, eventData);
};
</script>
58 changes: 37 additions & 21 deletions packages/editor/src/fields/StyleSetter/pro/Layout.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<MContainer :config="config" :model="values" @change="change"></MContainer>
<Box :model="values" @change="change"></Box>
<Box v-show="!['fixed', 'absolute'].includes(values.position)" :model="values" @change="change"></Box>
</template>

<script lang="ts" setup>
Expand Down Expand Up @@ -125,7 +125,7 @@ const config = {
},
{
name: 'height',
text: '宽度',
text: '高度',
labelWidth: '68px',
type: 'data-source-field-select',
fieldConfig: {
Expand All @@ -135,25 +135,41 @@ const config = {
],
},
{
type: 'data-source-field-select',
text: 'overflow',
name: 'overflow',
checkStrictly: false,
dataSourceFieldType: ['string'],
fieldConfig: {
type: 'select',
clearable: true,
allowCreate: true,
options: [
{ text: 'visible', value: 'visible' },
{ text: 'hidden', value: 'hidden' },
{ text: 'clip', value: 'clip' },
{ text: 'scroll', value: 'scroll' },
{ text: 'auto', value: 'auto' },
{ text: 'overlay', value: 'overlay' },
{ text: 'initial', value: 'initial' },
],
},
type: 'row',
items: [
{
type: 'data-source-field-select',
text: 'overflow',
name: 'overflow',
labelWidth: '68px',
checkStrictly: false,
dataSourceFieldType: ['string'],
fieldConfig: {
type: 'select',
clearable: true,
allowCreate: true,
options: [
{ text: 'visible', value: 'visible' },
{ text: 'hidden', value: 'hidden' },
{ text: 'clip', value: 'clip' },
{ text: 'scroll', value: 'scroll' },
{ text: 'auto', value: 'auto' },
{ text: 'overlay', value: 'overlay' },
{ text: 'initial', value: 'initial' },
],
},
},
{
type: 'data-source-field-select',
text: '透明度',
name: 'opacity',
labelWidth: '68px',
dataSourceFieldType: ['string', 'number'],
fieldConfig: {
type: 'text',
},
},
],
},
],
};
Expand Down
51 changes: 47 additions & 4 deletions packages/editor/src/fields/StyleSetter/pro/Position.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<template>
<MContainer :config="config" :model="values" @change="change"></MContainer>
<Position v-show="values['position'] !== 'static'" :model="values" @change="change"></Position>
</template>

<script lang="ts" setup>
import { ContainerChangeEventData, MContainer } from '@tmagic/form';
import type { StyleSchema } from '@tmagic/schema';
import Position from '../components/Position.vue';
defineProps<{ values: Partial<StyleSchema> }>();
const props = defineProps<{ values: Partial<StyleSchema> }>();
const emit = defineEmits<{
change: [v: string | StyleSchema, eventData: ContainerChangeEventData];
Expand All @@ -30,6 +27,52 @@ const config = {
})),
},
},
{
type: 'row',
labelWidth: '68px',
display: () => props.values.position !== 'static',
items: [
{
name: 'left',
type: 'data-source-field-select',
text: 'left',
fieldConfig: {
type: 'text',
},
},
{
name: 'top',
type: 'data-source-field-select',
text: 'top',
fieldConfig: {
type: 'text',
},
},
],
},
{
type: 'row',
labelWidth: '68px',
display: () => props.values.position !== 'static',
items: [
{
name: 'right',
type: 'data-source-field-select',
text: 'right',
fieldConfig: {
type: 'text',
},
},
{
name: 'bottom',
type: 'data-source-field-select',
text: 'bottom',
fieldConfig: {
type: 'text',
},
},
],
},
{
labelWidth: '68px',
name: 'zIndex',
Expand Down
9 changes: 8 additions & 1 deletion packages/editor/src/layouts/props-panel/PropsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ import { computed, inject, onBeforeUnmount, ref, useTemplateRef, watchEffect } f
import { Close, Sugar } from '@element-plus/icons-vue';
import type { OnDrag } from 'gesto';
import type { MNode } from '@tmagic/core';
import { type MNode } from '@tmagic/core';
import { TMagicButton } from '@tmagic/design';
import type { ContainerChangeEventData, FormState, FormValue } from '@tmagic/form';
import { setValueByKeyPath } from '@tmagic/utils';
import MIcon from '@editor/components/Icon.vue';
import Resizer from '@editor/components/Resizer.vue';
Expand Down Expand Up @@ -136,6 +137,12 @@ const submit = async (v: MNode, eventData?: ContainerChangeEventData) => {
newValue.style[key] = value;
}
});
eventData?.changeRecords?.forEach((record) => {
if (record.propPath?.startsWith('style') && record.value === '') {
setValueByKeyPath(record.propPath, record.value, newValue);
}
});
}
services?.editorService.update(newValue, { changeRecords: eventData?.changeRecords });
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/theme/style-setter/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.layout-box-container {
position: relative;
width: 100%;
height: 150px;
height: 130px;

.help-txt {
float: left;
Expand Down

0 comments on commit e8461f9

Please sign in to comment.