mirror of
				https://github.com/Tencent/tmagic-editor.git
				synced 2025-11-04 10:49:51 +08:00 
			
		
		
		
	fix(editor): content-menu没有响应式
This commit is contained in:
		
							parent
							
								
									131ae30bae
								
							
						
					
					
						commit
						c2e8a1caae
					
				@ -1,12 +1,12 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <framework :code-options="codeOptions">
 | 
					  <Framework :code-options="codeOptions">
 | 
				
			||||||
    <template #nav>
 | 
					    <template #nav>
 | 
				
			||||||
      <slot name="nav" :editorService="editorService"><nav-menu :data="menu"></nav-menu></slot>
 | 
					      <slot name="nav" :editorService="editorService"><NavMenu :data="menu"></NavMenu></slot>
 | 
				
			||||||
    </template>
 | 
					    </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <template #sidebar>
 | 
					    <template #sidebar>
 | 
				
			||||||
      <slot name="sidebar" :editorService="editorService">
 | 
					      <slot name="sidebar" :editorService="editorService">
 | 
				
			||||||
        <sidebar :data="sidebar">
 | 
					        <Sidebar :data="sidebar" :layer-content-menu="layerContentMenu">
 | 
				
			||||||
          <template #layer-panel-header>
 | 
					          <template #layer-panel-header>
 | 
				
			||||||
            <slot name="layer-panel-header"></slot>
 | 
					            <slot name="layer-panel-header"></slot>
 | 
				
			||||||
          </template>
 | 
					          </template>
 | 
				
			||||||
@ -34,33 +34,33 @@
 | 
				
			|||||||
          <template #code-block-edit-panel-header="{ id }">
 | 
					          <template #code-block-edit-panel-header="{ id }">
 | 
				
			||||||
            <slot name="code-block-edit-panel-header" :id="id"></slot>
 | 
					            <slot name="code-block-edit-panel-header" :id="id"></slot>
 | 
				
			||||||
          </template>
 | 
					          </template>
 | 
				
			||||||
        </sidebar>
 | 
					        </Sidebar>
 | 
				
			||||||
      </slot>
 | 
					      </slot>
 | 
				
			||||||
    </template>
 | 
					    </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <template #workspace>
 | 
					    <template #workspace>
 | 
				
			||||||
      <slot name="workspace" :editorService="editorService">
 | 
					      <slot name="workspace" :editorService="editorService">
 | 
				
			||||||
        <workspace>
 | 
					        <Workspace :stage-content-menu="stageContentMenu">
 | 
				
			||||||
          <template #stage><slot name="stage"></slot></template>
 | 
					          <template #stage><slot name="stage"></slot></template>
 | 
				
			||||||
          <template #workspace-content><slot name="workspace-content" :editorService="editorService"></slot></template>
 | 
					          <template #workspace-content><slot name="workspace-content" :editorService="editorService"></slot></template>
 | 
				
			||||||
          <template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
 | 
					          <template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
 | 
				
			||||||
          <template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
 | 
					          <template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
 | 
				
			||||||
        </workspace>
 | 
					        </Workspace>
 | 
				
			||||||
      </slot>
 | 
					      </slot>
 | 
				
			||||||
    </template>
 | 
					    </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <template #props-panel>
 | 
					    <template #props-panel>
 | 
				
			||||||
      <slot name="props-panel">
 | 
					      <slot name="props-panel">
 | 
				
			||||||
        <props-panel @mounted="(instance: any) => $emit('props-panel-mounted', instance)">
 | 
					        <PropsPanel @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>
 | 
				
			||||||
        </props-panel>
 | 
					        </PropsPanel>
 | 
				
			||||||
      </slot>
 | 
					      </slot>
 | 
				
			||||||
    </template>
 | 
					    </template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <template #empty><slot name="empty" :editorService="editorService"></slot></template>
 | 
					    <template #empty><slot name="empty" :editorService="editorService"></slot></template>
 | 
				
			||||||
  </framework>
 | 
					  </Framework>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
