2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2022-05-28 07:28:12 +02:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader" class="mkw-memo">
|
2022-12-24 06:45:27 +01:00
|
|
|
<template #header><i class="ti ti-note"></i>{{ i18n.ts._widgets.memo }}</template>
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2020-07-11 03:13:11 +02:00
|
|
|
<div class="otgbylcu">
|
2022-07-20 15:24:26 +02:00
|
|
|
<textarea v-model="text" :placeholder="i18n.ts.placeholder" @input="onChange"></textarea>
|
|
|
|
<button :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>
|
|
|
|
import { onMounted, onUnmounted, reactive, ref, watch } from 'vue';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2022-07-20 15:24:26 +02:00
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
2021-11-11 18:02:25 +01:00
|
|
|
import * as os from '@/os';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2022-01-08 12:30:01 +01:00
|
|
|
import { defaultStore } from '@/store';
|
2022-07-20 15:24:26 +02:00
|
|
|
import { i18n } from '@/i18n';
|
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
|
|
|
},
|
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
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
2022-05-25 09:43:12 +02:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: 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>
|
|
|
|
|
2022-12-27 10:01:06 +01:00
|
|
|
<style lang="scss">
|
2020-01-29 20:37:25 +01:00
|
|
|
.otgbylcu {
|
|
|
|
padding-bottom: 28px + 16px;
|
|
|
|
|
|
|
|
> textarea {
|
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
max-width: 100%;
|
|
|
|
min-width: 100%;
|
|
|
|
padding: 16px;
|
2021-02-06 13:36:47 +01:00
|
|
|
color: var(--fg);
|
|
|
|
background: transparent;
|
2020-01-29 20:37:25 +01:00
|
|
|
border: none;
|
2021-04-10 05:40:50 +02:00
|
|
|
border-bottom: solid 0.5px var(--divider);
|
2020-01-29 20:37:25 +01:00
|
|
|
border-radius: 0;
|
2020-03-29 04:06:58 +02:00
|
|
|
box-sizing: border-box;
|
2021-02-06 13:36:47 +01:00
|
|
|
font: inherit;
|
|
|
|
font-size: 0.9em;
|
|
|
|
|
2021-10-02 19:46:58 +02:00
|
|
|
&:focus-visible {
|
2021-02-06 13:36:47 +01:00
|
|
|
outline: none;
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
> 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|