2020-01-29 19:37:25 +00:00
|
|
|
<template>
|
2023-05-19 07:20:53 +00:00
|
|
|
<MkContainer :showHeader="widgetProps.showHeader" data-cy-mkw-memo class="mkw-memo">
|
2023-01-14 23:30:29 +00:00
|
|
|
<template #icon><i class="ti ti-note"></i></template>
|
|
|
|
<template #header>{{ i18n.ts._widgets.memo }}</template>
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-15 05:03:28 +00:00
|
|
|
<div :class="$style.root">
|
2023-03-10 10:51:35 +00:00
|
|
|
<textarea v-model="text" :style="`height: ${widgetProps.height}px;`" :class="$style.textarea" :placeholder="i18n.ts.placeholder" @input="onChange"></textarea>
|
2023-01-15 05:03:28 +00:00
|
|
|
<button :class="$style.save" :disabled="!changed" class="_buttonPrimary" @click="saveMemo">{{ i18n.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>
|
2023-02-16 14:09:41 +00:00
|
|
|
import { ref, watch } from 'vue';
|
2023-05-19 07:20:53 +00:00
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2022-07-20 13:24:26 +00:00
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
2022-09-06 09:21:49 +00:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2022-01-08 11:30:01 +00:00
|
|
|
import { defaultStore } from '@/store';
|
2022-07-20 13:24:26 +00:00
|
|
|
import { i18n } from '@/i18n';
|
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
|
|
|
},
|
2023-03-10 10:51:35 +00:00
|
|
|
height: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 100,
|
|
|
|
},
|
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
|
|
|
|
2023-05-19 07:20:53 +00:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<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>
|
|
|
|
|
2023-01-15 05:03:28 +00:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2020-01-29 19:37:25 +00:00
|
|
|
padding-bottom: 28px + 16px;
|
2023-01-15 05:03:28 +00:00
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-15 05:03:28 +00: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 19:37:25 +00:00
|
|
|
outline: none;
|
2023-01-15 05:03:28 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-01-15 05:03:28 +00: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 19:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|