@ -319,8 +319,6 @@ export default defineComponent({
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    provide('services', services);
 | 
					    provide('services', services);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    provide('layerContentMenu', props.layerContentMenu);
 | 
					 | 
				
			||||||
    provide('stageContentMenu', props.stageContentMenu);
 | 
					 | 
				
			||||||
    provide(
 | 
					    provide(
 | 
				
			||||||
      'stageOptions',
 | 
					      'stageOptions',
 | 
				
			||||||
      reactive({
 | 
					      reactive({
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,5 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <content-menu :menu-data="menuData" ref="menu" style="overflow: initial"></content-menu>
 | 
					  <ContentMenu :menu-data="menuData" ref="menu" style="overflow: initial"></ContentMenu>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script lang="ts" setup name="MEditorLayerMenu">
 | 
					<script lang="ts" setup name="MEditorLayerMenu">
 | 
				
			||||||
@ -11,6 +11,10 @@ import { NodeType } from '@tmagic/schema';
 | 
				
			|||||||
import ContentMenu from '../../components/ContentMenu.vue';
 | 
					import ContentMenu from '../../components/ContentMenu.vue';
 | 
				
			||||||
import type { ComponentGroup, MenuButton, MenuComponent, Services } from '../../type';
 | 
					import type { ComponentGroup, MenuButton, MenuComponent, Services } from '../../type';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const props = defineProps<{
 | 
				
			||||||
 | 
					  layerContentMenu: (MenuButton | MenuComponent)[];
 | 
				
			||||||
 | 
					}>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const services = inject<Services>('services');
 | 
					const services = inject<Services>('services');
 | 
				
			||||||
const menu = ref<InstanceType<typeof ContentMenu>>();
 | 
					const menu = ref<InstanceType<typeof ContentMenu>>();
 | 
				
			||||||
const node = computed(() => services?.editorService.get('node'));
 | 
					const node = computed(() => services?.editorService.get('node'));
 | 
				
			||||||
@ -18,8 +22,6 @@ const isRoot = computed(() => node.value?.type === NodeType.ROOT);
 | 
				
			|||||||
const isPage = computed(() => node.value?.type === NodeType.PAGE);
 | 
					const isPage = computed(() => node.value?.type === NodeType.PAGE);
 | 
				
			||||||
const componentList = computed(() => services?.componentListService.getList() || []);
 | 
					const componentList = computed(() => services?.componentListService.getList() || []);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const layerContentMenu = inject<(MenuComponent | MenuButton)[]>('layerContentMenu', []);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const createMenuItems = (group: ComponentGroup): MenuButton[] =>
 | 
					const createMenuItems = (group: ComponentGroup): MenuButton[] =>
 | 
				
			||||||
  group.items.map((component) => ({
 | 
					  group.items.map((component) => ({
 | 
				
			||||||
    text: component.text,
 | 
					    text: component.text,
 | 
				
			||||||
@ -97,7 +99,7 @@ const menuData = computed<(MenuButton | MenuComponent)[]>(() => [
 | 
				
			|||||||
      node.value && services?.editorService.remove(node.value);
 | 
					      node.value && services?.editorService.remove(node.value);
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  ...layerContentMenu,
 | 
					  ...props.layerContentMenu,
 | 
				
			||||||
]);
 | 
					]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const show = (e: MouseEvent) => {
 | 
					const show = (e: MouseEvent) => {
 | 
				
			||||||
 | 
				
			|||||||
@ -59,9 +59,9 @@
 | 
				
			|||||||
      </template>
 | 
					      </template>
 | 
				
			||||||
    </TMagicTree>
 | 
					    </TMagicTree>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <teleport to="body">
 | 
					    <Teleport to="body">
 | 
				
			||||||
      <layer-menu ref="menu"></layer-menu>
 | 
					      <LayerMenu ref="menu" :layer-content-menu="layerContentMenu"></LayerMenu>
 | 
				
			||||||
    </teleport>
 | 
					    </Teleport>
 | 
				
			||||||
  </TMagicScrollbar>
 | 
					  </TMagicScrollbar>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -76,11 +76,15 @@ import type { Id, MNode, MPage } from '@tmagic/schema';
 | 
				
			|||||||
import { MContainer, NodeType } from '@tmagic/schema';
 | 
					import { MContainer, NodeType } from '@tmagic/schema';
 | 
				
			||||||
import StageCore from '@tmagic/stage';
 | 
					import StageCore from '@tmagic/stage';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import type { Services } from '../../type';
 | 
					import type { MenuButton, MenuComponent, Services } from '../../type';
 | 
				
			||||||
import { Layout } from '../../type';
 | 
					import { Layout } from '../../type';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import LayerMenu from './LayerMenu.vue';
 | 
					import LayerMenu from './LayerMenu.vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					defineProps<{
 | 
				
			||||||
 | 
					  layerContentMenu: (MenuButton | MenuComponent)[];
 | 
				
			||||||
 | 
					}>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const throttleTime = 150;
 | 
					const throttleTime = 150;
 | 
				
			||||||
const services = inject<Services>('services');
 | 
					const services = inject<Services>('services');
 | 
				
			||||||
const tree = ref<InstanceType<typeof TMagicTree>>();
 | 
					const tree = ref<InstanceType<typeof TMagicTree>>();
 | 
				
			||||||
 | 
				
			|||||||
@ -85,7 +85,7 @@ import { Coin, EditPen, Files } from '@element-plus/icons-vue';
 | 
				
			|||||||
import { getConfig, TMagicTabs } from '@tmagic/design';
 | 
					import { getConfig, TMagicTabs } from '@tmagic/design';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import MIcon from '../../components/Icon.vue';
 | 
					import MIcon from '../../components/Icon.vue';
 | 
				
			||||||
import type { SideComponent, SideItem } from '../../type';
 | 
					import type { MenuButton, MenuComponent, SideComponent, SideItem } from '../../type';
 | 
				
			||||||
import { SideBarData } from '../../type';
 | 
					import { SideBarData } from '../../type';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import CodeBlockList from './code-block/CodeBlockList.vue';
 | 
					import CodeBlockList from './code-block/CodeBlockList.vue';
 | 
				
			||||||
@ -95,6 +95,7 @@ import LayerPanel from './LayerPanel.vue';
 | 
				
			|||||||
const props = withDefaults(
 | 
					const props = withDefaults(
 | 
				
			||||||
  defineProps<{
 | 
					  defineProps<{
 | 
				
			||||||
    data?: SideBarData;
 | 
					    data?: SideBarData;
 | 
				
			||||||
 | 
					    layerContentMenu: (MenuButton | MenuComponent)[];
 | 
				
			||||||
  }>(),
 | 
					  }>(),
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    data: () => ({ type: 'tabs', status: '组件', items: ['component-list', 'layer', 'code-block'] }),
 | 
					    data: () => ({ type: 'tabs', status: '组件', items: ['component-list', 'layer', 'code-block'] }),
 | 
				
			||||||
@ -120,6 +121,9 @@ const getItemConfig = (data: SideItem): SideComponent => {
 | 
				
			|||||||
      type: 'component',
 | 
					      type: 'component',
 | 
				
			||||||
      icon: Files,
 | 
					      icon: Files,
 | 
				
			||||||
      text: '已选组件',
 | 
					      text: '已选组件',
 | 
				
			||||||
 | 
					      props: {
 | 
				
			||||||
 | 
					        layerContentMenu: props.layerContentMenu,
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
      component: LayerPanel,
 | 
					      component: LayerPanel,
 | 
				
			||||||
      slots: {},
 | 
					      slots: {},
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
				
			|||||||
@ -17,7 +17,7 @@
 | 
				
			|||||||
      @dragover="dragoverHandler"
 | 
					      @dragover="dragoverHandler"
 | 
				
			||||||
    ></div>
 | 
					    ></div>
 | 
				
			||||||
    <teleport to="body">
 | 
					    <teleport to="body">
 | 
				
			||||||
      <viewer-menu ref="menu" :is-multi-select="isMultiSelect"></viewer-menu>
 | 
					      <viewer-menu ref="menu" :is-multi-select="isMultiSelect" :stage-content-menu="stageContentMenu"></viewer-menu>
 | 
				
			||||||
    </teleport>
 | 
					    </teleport>
 | 
				
			||||||
  </scroll-viewer>
 | 
					  </scroll-viewer>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
@ -30,11 +30,15 @@ import type { MApp, MContainer, MNode, MPage } from '@tmagic/schema';
 | 
				
			|||||||
import StageCore, { calcValueByFontsize, getOffset, Runtime } from '@tmagic/stage';
 | 
					import StageCore, { calcValueByFontsize, getOffset, Runtime } from '@tmagic/stage';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import ScrollViewer from '../../components/ScrollViewer.vue';
 | 
					import ScrollViewer from '../../components/ScrollViewer.vue';
 | 
				
			||||||
import { Layout, Services, StageOptions, StageRect } from '../../type';
 | 
					import { Layout, MenuButton, MenuComponent, Services, StageOptions, StageRect } from '../../type';
 | 
				
			||||||
import { useStage } from '../../utils/stage';
 | 
					import { useStage } from '../../utils/stage';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import ViewerMenu from './ViewerMenu.vue';
 | 
					import ViewerMenu from './ViewerMenu.vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					defineProps<{
 | 
				
			||||||
 | 
					  stageContentMenu: (MenuButton | MenuComponent)[];
 | 
				
			||||||
 | 
					}>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let stage: StageCore | null = null;
 | 
					let stage: StageCore | null = null;
 | 
				
			||||||
let runtime: Runtime | null = null;
 | 
					let runtime: Runtime | null = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,7 @@
 | 
				
			|||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script lang="ts" setup name="MEditorViewerMenu">
 | 
					<script lang="ts" setup name="MEditorViewerMenu">
 | 
				
			||||||
import { computed, inject, markRaw, reactive, ref, watch } from 'vue';
 | 
					import { computed, inject, markRaw, ref, watch } from 'vue';
 | 
				
			||||||
import { Bottom, Delete, DocumentCopy, Top } from '@element-plus/icons-vue';
 | 
					import { Bottom, Delete, DocumentCopy, Top } from '@element-plus/icons-vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { MNode, NodeType } from '@tmagic/schema';
 | 
					import { MNode, NodeType } from '@tmagic/schema';
 | 
				
			||||||
@ -15,7 +15,10 @@ import storageService from '../../services/storage';
 | 
				
			|||||||
import { LayerOffset, Layout, MenuButton, MenuComponent, Services } from '../../type';
 | 
					import { LayerOffset, Layout, MenuButton, MenuComponent, Services } from '../../type';
 | 
				
			||||||
import { COPY_STORAGE_KEY } from '../../utils/editor';
 | 
					import { COPY_STORAGE_KEY } from '../../utils/editor';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const props = withDefaults(defineProps<{ isMultiSelect?: boolean }>(), { isMultiSelect: false });
 | 
					const props = withDefaults(
 | 
				
			||||||
 | 
					  defineProps<{ isMultiSelect?: boolean; stageContentMenu: (MenuButton | MenuComponent)[] }>(),
 | 
				
			||||||
 | 
					  { isMultiSelect: false },
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const services = inject<Services>('services');
 | 
					const services = inject<Services>('services');
 | 
				
			||||||
const editorService = services?.editorService;
 | 
					const editorService = services?.editorService;
 | 
				
			||||||
@ -28,9 +31,7 @@ const nodes = computed(() => editorService?.get<MNode[]>('nodes'));
 | 
				
			|||||||
const parent = computed(() => editorService?.get('parent'));
 | 
					const parent = computed(() => editorService?.get('parent'));
 | 
				
			||||||
const stage = computed(() => editorService?.get<StageCore>('stage'));
 | 
					const stage = computed(() => editorService?.get<StageCore>('stage'));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const stageContentMenu = inject<(MenuButton | MenuComponent)[]>('stageContentMenu', []);
 | 
					const menuData = computed<(MenuButton | MenuComponent)[]>(() => [
 | 
				
			||||||
 | 
					 | 
				
			||||||
const menuData = reactive<(MenuButton | MenuComponent)[]>([
 | 
					 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    type: 'button',
 | 
					    type: 'button',
 | 
				
			||||||
    text: '水平居中',
 | 
					    text: '水平居中',
 | 
				
			||||||
@ -130,7 +131,7 @@ const menuData = reactive<(MenuButton | MenuComponent)[]>([
 | 
				
			|||||||
      editorService?.get<StageCore>('stage').clearGuides();
 | 
					      editorService?.get<StageCore>('stage').clearGuides();
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  ...stageContentMenu,
 | 
					  ...props.stageContentMenu,
 | 
				
			||||||
]);
 | 
					]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
watch(
 | 
					watch(
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,7 @@
 | 
				
			|||||||
    <Breadcrumb></Breadcrumb>
 | 
					    <Breadcrumb></Breadcrumb>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <slot name="stage">
 | 
					    <slot name="stage">
 | 
				
			||||||
      <MagicStage :key="page?.id"></MagicStage>
 | 
					      <MagicStage :key="page?.id" :stage-content-menu="stageContentMenu"></MagicStage>
 | 
				
			||||||
    </slot>
 | 
					    </slot>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <slot name="workspace-content"></slot>
 | 
					    <slot name="workspace-content"></slot>
 | 
				
			||||||
@ -22,12 +22,16 @@ import KeyController from 'keycon';
 | 
				
			|||||||
import type { MNode, MPage } from '@tmagic/schema';
 | 
					import type { MNode, MPage } from '@tmagic/schema';
 | 
				
			||||||
import { isPage } from '@tmagic/utils';
 | 
					import { isPage } from '@tmagic/utils';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import type { Services } from '../../type';
 | 
					import type { MenuButton, MenuComponent, Services } from '../../type';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import Breadcrumb from './Breadcrumb.vue';
 | 
					import Breadcrumb from './Breadcrumb.vue';
 | 
				
			||||||
import PageBar from './PageBar.vue';
 | 
					import PageBar from './PageBar.vue';
 | 
				
			||||||
import MagicStage from './Stage.vue';
 | 
					import MagicStage from './Stage.vue';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					defineProps<{
 | 
				
			||||||
 | 
					  stageContentMenu: (MenuButton | MenuComponent)[];
 | 
				
			||||||
 | 
					}>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const services = inject<Services>('services');
 | 
					const services = inject<Services>('services');
 | 
				
			||||||
const workspace = ref<HTMLDivElement>();
 | 
					const workspace = ref<HTMLDivElement>();
 | 
				
			||||||
const nodes = computed(() => services?.editorService.get<MNode[]>('nodes'));
 | 
					const nodes = computed(() => services?.editorService.get<MNode[]>('nodes'));
 | 
				
			||||||
 | 
				
			|||||||
@ -60,7 +60,7 @@ describe('Stage.vue', () => {
 | 
				
			|||||||
        type: NodeType.ROOT,
 | 
					        type: NodeType.ROOT,
 | 
				
			||||||
        items: [page],
 | 
					        items: [page],
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
 | 
					      stageContentMenu: [],
 | 
				
			||||||
      page,
 | 
					      page,
 | 
				
			||||||
      node: page,
 | 
					      node: page,
 | 
				
			||||||
      uiSelectMode: false,
 | 
					      uiSelectMode: false,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user