2023-07-27 14:31:52 +09:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2023-05-19 16:20:53 +09:00
|
|
|
<MkContainer :showHeader="widgetProps.showHeader" data-cy-mkw-memo class="mkw-memo">
|
2023-01-15 08:30:29 +09:00
|
|
|
<template #icon><i class="ti ti-note"></i></template>
|
|
|
|
<template #header>{{ i18n.ts._widgets.memo }}</template>
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-01-15 14:03:28 +09:00
|
|
|
<div :class="$style.root">
|
2023-03-10 19:51:35 +09:00
|
|
|
<textarea v-model="text" :style="`height: ${widgetProps.height}px;`" :class="$style.textarea" :placeholder="i18n.ts.placeholder" @input="onChange"></textarea>
|
2023-01-15 14:03:28 +09:00
|
|
|
<button :class="$style.save" :disabled="!changed" class="_buttonPrimary" @click="saveMemo">{{ i18n.ts.save }}</button>
|
2020-07-11 10:13:11 +09:00
|
|
|
</div>
|
2020-10-17 20:12:00 +09:00
|
|
|
</MkContainer>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 23:09:41 +09:00
|
|
|
import { ref, watch } from 'vue';
|
2023-09-29 11:22:59 +09:00
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
|
2023-09-19 16:37:43 +09:00
|
|
|
import { GetFormResultType } from '@/scripts/form.js';
|
2022-09-06 18:21:49 +09:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2023-09-19 16:37:43 +09:00
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const name = 'memo';
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
2023-03-10 19:51:35 +09:00
|
|
|
height: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 100,
|
|
|
|
},
|
2022-01-08 20:30:01 +09:00
|
|
|
};
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-05-19 16:20:53 +09:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const text = ref<string | null>(defaultStore.state.memo);
|
|
|
|
const changed = ref(false);
|
|
|
|
let timeoutId;
|
|
|
|
|
|
|
|
const saveMemo = () => {
|
|
|
|
defaultStore.set('memo', text.value);
|
|
|
|
changed.value = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
const onChange = () => {
|
|
|
|
changed.value = true;
|
2022-01-16 10:14:14 +09:00
|
|
|
window.clearTimeout(timeoutId);
|
|
|
|
timeoutId = window.setTimeout(saveMemo, 1000);
|
2022-01-08 20:30:01 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
watch(() => defaultStore.reactiveState.memo, newText => {
|
|
|
|
text.value = newText.value;
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2023-01-15 14:03:28 +09:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2020-01-30 04:37:25 +09:00
|
|
|
padding-bottom: 28px + 16px;
|
2023-01-15 14:03:28 +09:00
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-01-15 14:03:28 +09:00
|
|
|
.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 {
|
2020-01-30 04:37:25 +09:00
|
|
|
outline: none;
|
2023-01-15 14:03:28 +09:00
|
|
|
}
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-01-15 14:03:28 +09:00
|
|
|
.save {
|
|
|
|
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;
|
2020-01-30 04:37:25 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|