Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make sure panel vue component be child of DockViewVue component #669

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/dockview-core/src/dockview/dockviewComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ export class DockviewComponent
group = item;

const popoutReferenceGroupId = this._popoutGroups.find(
(_) => _.popoutGroup === group
(_) => _.popoutGroup.id === group.id
)?.referenceGroup;
const popoutReferenceGroup = popoutReferenceGroupId
? this.getPanel(popoutReferenceGroupId)
Expand Down Expand Up @@ -1715,7 +1715,7 @@ export class DockviewComponent

if (group.api.location.type === 'floating') {
const floatingGroup = this._floatingGroups.find(
(_) => _.group === group
(_) => _.group.id === group.id
);

if (floatingGroup) {
Expand All @@ -1728,7 +1728,7 @@ export class DockviewComponent
remove(this._floatingGroups, floatingGroup);
floatingGroup.dispose();

if (!options?.skipActive && this._activeGroup === group) {
if (!options?.skipActive && this._activeGroup?.id === group.id) {
const groups = Array.from(this._groups.values());

this.doSetGroupAndPanelActive(
Expand All @@ -1744,7 +1744,7 @@ export class DockviewComponent

if (group.api.location.type === 'popout') {
const selectedGroup = this._popoutGroups.find(
(_) => _.popoutGroup === group
(_) => _.popoutGroup.id === group.id
);

if (selectedGroup) {
Expand All @@ -1771,7 +1771,7 @@ export class DockviewComponent
this.doSetGroupAndPanelActive(removedGroup);
}

if (!options?.skipActive && this._activeGroup === group) {
if (!options?.skipActive && this._activeGroup?.id === group.id) {
const groups = Array.from(this._groups.values());

this.doSetGroupAndPanelActive(
Expand Down Expand Up @@ -1857,11 +1857,6 @@ export class DockviewComponent
throw new Error(`No panel with id ${sourceItemId}`);
}

if (sourceGroup.model.size === 0) {
// remove the group and do not set a new group as active
this.doRemoveGroup(sourceGroup, { skipActive: true });
}

this.movingLock(() =>
destinationGroup.model.openPanel(removedPanel, {
index: destinationIndex,
Expand All @@ -1870,6 +1865,11 @@ export class DockviewComponent
);
this.doSetGroupAndPanelActive(destinationGroup);

if (sourceGroup.model.size === 0) {
// remove the group and do not set a new group as active
this.doRemoveGroup(sourceGroup, { skipActive: true });
}

this._onDidMovePanel.fire({
panel: removedPanel,
from: sourceGroup,
Expand Down
28 changes: 26 additions & 2 deletions packages/dockview-vue/src/dockview/dockview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ import {
onBeforeUnmount,
markRaw,
getCurrentInstance,
reactive,
mergeProps,
} from 'vue';
import {
VueHeaderActionsRenderer,
VueRenderer,
VueWatermarkRenderer,
findComponent,
} from '../utils';
import type { IDockviewVueProps, VueEvents } from './types';
import type { IDockviewVueProps, VNodeType, VueEvents } from './types';
import Tele from './teleport.vue'

function extractCoreOptions(props: IDockviewVueProps): DockviewOptions {
const coreOptions = (PROPERTY_KEYS as (keyof DockviewOptions)[]).reduce(
Expand Down Expand Up @@ -174,8 +177,29 @@ onBeforeUnmount(() => {
instance.value.dispose();
}
});

const vnodes = reactive<VNodeType[]>([]);

defineExpose({
add(item: VNodeType) {
vnodes.push(item)
},
remove(key: symbol) {
const index = vnodes.findIndex(item => item.key === key);
if(index > -1) {
vnodes.splice(index, 1);
}
},
update(key: symbol, props: Record<string, any>) {
const item = vnodes.find(item => item.key === key);
if(item) {
item.props = mergeProps(item.props, props);
}
}
})
</script>

<template>
<div ref="el" />
<div ref="el" :="$attrs" />
<Tele :items="vnodes"/>
</template>
13 changes: 13 additions & 0 deletions packages/dockview-vue/src/dockview/teleport.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<script setup lang="ts">
import type { VNodeType } from './types';
const props = defineProps<{
items: VNodeType[]
}>();
</script>

<template>
<Teleport v-for="item in props.items" :key="item.key" :to="item.target">
<component :is="item.component" :=item.props></component>
</Teleport>
</template>
8 changes: 8 additions & 0 deletions packages/dockview-vue/src/dockview/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type DockviewOptions, type DockviewReadyEvent } from 'dockview-core';
import type { Component } from 'vue';

export interface VueProps {
watermarkComponent?: string;
Expand All @@ -13,3 +14,10 @@ export type VueEvents = {
};

export type IDockviewVueProps = DockviewOptions & VueProps;

export type VNodeType = {
key: symbol;
component: Component;
props: any;
target: HTMLElement;
}
27 changes: 19 additions & 8 deletions packages/dockview-vue/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
cloneVNode,
type DefineComponent,
type ComponentInternalInstance,
markRaw,
} from 'vue';

export type ComponentInterface = ComponentOptionsBase<
Expand Down Expand Up @@ -69,22 +70,32 @@ export function mountVueComponent<T extends Record<string, any>>(
props: T,
element: HTMLElement
) {
let vNode = createVNode(component, Object.freeze(props));
// let vNode = createVNode(component, Object.freeze(props));

vNode.appContext = parent.appContext;
// vNode.appContext = parent.appContext;

render(vNode, element);
// render(vNode, element);

let runningProps = props;
// let runningProps = props;

const key = Symbol();
parent.exposed!.add({
key,
component: markRaw(component),
target: markRaw(element),
props,
});

return {
update: (newProps: any) => {
runningProps = { ...props, ...newProps };
vNode = cloneVNode(vNode, runningProps);
render(vNode, element);
// runningProps = { ...props, ...newProps };
// vNode = cloneVNode(vNode, runningProps);
// render(vNode, element);
parent.exposed!.update(key, newProps);
},
dispose: () => {
render(null, element);
// render(null, element);
parent.exposed!.remove(key);
},
};
}
Expand Down
1 change: 1 addition & 0 deletions packages/dockview-vue/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"exclude": ["src/**/__tests__/*", "src/**/*.cy.ts"],
"compilerOptions": {
"jsxImportSource": "vue",
"composite": true,
"baseUrl": "."
}
Expand Down