Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d969d93ff8 |
2 changed files with 74 additions and 30 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
id="inputItem"
|
id="inputItem"
|
||||||
class="input-item"
|
class="input-item"
|
||||||
:class="{ playing: isRecording }"
|
:class="{ playing: isRecording }"
|
||||||
:style="{ top: `${elementY}px`, left: `${elementX}px` }"
|
:style="{ top: `${position.y}px`, left: `${position.x}px` }"
|
||||||
>
|
>
|
||||||
|
|
||||||
<!-- animations for recording and on-standby -->
|
<!-- animations for recording and on-standby -->
|
||||||
|
|
@ -15,12 +15,13 @@
|
||||||
<!-- Show text input on key-down -->
|
<!-- Show text input on key-down -->
|
||||||
<input id="textInput" type="text" />
|
<input id="textInput" type="text" />
|
||||||
|
|
||||||
|
<div @mousedown.prevent="toggleMenu" id="helpMenu" v-if="!isDragging"></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { defineComponent, watch, ref } from "vue";
|
||||||
import { defineComponent } from "vue";
|
|
||||||
import draggify from "@/modules/draggify";
|
import draggify from "@/modules/draggify";
|
||||||
import useInputController from "./inputController";
|
import useInputController from "./inputController";
|
||||||
|
|
||||||
|
|
@ -29,22 +30,57 @@ export default defineComponent({
|
||||||
setup() {
|
setup() {
|
||||||
|
|
||||||
// Calculate position of inputItem on drag.
|
// Calculate position of inputItem on drag.
|
||||||
const { elementX, elementY } = draggify({ elementId: "inputItem" });
|
const { position, isDragging } = draggify({ elementId: "inputItem" });
|
||||||
|
|
||||||
// determine whether the user is typing or recording.
|
// determine whether the user is typing or recording.
|
||||||
const { isRecording, isTyping } = useInputController();
|
const { isRecording, isTyping } = useInputController();
|
||||||
|
|
||||||
|
const canOpen = ref(true);
|
||||||
|
|
||||||
|
const toggleMenu = (e: any) => {
|
||||||
|
if(isDragging.value === false) {
|
||||||
|
setImmediate(() => {
|
||||||
|
console.log('yuh yeet')
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(isDragging, (current, prev) => {
|
||||||
|
if (current) {
|
||||||
|
console.log('is dragging')
|
||||||
|
canOpen.value = false;
|
||||||
|
} else {
|
||||||
|
console.log('not dragging')
|
||||||
|
canOpen.value = true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
elementX,
|
position,
|
||||||
elementY,
|
|
||||||
isRecording,
|
isRecording,
|
||||||
isTyping,
|
isTyping,
|
||||||
|
toggleMenu,
|
||||||
|
isDragging,
|
||||||
|
canOpen
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
#helpMenu {
|
||||||
|
width: 150px;
|
||||||
|
height: 150px;
|
||||||
|
border: 1px solid red;
|
||||||
|
background-color: transparent;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
|
||||||
|
border-radius: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
#textInput {
|
#textInput {
|
||||||
width: 0px;
|
width: 0px;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { onMounted, ref, onUnmounted } from "vue";
|
import { onMounted, ref, onUnmounted, watch } from "vue";
|
||||||
|
|
||||||
//---Dragabble Helper Funcs--------------------------------------
|
//---Dragabble Helper Funcs--------------------------------------
|
||||||
|
|
||||||
|
|
@ -34,9 +34,13 @@ export default function draggify(input: { elementId: string }) {
|
||||||
|
|
||||||
let element: HTMLElement | null;
|
let element: HTMLElement | null;
|
||||||
|
|
||||||
// Cords of inputItem.
|
// Cords of target element.
|
||||||
const elementX = ref(0);
|
const position = ref({
|
||||||
const elementY = ref(0);
|
x: 0,
|
||||||
|
y: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
const isDragging = ref(false);
|
||||||
|
|
||||||
// Position of inputItem on terms of percentage of window.
|
// Position of inputItem on terms of percentage of window.
|
||||||
let percentX: number;
|
let percentX: number;
|
||||||
|
|
@ -50,33 +54,37 @@ export default function draggify(input: { elementId: string }) {
|
||||||
|
|
||||||
// Update the position of inputItem on mouse dragging.
|
// Update the position of inputItem on mouse dragging.
|
||||||
const onMouseMove = (e: any) => {
|
const onMouseMove = (e: any) => {
|
||||||
|
isDragging.value = true;
|
||||||
element = document.getElementById(input.elementId);
|
element = document.getElementById(input.elementId);
|
||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
|
element.classList.add("dragging");
|
||||||
const inputItemRect = element.getBoundingClientRect();
|
const inputItemRect = element.getBoundingClientRect();
|
||||||
elementX.value = inputItemRect.left + e.movementX;
|
position.value.x = inputItemRect.left + e.movementX;
|
||||||
elementY.value = inputItemRect.top + e.movementY;
|
position.value.y = inputItemRect.top + e.movementY;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add an event listener for dragging.
|
// Add an event listener for dragging.
|
||||||
const onMouseDown = (_e: any) => {
|
const onMouseDown = (e: any) => {
|
||||||
window.addEventListener('mousemove', onMouseMove, true);
|
window.addEventListener('mousemove', onMouseMove, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update position references when user is done moving targetEl.
|
// Update position references when user is done moving targetEl.
|
||||||
const onMouseUp = (_e: any) => {
|
const onMouseUp = (e: any) => {
|
||||||
|
isDragging.value = false;
|
||||||
|
if (element) element.classList.remove("dragging")
|
||||||
window.removeEventListener('mousemove', onMouseMove, true);
|
window.removeEventListener('mousemove', onMouseMove, true);
|
||||||
|
|
||||||
const winW = window.innerWidth;
|
const winW = window.innerWidth;
|
||||||
const winH = window.innerHeight;
|
const winH = window.innerHeight;
|
||||||
|
|
||||||
xShort = calcSideProximity(elementX.value, winW);
|
xShort = calcSideProximity(position.value.x, winW);
|
||||||
yShort = calcSideProximity(elementY.value, winH);
|
yShort = calcSideProximity(position.value.y, winH);
|
||||||
|
|
||||||
percentX = elementX.value / winW;
|
percentX = position.value.x / winW;
|
||||||
percentY = elementY.value / winH;
|
percentY = position.value.y / winH;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,8 +93,8 @@ export default function draggify(input: { elementId: string }) {
|
||||||
const winW = window.innerWidth;
|
const winW = window.innerWidth;
|
||||||
const winH = window.innerHeight;
|
const winH = window.innerHeight;
|
||||||
|
|
||||||
elementX.value = calcPosition(elementX.value, percentX, xShort, winW);
|
position.value.x = calcPosition(position.value.x, percentX, xShort, winW);
|
||||||
elementY.value = calcPosition(elementY.value, percentY, yShort, winH);
|
position.value.y = calcPosition(position.value.y, percentY, yShort, winH);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,25 +104,25 @@ export default function draggify(input: { elementId: string }) {
|
||||||
element = document.getElementById(input.elementId);
|
element = document.getElementById(input.elementId);
|
||||||
|
|
||||||
if (element) {
|
if (element) {
|
||||||
element.addEventListener('mousedown', onMouseDown, false);
|
element.addEventListener('mousedown', onMouseDown, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("mouseup", onMouseUp, false);
|
window.addEventListener("mouseup", onMouseUp, false);
|
||||||
|
|
||||||
// Initialize the positional references.
|
// Initialize the positional references.
|
||||||
percentX = elementX.value / window.innerWidth;
|
percentX = position.value.x / window.innerWidth;
|
||||||
percentY = elementY.value / window.innerHeight;
|
percentY = position.value.y / window.innerHeight;
|
||||||
|
|
||||||
xShort = calcSideProximity(elementX.value, window.innerWidth);
|
xShort = calcSideProximity(position.value.x, window.innerWidth);
|
||||||
yShort = calcSideProximity(elementX.value, window.innerHeight);
|
yShort = calcSideProximity(position.value.x, window.innerHeight);
|
||||||
|
|
||||||
// Then, we can listen for window resize.
|
// Then, we can listen for window resize.
|
||||||
window.addEventListener('resize', onWindowResize, false);
|
window.addEventListener('resize', onWindowResize, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialize the coordinants.
|
// Initialize the coordinants.
|
||||||
elementX.value = 20;
|
position.value.x = 20;
|
||||||
elementY.value = 200 - 38 - 20;
|
position.value.y = 200 - 38 - 20;
|
||||||
|
|
||||||
// remove event listeners on component dismount.
|
// remove event listeners on component dismount.
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
|
@ -124,8 +132,8 @@ export default function draggify(input: { elementId: string }) {
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
elementX,
|
position,
|
||||||
elementY
|
isDragging
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue