2023-07-07 19:22:30 +00:00
|
|
|
<template>
|
2023-07-23 13:31:28 +00:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader" class="mkw-memo">
|
|
|
|
<template #header
|
|
|
|
><i class="ph-sticker ph-bold ph-lg"></i
|
|
|
|
>{{ i18n.ts._widgets.memo }}</template
|
|
|
|
>
|
|
|
|
|
|
|
|
<div class="otgbylcu">
|
|
|
|
<textarea
|
|
|
|
v-model="text"
|
|
|
|
:placeholder="i18n.ts.placeholder"
|
|
|
|
@input="onChange"
|
|
|
|
></textarea>
|
|
|
|
<button
|
|
|
|
:disabled="!changed"
|
|
|
|
class="_buttonPrimary"
|
|
|
|
@click="saveMemo"
|
|
|
|
>
|
|
|
|
{{ i18n.ts.save }}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</MkContainer>
|
2023-07-07 19:22:30 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, onUnmounted, reactive, ref, watch } from "vue";
|
|
|
|
import {
|
2023-07-23 13:31:28 +00:00
|
|
|
useWidgetPropsManager,
|
|
|
|
Widget,
|
|
|
|
WidgetComponentEmits,
|
|
|
|
WidgetComponentExpose,
|
|
|
|
WidgetComponentProps,
|
2023-07-07 19:22:30 +00:00
|
|
|
} from "./widget";
|
|
|
|
import { GetFormResultType } from "@/scripts/form";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import MkContainer from "@/components/MkContainer.vue";
|
|
|
|
import { defaultStore } from "@/store";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
|
|
|
|
const name = "memo";
|
|
|
|
|
|
|
|
const widgetPropsDef = {
|
2023-07-23 13:31:28 +00:00
|
|
|
showHeader: {
|
|
|
|
type: "boolean" as const,
|
|
|
|
default: true,
|
|
|
|
},
|
2023-07-07 19:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// Currently, due to a limitation of vue, imported types cannot be passed to generics.
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps> }>();
|
|
|
|
const emit = defineEmits<{ (ev: "updateProps", props: WidgetProps) }>();
|
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(
|
2023-07-23 13:31:28 +00:00
|
|
|
name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit
|
2023-07-07 19:22:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const text = ref<string | null>(defaultStore.state.memo);
|
|
|
|
const changed = ref(false);
|
|
|
|
let timeoutId;
|
|
|
|
|
|
|
|
const saveMemo = () => {
|
2023-07-23 13:31:28 +00:00
|
|
|
defaultStore.set("memo", text.value);
|
|
|
|
changed.value = false;
|
2023-07-07 19:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const onChange = () => {
|
2023-07-23 13:31:28 +00:00
|
|
|
changed.value = true;
|
|
|
|
window.clearTimeout(timeoutId);
|
|
|
|
timeoutId = window.setTimeout(saveMemo, 1000);
|
2023-07-07 19:22:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
watch(
|
2023-07-23 13:31:28 +00:00
|
|
|
() => defaultStore.reactiveState.memo,
|
|
|
|
(newText) => {
|
|
|
|
text.value = newText.value;
|
|
|
|
}
|
2023-07-07 19:22:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
2023-07-23 13:31:28 +00:00
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2023-07-07 19:22:30 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.otgbylcu {
|
2023-07-23 13:31:28 +00:00
|
|
|
padding-bottom: 28px + 16px;
|
|
|
|
|
|
|
|
> textarea {
|
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
max-width: 100%;
|
|
|
|
min-width: 100%;
|
|
|
|
padding: 16px;
|
|
|
|
color: var(--fg);
|
|
|
|
background: transparent;
|
|
|
|
border: none;
|
|
|
|
border-bottom: solid 0.5px var(--divider);
|
|
|
|
border-radius: 0;
|
|
|
|
box-sizing: border-box;
|
|
|
|
font: inherit;
|
|
|
|
font-size: 0.9em;
|
|
|
|
|
|
|
|
&:focus-visible {
|
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> button {
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
bottom: 8px;
|
|
|
|
right: 8px;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0 10px;
|
|
|
|
height: 28px;
|
|
|
|
outline: none;
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
|
|
&:disabled {
|
|
|
|
opacity: 0.7;
|
|
|
|
cursor: default;
|
|
|
|
}
|
|
|
|
}
|
2023-07-07 19:22:30 +00:00
|
|
|
}
|
|
|
|
</style>
|