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