Skip to content

Commit

Permalink
add logic to resize
Browse files Browse the repository at this point in the history
  • Loading branch information
madeindjs committed Jan 7, 2025
1 parent 33aa067 commit 3a8a73b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 20 deletions.
40 changes: 21 additions & 19 deletions src/ui/src/builder/panels/BuilderCodePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@
keyboard-shortcut-key="J"
class="BuilderCodePanel"
>
<div class="BuilderCodePanel__content">
<ShareSourceFilesTree
:source-files="sourceFiles"
:path-active="openedFilePath"
class="BuilderCodePanel__content__tree"
@select="openFile"
/>
<BuilderEmbeddedCodeEditor
v-model="code"
class="BuilderCodePanel__content__editor"
variant="full"
:language="openedFileLanguage"
:disabled="isDisabled"
@update:model-value="handleUpdate"
></BuilderEmbeddedCodeEditor>
</div>
<ShareHorizontalResize :initial-left-size="100">
<template #left>
<ShareSourceFilesTree
:source-files="sourceFiles"
:path-active="openedFilePath"
class="BuilderCodePanel__content__tree"
@select="openFile"
/>
</template>
<template #right>
<BuilderEmbeddedCodeEditor
v-model="code"
class="BuilderCodePanel__content__editor"
variant="full"
:language="openedFileLanguage"
:disabled="isDisabled"
@update:model-value="handleUpdate"
/>
</template>
</ShareHorizontalResize>
<template #actionsCompanion>
<div v-if="status" class="status" :class="status.type">
{{ status.message }}
Expand All @@ -39,6 +43,7 @@ import BuilderAsyncLoader from "../BuilderAsyncLoader.vue";
import injectionKeys from "@/injectionKeys";
import ShareSourceFilesTree from "@/components/shared/SharedSourceFilesTree/ShareSourceFilesTree.vue";
import { useSourceFiles } from "@/core/useSourceFiles";
import ShareHorizontalResize from "@/components/shared/ShareHorizontalResize.vue";
defineProps<{
contentsTeleportEl: HTMLElement;
Expand Down Expand Up @@ -118,15 +123,12 @@ async function save() {

<style scoped>
.BuilderCodePanel__content {
display: grid;
grid-template-columns: 100px minmax(0, 100%);
height: 100%;
width: 100%;
}
.BuilderCodePanel__content__tree {
height: 100%;
width: 100%;
border-right: 1px solid var(--builderSeparatorColor);
padding: 4px;
}
Expand Down
58 changes: 58 additions & 0 deletions src/ui/src/components/shared/ShareHorizontalResize.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<template>
<div ref="root" class="ShareHorizontalResize" :style="style">
<div class="ShareHorizontalResize__left">
<slot name="left" />
</div>
<hr
class="ShareHorizontalResize__divider"
@mousedown.prevent="handleMouseDown"
/>
<div class="ShareHorizontalResize__right">
<slot name="right" />
</div>
</div>
</template>

<script setup lang="ts">
import { computed, CSSProperties, ref } from "vue";
const props = defineProps({
initialLeftSize: { type: Number, required: true },
});
const root = ref<HTMLElement | null>(null);
let leftSize = ref(props.initialLeftSize);
const style = computed<CSSProperties>(() => ({
gridTemplateColumns: `${leftSize.value}px 1px minmax(0, 100%)`,
}));
function handleMouseDown() {
document.addEventListener("mousemove", onMouseMove);
document.addEventListener("mouseup", onMouseUp);
const sliderBoundingRect = root.value.getBoundingClientRect();
function onMouseMove(event: MouseEvent) {
leftSize.value = event.x - sliderBoundingRect.left;
}
function onMouseUp() {
document.removeEventListener("mouseup", onMouseUp);
document.removeEventListener("mousemove", onMouseMove);
}
}
</script>

<style scoped>
.ShareHorizontalResize {
display: grid;
height: 100%;
}
.ShareHorizontalResize__divider {
border: none;
background-color: var(--builderSeparatorColor);
height: 100%;
cursor: ew-resize;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const isDirectory = computed(() => typeof props.content !== "string");
:class="{
'SharedSourceFilesTreeNode__file--active': isPathActive,
}"
:data-writer-tooltip="currentPathString"
@click="$emit('select', [...path, root])"
>
<span class="material-symbols-outlined">description</span>
Expand Down

0 comments on commit 3a8a73b

Please sign in to comment.