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'"
|
2025-12-27 03:39:40 +00:00
|
|
|
@click.left.stop="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-25 19:56:25 +00:00
|
|
|
import { ref, useTemplateRef } from "vue";
|
2023-02-17 19:00:27 +00:00
|
|
|
|
2025-12-25 19:56:25 +00:00
|
|
|
import { Like, unwrap_like, wait_for } from "@/lib/helpers";
|
2023-09-10 01:59:19 +00:00
|
|
|
import SVGRect from "../calendar/SVGRect.vue";
|
2023-02-17 19:00:27 +00:00
|
|
|
|
2025-12-25 19:56:25 +00:00
|
|
|
const model = defineModel<Like<Door>>({ required: true });
|
2025-12-05 02:12:33 +00:00
|
|
|
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("");
|
2025-12-07 03:28:00 +00:00
|
|
|
const editing = ref(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);
|
2025-12-07 03:28:00 +00:00
|
|
|
editing.value = !editing.value;
|
2025-12-05 02:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function on_click(event: MouseEvent) {
|
|
|
|
|
if (!(event.target instanceof HTMLDivElement)) {
|
|
|
|
|
return;
|
2023-02-17 19:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-25 19:56:25 +00:00
|
|
|
if (editing.value) {
|
|
|
|
|
unwrap_like(model.value).day = day_str.value;
|
2025-12-05 02:12:33 +00:00
|
|
|
} else {
|
2025-12-25 19:56:25 +00:00
|
|
|
wait_for(
|
|
|
|
|
() => day_input.value !== null,
|
|
|
|
|
() => day_input.value!.select(),
|
|
|
|
|
);
|
2025-12-05 02:12:33 +00:00
|
|
|
}
|
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) {
|
2025-12-07 03:28:00 +00:00
|
|
|
if (!editing.value) {
|
2025-12-05 02:12:33 +00:00
|
|
|
return;
|
2023-02-17 19:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
if (event.key === "Enter") {
|
2025-12-25 19:56:25 +00:00
|
|
|
unwrap_like(model.value).day = day_str.value;
|
2025-12-05 02:12:33 +00:00
|
|
|
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>
|