mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2026-01-11 15:43:00 +00:00
🔧 ui: minor changes to helpers
- rename `Like` -> `VueLike` (also `unwrap_like` -> `unwrap_vuelike`) - rename `ensure_loaded` -> `unwrap_loading` - make `unwrap_loading` throw `null` on error instead of `""`
This commit is contained in:
parent
eacd1da482
commit
7cca8c4825
9 changed files with 30 additions and 30 deletions
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
<figure>
|
<figure>
|
||||||
<div class="image is-unselectable">
|
<div class="image is-unselectable">
|
||||||
<img :src="ensure_loaded(store.background_image).data_url" />
|
<img :src="unwrap_loading(store.background_image).data_url" />
|
||||||
<ThouCanvas>
|
<ThouCanvas>
|
||||||
<CalendarDoor
|
<CalendarDoor
|
||||||
v-for="(door, index) in doors"
|
v-for="(door, index) in doors"
|
||||||
|
|
@ -49,7 +49,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { API } from "@/lib/api";
|
import { API } from "@/lib/api";
|
||||||
import { APIError } from "@/lib/api_error";
|
import { APIError } from "@/lib/api_error";
|
||||||
import { ensure_loaded, Like, name_door } from "@/lib/helpers";
|
import { VueLike, name_door, unwrap_loading } from "@/lib/helpers";
|
||||||
import { ImageData } from "@/lib/model";
|
import { ImageData } from "@/lib/model";
|
||||||
import { Door } from "@/lib/rects/door";
|
import { Door } from "@/lib/rects/door";
|
||||||
import { advent22Store } from "@/lib/store";
|
import { advent22Store } from "@/lib/store";
|
||||||
|
|
@ -62,7 +62,7 @@ import CalendarDoor from "./calendar/CalendarDoor.vue";
|
||||||
import ThouCanvas from "./calendar/ThouCanvas.vue";
|
import ThouCanvas from "./calendar/ThouCanvas.vue";
|
||||||
|
|
||||||
defineProps<{
|
defineProps<{
|
||||||
doors: Like<Door>[];
|
doors: VueLike<Door>[];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const store = advent22Store();
|
const store = advent22Store();
|
||||||
|
|
|
||||||
|
|
@ -17,14 +17,14 @@
|
||||||
import { Door } from "@/lib/rects/door";
|
import { Door } from "@/lib/rects/door";
|
||||||
import { advent22Store } from "@/lib/store";
|
import { advent22Store } from "@/lib/store";
|
||||||
|
|
||||||
import { Like } from "@/lib/helpers";
|
import { VueLike } from "@/lib/helpers";
|
||||||
import SVGRect from "./SVGRect.vue";
|
import SVGRect from "./SVGRect.vue";
|
||||||
|
|
||||||
const store = advent22Store();
|
const store = advent22Store();
|
||||||
|
|
||||||
withDefaults(
|
withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
door: Like<Door>;
|
door: VueLike<Door>;
|
||||||
force_visible?: boolean;
|
force_visible?: boolean;
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Like, loading_success } from "@/lib/helpers";
|
import { VueLike, loading_success } from "@/lib/helpers";
|
||||||
import { Rectangle } from "@/lib/rects/rectangle";
|
import { Rectangle } from "@/lib/rects/rectangle";
|
||||||
import { advent22Store } from "@/lib/store";
|
import { advent22Store } from "@/lib/store";
|
||||||
import { computed } from "vue";
|
import { computed } from "vue";
|
||||||
|
|
@ -39,7 +39,7 @@ withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
variant: BulmaVariant;
|
variant: BulmaVariant;
|
||||||
visible?: boolean;
|
visible?: boolean;
|
||||||
rectangle: Like<Rectangle>;
|
rectangle: VueLike<Rectangle>;
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
visible: true,
|
visible: true,
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import { Rectangle } from "@/lib/rects/rectangle";
|
||||||
import { Vector2D } from "@/lib/rects/vector2d";
|
import { Vector2D } from "@/lib/rects/vector2d";
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
|
|
||||||
import { Like } from "@/lib/helpers";
|
import { VueLike } from "@/lib/helpers";
|
||||||
import CalendarDoor from "../calendar/CalendarDoor.vue";
|
import CalendarDoor from "../calendar/CalendarDoor.vue";
|
||||||
import SVGRect from "../calendar/SVGRect.vue";
|
import SVGRect from "../calendar/SVGRect.vue";
|
||||||
import ThouCanvas from "../calendar/ThouCanvas.vue";
|
import ThouCanvas from "../calendar/ThouCanvas.vue";
|
||||||
|
|
@ -37,9 +37,9 @@ import ThouCanvas from "../calendar/ThouCanvas.vue";
|
||||||
type CanvasState =
|
type CanvasState =
|
||||||
| { kind: "idle" }
|
| { kind: "idle" }
|
||||||
| { kind: "drawing" }
|
| { kind: "drawing" }
|
||||||
| { kind: "dragging"; door: Like<Door>; origin: Vector2D };
|
| { kind: "dragging"; door: VueLike<Door>; origin: Vector2D };
|
||||||
|
|
||||||
const model = defineModel<Like<Door>[]>({ required: true });
|
const model = defineModel<VueLike<Door>[]>({ required: true });
|
||||||
|
|
||||||
const MIN_RECT_AREA = 300;
|
const MIN_RECT_AREA = 300;
|
||||||
const state = ref<CanvasState>({ kind: "idle" });
|
const state = ref<CanvasState>({ kind: "idle" });
|
||||||
|
|
@ -47,7 +47,7 @@ const preview = ref(new Rectangle());
|
||||||
|
|
||||||
const preview_visible = computed(() => state.value.kind !== "idle");
|
const preview_visible = computed(() => state.value.kind !== "idle");
|
||||||
|
|
||||||
function pop_door(point: Vector2D): Like<Door> | undefined {
|
function pop_door(point: Vector2D): VueLike<Door> | undefined {
|
||||||
const idx = model.value.findIndex((rect) => rect.position.contains(point));
|
const idx = model.value.findIndex((rect) => rect.position.contains(point));
|
||||||
|
|
||||||
if (idx === -1) {
|
if (idx === -1) {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<figure class="image is-unselectable">
|
<figure class="image is-unselectable">
|
||||||
<img :src="ensure_loaded(store.background_image).data_url" />
|
<img :src="unwrap_loading(store.background_image).data_url" />
|
||||||
<ThouCanvas>
|
<ThouCanvas>
|
||||||
<PreviewDoor
|
<PreviewDoor
|
||||||
v-for="(_, index) in model"
|
v-for="(_, index) in model"
|
||||||
|
|
@ -24,13 +24,13 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ensure_loaded, Like } from "@/lib/helpers";
|
import { VueLike, unwrap_loading } from "@/lib/helpers";
|
||||||
import { Door } from "@/lib/rects/door";
|
import { Door } from "@/lib/rects/door";
|
||||||
import { advent22Store } from "@/lib/store";
|
import { advent22Store } from "@/lib/store";
|
||||||
|
|
||||||
import ThouCanvas from "../calendar/ThouCanvas.vue";
|
import ThouCanvas from "../calendar/ThouCanvas.vue";
|
||||||
import PreviewDoor from "./PreviewDoor.vue";
|
import PreviewDoor from "./PreviewDoor.vue";
|
||||||
|
|
||||||
const model = defineModel<Like<Door>[]>({ required: true });
|
const model = defineModel<VueLike<Door>[]>({ required: true });
|
||||||
const store = advent22Store();
|
const store = advent22Store();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -9,19 +9,19 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<figure class="image is-unselectable">
|
<figure class="image is-unselectable">
|
||||||
<img :src="ensure_loaded(store.background_image).data_url" />
|
<img :src="unwrap_loading(store.background_image).data_url" />
|
||||||
<DoorCanvas v-model="model" />
|
<DoorCanvas v-model="model" />
|
||||||
</figure>
|
</figure>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ensure_loaded, Like } from "@/lib/helpers";
|
import { VueLike, unwrap_loading } from "@/lib/helpers";
|
||||||
import { Door } from "@/lib/rects/door";
|
import { Door } from "@/lib/rects/door";
|
||||||
import { advent22Store } from "@/lib/store";
|
import { advent22Store } from "@/lib/store";
|
||||||
|
|
||||||
import DoorCanvas from "./DoorCanvas.vue";
|
import DoorCanvas from "./DoorCanvas.vue";
|
||||||
|
|
||||||
const model = defineModel<Like<Door>[]>({ required: true });
|
const model = defineModel<VueLike<Door>[]>({ required: true });
|
||||||
const store = advent22Store();
|
const store = advent22Store();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,10 @@
|
||||||
import { Door } from "@/lib/rects/door";
|
import { Door } from "@/lib/rects/door";
|
||||||
import { ref, useTemplateRef } from "vue";
|
import { ref, useTemplateRef } from "vue";
|
||||||
|
|
||||||
import { Like, unwrap_like, wait_for } from "@/lib/helpers";
|
import { VueLike, unwrap_vuelike, wait_for } from "@/lib/helpers";
|
||||||
import SVGRect from "../calendar/SVGRect.vue";
|
import SVGRect from "../calendar/SVGRect.vue";
|
||||||
|
|
||||||
const model = defineModel<Like<Door>>({ required: true });
|
const model = defineModel<VueLike<Door>>({ required: true });
|
||||||
const day_input = useTemplateRef("day_input");
|
const day_input = useTemplateRef("day_input");
|
||||||
|
|
||||||
const day_str = ref("");
|
const day_str = ref("");
|
||||||
|
|
@ -46,7 +46,7 @@ function on_click(event: MouseEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editing.value) {
|
if (editing.value) {
|
||||||
unwrap_like(model.value).day = day_str.value;
|
unwrap_vuelike(model.value).day = day_str.value;
|
||||||
} else {
|
} else {
|
||||||
wait_for(
|
wait_for(
|
||||||
() => day_input.value !== null,
|
() => day_input.value !== null,
|
||||||
|
|
@ -63,7 +63,7 @@ function on_keydown(event: KeyboardEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.key === "Enter") {
|
if (event.key === "Enter") {
|
||||||
unwrap_like(model.value).day = day_str.value;
|
unwrap_vuelike(model.value).day = day_str.value;
|
||||||
toggle_editing();
|
toggle_editing();
|
||||||
} else if (event.key === "Delete") {
|
} else if (event.key === "Delete") {
|
||||||
model.value.day = -1;
|
model.value.day = -1;
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@ export function objForEach<T>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Like<T> = T | UnwrapRef<T>;
|
export type VueLike<T> = T | UnwrapRef<T>;
|
||||||
|
|
||||||
export function unwrap_like<T>(value: Like<T>): T {
|
export function unwrap_vuelike<T>(value: VueLike<T>): T {
|
||||||
return value as T;
|
return value as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,8 +27,8 @@ export function loading_success<T>(o: Loading<T>): o is T {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ensure_loaded<T>(o: Loading<T>): T {
|
export function unwrap_loading<T>(o: Loading<T>): T {
|
||||||
if (!loading_success(o)) throw "";
|
if (!loading_success(o)) throw null;
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Like, unwrap_like } from "../helpers";
|
import { VueLike, unwrap_vuelike } from "../helpers";
|
||||||
import { DoorSaved } from "../model";
|
import { DoorSaved } from "../model";
|
||||||
import { Rectangle } from "./rectangle";
|
import { Rectangle } from "./rectangle";
|
||||||
import { Vector2D } from "./vector2d";
|
import { Vector2D } from "./vector2d";
|
||||||
|
|
@ -9,11 +9,11 @@ export class Door {
|
||||||
private _day = Door.MIN_DAY;
|
private _day = Door.MIN_DAY;
|
||||||
public position: Rectangle;
|
public position: Rectangle;
|
||||||
|
|
||||||
constructor(position: Like<Rectangle>);
|
constructor(position: VueLike<Rectangle>);
|
||||||
constructor(position: Like<Rectangle>, day: number);
|
constructor(position: VueLike<Rectangle>, day: number);
|
||||||
constructor(position: Like<Rectangle>, day = Door.MIN_DAY) {
|
constructor(position: VueLike<Rectangle>, day = Door.MIN_DAY) {
|
||||||
this.day = day;
|
this.day = day;
|
||||||
this.position = unwrap_like(position);
|
this.position = unwrap_vuelike(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public get day(): number {
|
public get day(): number {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue