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