2022-01-22 20:19:26 +01:00
|
|
|
<script lang="ts">
|
|
|
|
import { debounce } from "lodash";
|
|
|
|
import { createEventDispatcher } from "svelte";
|
|
|
|
import { useEntity } from "../../lib/entity";
|
|
|
|
import type { AttributeCreate, AttributeUpdate } from "../../types/base";
|
|
|
|
import type { UpEntry } from "upend";
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
export let address: string;
|
|
|
|
export let editable: boolean;
|
|
|
|
|
|
|
|
$: ({ entity } = useEntity(address));
|
|
|
|
|
|
|
|
let noteEntry: UpEntry | undefined;
|
2022-01-28 16:46:08 +01:00
|
|
|
let notes: string | undefined = undefined;
|
2022-01-22 20:19:26 +01:00
|
|
|
$: {
|
|
|
|
if ($entity?.attr["NOTE"]?.length && $entity?.attr["NOTE"][0]?.value?.c) {
|
|
|
|
noteEntry = $entity?.attr["NOTE"][0];
|
|
|
|
notes = String(noteEntry.value.c);
|
|
|
|
} else {
|
|
|
|
noteEntry = undefined;
|
|
|
|
notes = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let contentEl: HTMLDivElement;
|
|
|
|
|
|
|
|
const update = debounce(() => {
|
|
|
|
if (noteEntry) {
|
|
|
|
dispatch("change", {
|
|
|
|
type: "update",
|
|
|
|
address: noteEntry.address,
|
|
|
|
attribute: "NOTE",
|
2022-01-28 20:51:34 +01:00
|
|
|
value: { t: "String", c: contentEl.innerText },
|
2022-01-22 20:19:26 +01:00
|
|
|
} as AttributeUpdate);
|
|
|
|
} else {
|
|
|
|
dispatch("change", {
|
|
|
|
type: "create",
|
|
|
|
address: address,
|
|
|
|
attribute: "NOTE",
|
2022-01-28 20:51:34 +01:00
|
|
|
value: { t: "String", c: contentEl.innerText },
|
2022-01-22 20:19:26 +01:00
|
|
|
} as AttributeCreate);
|
|
|
|
}
|
|
|
|
}, 500);
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if notes || editable}
|
|
|
|
<section class="notes labelborder">
|
|
|
|
<header>
|
|
|
|
<h3>Notes</h3>
|
|
|
|
</header>
|
|
|
|
<div
|
|
|
|
class="content"
|
|
|
|
contenteditable={editable ? "true" : "false"}
|
|
|
|
on:input={update}
|
|
|
|
bind:this={contentEl}
|
|
|
|
>
|
|
|
|
{notes ? notes : ""}
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
@use "../util";
|
|
|
|
|
|
|
|
.content {
|
|
|
|
background: var(--background);
|
|
|
|
border-radius: 4px;
|
2022-01-23 11:31:20 +01:00
|
|
|
padding: 0.5em;
|
2022-01-22 20:19:26 +01:00
|
|
|
}
|
|
|
|
</style>
|