2023-02-17 19:00:27 +00:00
|
|
|
<template>
|
2023-09-20 22:04:47 +00:00
|
|
|
<SVGRect
|
2023-09-22 19:02:51 +00:00
|
|
|
style="cursor: text"
|
2025-12-05 02:12:33 +00:00
|
|
|
:rectangle="model.position"
|
2023-09-20 22:04:47 +00:00
|
|
|
:variant="editing ? 'success' : 'primary'"
|
2023-09-22 19:02:51 +00:00
|
|
|
@click.left="on_click"
|
2023-11-05 23:51:16 +00:00
|
|
|
visible
|
2023-09-07 01:17:14 +00:00
|
|
|
>
|
2023-09-22 19:02:51 +00:00
|
|
|
<input
|
|
|
|
|
v-if="editing"
|
|
|
|
|
v-model="day_str"
|
|
|
|
|
ref="day_input"
|
|
|
|
|
class="input is-large"
|
|
|
|
|
type="number"
|
2025-12-05 02:12:33 +00:00
|
|
|
:min="Door.MIN_DAY"
|
2023-09-22 19:02:51 +00:00
|
|
|
placeholder="Tag"
|
|
|
|
|
@keydown="on_keydown"
|
|
|
|
|
/>
|
|
|
|
|
<div v-else class="has-text-danger">
|
2025-12-05 02:12:33 +00:00
|
|
|
{{ model.day > 0 ? model.day : "*" }}
|
2023-02-17 19:00:27 +00:00
|
|
|
</div>
|
2023-09-22 19:02:51 +00:00
|
|
|
</SVGRect>
|
2023-02-17 19:00:27 +00:00
|
|
|
</template>
|
|
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
<script setup lang="ts">
|
2024-08-23 16:38:04 +00:00
|
|
|
import { Door } from "@/lib/rects/door";
|
2025-12-05 02:12:33 +00:00
|
|
|
import { nextTick, ref, useTemplateRef } from "vue";
|
2023-02-17 19:00:27 +00:00
|
|
|
|
2023-09-10 01:59:19 +00:00
|
|
|
import SVGRect from "../calendar/SVGRect.vue";
|
2023-02-17 19:00:27 +00:00
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
const model = defineModel<Door>({ required: true });
|
|
|
|
|
const day_input = useTemplateRef("day_input");
|
2023-02-17 19:00:27 +00:00
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
const day_str = ref("");
|
|
|
|
|
let editing = false;
|
2023-02-17 19:00:27 +00:00
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
function toggle_editing() {
|
|
|
|
|
day_str.value = String(model.value.day);
|
|
|
|
|
editing = !editing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function on_click(event: MouseEvent) {
|
|
|
|
|
if (!(event.target instanceof HTMLDivElement)) {
|
|
|
|
|
return;
|
2023-02-17 19:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
if (!editing) {
|
|
|
|
|
const day_input_focus = () => {
|
|
|
|
|
if (day_input.value === null) {
|
|
|
|
|
nextTick(day_input_focus);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-17 19:00:27 +00:00
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
day_input.value.select();
|
|
|
|
|
};
|
|
|
|
|
day_input_focus();
|
|
|
|
|
} else {
|
|
|
|
|
model.value.day = day_str.value;
|
|
|
|
|
}
|
2023-02-18 00:43:07 +00:00
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
toggle_editing();
|
|
|
|
|
}
|
2023-02-17 19:00:27 +00:00
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
function on_keydown(event: KeyboardEvent) {
|
|
|
|
|
if (!editing) {
|
|
|
|
|
return;
|
2023-02-17 19:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
if (event.key === "Enter") {
|
|
|
|
|
model.value.day = day_str.value;
|
|
|
|
|
toggle_editing();
|
|
|
|
|
} else if (event.key === "Delete") {
|
|
|
|
|
model.value.day = -1;
|
|
|
|
|
toggle_editing();
|
|
|
|
|
} else if (event.key === "Escape") {
|
|
|
|
|
toggle_editing();
|
2023-02-17 19:00:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|