2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
2022-05-28 08:28:12 +03:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader" class="mkw-memo">
|
2021-04-20 17:22:59 +03:00
|
|
|
<template #header><i class="fas fa-sticky-note"></i>{{ $ts._widgets.memo }}</template>
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2020-07-11 04:13:11 +03:00
|
|
|
<div class="otgbylcu">
|
2020-12-26 03:47:36 +02:00
|
|
|
<textarea v-model="text" :placeholder="$ts.placeholder" @input="onChange"></textarea>
|
2021-11-19 12:36:12 +02:00
|
|
|
<button :disabled="!changed" class="_buttonPrimary" @click="saveMemo">{{ $ts.save }}</button>
|
2020-07-11 04:13:11 +03:00
|
|
|
</div>
|
2020-10-17 14:12:00 +03:00
|
|
|
</MkContainer>
|
2020-01-29 21:37:25 +02:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, onUnmounted, reactive, ref, watch } from 'vue';
|
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2021-11-11 19:02:25 +02:00
|
|
|
import * as os from '@/os';
|
2022-01-08 13:30:01 +02:00
|
|
|
import MkContainer from '@/components/ui/container.vue';
|
|
|
|
import { defaultStore } from '@/store';
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const name = 'memo';
|
2020-10-17 14:12:00 +03:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
2022-01-08 13:30:01 +02:00
|
|
|
};
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
2022-05-25 10:43:12 +03:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-08 13:30:01 +02: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 03:14:14 +02:00
|
|
|
window.clearTimeout(timeoutId);
|
|
|
|
timeoutId = window.setTimeout(saveMemo, 1000);
|
2022-01-08 13:30:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
watch(() => defaultStore.reactiveState.memo, newText => {
|
|
|
|
text.value = newText.value;
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-01-29 21:37:25 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.otgbylcu {
|
|
|
|
padding-bottom: 28px + 16px;
|
|
|
|
|
|
|
|
> textarea {
|
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
max-width: 100%;
|
|
|
|
min-width: 100%;
|
|
|
|
padding: 16px;
|
2021-02-06 14:36:47 +02:00
|
|
|
color: var(--fg);
|
|
|
|
background: transparent;
|
2020-01-29 21:37:25 +02:00
|
|
|
border: none;
|
2021-04-10 06:40:50 +03:00
|
|
|
border-bottom: solid 0.5px var(--divider);
|
2020-01-29 21:37:25 +02:00
|
|
|
border-radius: 0;
|
2020-03-29 05:06:58 +03:00
|
|
|
box-sizing: border-box;
|
2021-02-06 14:36:47 +02:00
|
|
|
font: inherit;
|
|
|
|
font-size: 0.9em;
|
|
|
|
|
2021-10-02 20:46:58 +03:00
|
|
|
&:focus-visible {
|
2021-02-06 14:36:47 +02:00
|
|
|
outline: none;
|
|
|
|
}
|
2020-01-29 21:37:25 +02: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>
|