2020-11-25 04:31:34 -08:00
|
|
|
<template>
|
2021-09-29 08:50:45 -07:00
|
|
|
<div class="adhpbeos">
|
|
|
|
<div class="label" @click="focus"><slot name="label"></slot></div>
|
|
|
|
<div class="input" :class="{ disabled, focused, tall, pre }">
|
2022-07-20 06:24:26 -07:00
|
|
|
<textarea
|
|
|
|
ref="inputEl"
|
2021-09-29 08:50:45 -07:00
|
|
|
v-model="v"
|
2021-12-25 08:42:50 -08:00
|
|
|
v-adaptive-border
|
2021-11-19 02:36:12 -08:00
|
|
|
:class="{ code, _monospace: code }"
|
2021-09-29 08:50:45 -07:00
|
|
|
:disabled="disabled"
|
|
|
|
:required="required"
|
|
|
|
:readonly="readonly"
|
|
|
|
:placeholder="placeholder"
|
|
|
|
:pattern="pattern"
|
|
|
|
:autocomplete="autocomplete"
|
|
|
|
:spellcheck="spellcheck"
|
|
|
|
@focus="focused = true"
|
|
|
|
@blur="focused = false"
|
|
|
|
@keydown="onKeydown($event)"
|
|
|
|
@input="onInput"
|
|
|
|
></textarea>
|
2020-11-25 04:31:34 -08:00
|
|
|
</div>
|
2021-09-29 08:50:45 -07:00
|
|
|
<div class="caption"><slot name="caption"></slot></div>
|
2021-02-12 19:28:26 -08:00
|
|
|
|
2022-07-20 06:24:26 -07:00
|
|
|
<MkButton v-if="manualSave && changed" primary class="save" @click="updated"><i class="fas fa-save"></i> {{ i18n.ts.save }}</MkButton>
|
2021-09-29 08:50:45 -07:00
|
|
|
</div>
|
2020-11-25 04:31:34 -08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-09-29 08:50:45 -07:00
|
|
|
import { defineComponent, onMounted, onUnmounted, nextTick, ref, watch, computed, toRefs } from 'vue';
|
|
|
|
import { debounce } from 'throttle-debounce';
|
2022-07-20 06:24:26 -07:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import { i18n } from '@/i18n';
|
2020-11-25 04:31:34 -08:00
|
|
|
|
|
|
|
export default defineComponent({
|
2021-02-12 19:28:26 -08:00
|
|
|
components: {
|
2021-09-29 08:50:45 -07:00
|
|
|
MkButton,
|
2021-02-12 19:28:26 -08:00
|
|
|
},
|
2021-09-29 08:50:45 -07:00
|
|
|
|
2020-11-25 04:31:34 -08:00
|
|
|
props: {
|
2021-09-29 08:50:45 -07:00
|
|
|
modelValue: {
|
2022-07-20 06:24:26 -07:00
|
|
|
required: true,
|
2021-09-29 08:50:45 -07:00
|
|
|
},
|
|
|
|
type: {
|
|
|
|
type: String,
|
2022-07-20 06:24:26 -07:00
|
|
|
required: false,
|
2020-11-25 04:31:34 -08:00
|
|
|
},
|
|
|
|
required: {
|
|
|
|
type: Boolean,
|
2022-07-20 06:24:26 -07:00
|
|
|
required: false,
|
2020-11-25 04:31:34 -08:00
|
|
|
},
|
|
|
|
readonly: {
|
|
|
|
type: Boolean,
|
2022-07-20 06:24:26 -07:00
|
|
|
required: false,
|
2020-11-25 04:31:34 -08:00
|
|
|
},
|
2021-09-29 08:50:45 -07:00
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
2022-07-20 06:24:26 -07:00
|
|
|
required: false,
|
2021-09-29 08:50:45 -07:00
|
|
|
},
|
2020-11-25 04:31:34 -08:00
|
|
|
pattern: {
|
|
|
|
type: String,
|
2022-07-20 06:24:26 -07:00
|
|
|
required: false,
|
2020-11-25 04:31:34 -08:00
|
|
|
},
|
2021-09-29 08:50:45 -07:00
|
|
|
placeholder: {
|
2020-11-25 04:31:34 -08:00
|
|
|
type: String,
|
2022-07-20 06:24:26 -07:00
|
|
|
required: false,
|
2020-11-25 04:31:34 -08:00
|
|
|
},
|
2021-09-29 08:50:45 -07:00
|
|
|
autofocus: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-07-20 06:24:26 -07:00
|
|
|
default: false,
|
2021-09-29 08:50:45 -07:00
|
|
|
},
|
|
|
|
autocomplete: {
|
2022-07-20 06:24:26 -07:00
|
|
|
required: false,
|
2021-09-29 08:50:45 -07:00
|
|
|
},
|
|
|
|
spellcheck: {
|
2022-07-20 06:24:26 -07:00
|
|
|
required: false,
|
2021-09-29 08:50:45 -07:00
|
|
|
},
|
2020-11-25 04:31:34 -08:00
|
|
|
code: {
|
|
|
|
type: Boolean,
|
2022-07-20 06:24:26 -07:00
|
|
|
required: false,
|
2020-11-25 04:31:34 -08:00
|
|
|
},
|
|
|
|
tall: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-07-20 06:24:26 -07:00
|
|
|
default: false,
|
2020-11-25 04:31:34 -08:00
|
|
|
},
|
|
|
|
pre: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-07-20 06:24:26 -07:00
|
|
|
default: false,
|
2020-11-25 04:31:34 -08:00
|
|
|
},
|
2021-09-29 08:50:45 -07:00
|
|
|
debounce: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
2022-07-20 06:24:26 -07:00
|
|
|
default: false,
|
2021-09-29 08:50:45 -07:00
|
|
|
},
|
2021-02-12 19:28:26 -08:00
|
|
|
manualSave: {
|
|
|
|
type: Boolean,
|
2020-11-25 04:31:34 -08:00
|
|
|
required: false,
|
2022-07-20 06:24:26 -07:00
|
|
|
default: false,
|
2020-11-25 04:31:34 -08:00
|
|
|
},
|
|
|
|
},
|
2021-09-29 08:50:45 -07:00
|
|
|
|
|
|
|
emits: ['change', 'keydown', 'enter', 'update:modelValue'],
|
|
|
|
|
2021-02-12 19:28:26 -08:00
|
|
|
setup(props, context) {
|
2021-09-29 08:50:45 -07:00
|
|
|
const { modelValue, autofocus } = toRefs(props);
|
|
|
|
const v = ref(modelValue.value);
|
|
|
|
const focused = ref(false);
|
2021-02-12 19:28:26 -08:00
|
|
|
const changed = ref(false);
|
2021-09-29 08:50:45 -07:00
|
|
|
const invalid = ref(false);
|
|
|
|
const filled = computed(() => v.value !== '' && v.value != null);
|
2021-02-12 19:28:26 -08:00
|
|
|
const inputEl = ref(null);
|
2021-09-29 08:50:45 -07:00
|
|
|
|
2021-02-12 19:28:26 -08:00
|
|
|
const focus = () => inputEl.value.focus();
|
|
|
|
const onInput = (ev) => {
|
|
|
|
changed.value = true;
|
|
|
|
context.emit('change', ev);
|
|
|
|
};
|
2021-09-29 08:50:45 -07:00
|
|
|
const onKeydown = (ev: KeyboardEvent) => {
|
|
|
|
context.emit('keydown', ev);
|
|
|
|
|
|
|
|
if (ev.code === 'Enter') {
|
|
|
|
context.emit('enter');
|
|
|
|
}
|
|
|
|
};
|
2021-02-12 19:28:26 -08:00
|
|
|
|
|
|
|
const updated = () => {
|
|
|
|
changed.value = false;
|
2021-09-29 08:50:45 -07:00
|
|
|
context.emit('update:modelValue', v.value);
|
2021-02-12 19:28:26 -08:00
|
|
|
};
|
|
|
|
|
2021-09-29 08:50:45 -07:00
|
|
|
const debouncedUpdated = debounce(1000, updated);
|
|
|
|
|
|
|
|
watch(modelValue, newValue => {
|
2021-02-12 19:28:26 -08:00
|
|
|
v.value = newValue;
|
|
|
|
});
|
|
|
|
|
|
|
|
watch(v, newValue => {
|
|
|
|
if (!props.manualSave) {
|
2021-09-29 08:50:45 -07:00
|
|
|
if (props.debounce) {
|
|
|
|
debouncedUpdated();
|
|
|
|
} else {
|
|
|
|
updated();
|
|
|
|
}
|
2021-02-12 19:28:26 -08:00
|
|
|
}
|
2021-09-29 08:50:45 -07:00
|
|
|
|
|
|
|
invalid.value = inputEl.value.validity.badInput;
|
2021-02-12 19:28:26 -08:00
|
|
|
});
|
2021-09-29 08:50:45 -07:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
nextTick(() => {
|
|
|
|
if (autofocus.value) {
|
|
|
|
focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-25 04:31:34 -08:00
|
|
|
return {
|
2021-02-12 19:28:26 -08:00
|
|
|
v,
|
2021-09-29 08:50:45 -07:00
|
|
|
focused,
|
|
|
|
invalid,
|
2021-02-12 19:28:26 -08:00
|
|
|
changed,
|
2021-09-29 08:50:45 -07:00
|
|
|
filled,
|
|
|
|
inputEl,
|
2021-02-12 19:28:26 -08:00
|
|
|
focus,
|
|
|
|
onInput,
|
2021-09-29 08:50:45 -07:00
|
|
|
onKeydown,
|
|
|
|
updated,
|
2021-02-12 19:28:26 -08:00
|
|
|
};
|
2021-09-29 08:50:45 -07:00
|
|
|
},
|
2020-11-25 04:31:34 -08:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-09-29 08:50:45 -07:00
|
|
|
.adhpbeos {
|
|
|
|
> .label {
|
|
|
|
font-size: 0.85em;
|
2021-11-28 03:07:37 -08:00
|
|
|
padding: 0 0 8px 0;
|
2021-09-29 08:50:45 -07:00
|
|
|
user-select: none;
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .caption {
|
2021-11-28 03:07:37 -08:00
|
|
|
font-size: 0.85em;
|
|
|
|
padding: 8px 0 0 0;
|
2021-09-29 08:50:45 -07:00
|
|
|
color: var(--fgTransparentWeak);
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 04:31:34 -08:00
|
|
|
|
|
|
|
> .input {
|
|
|
|
position: relative;
|
2021-09-29 08:50:45 -07:00
|
|
|
|
2020-11-25 04:31:34 -08:00
|
|
|
> textarea {
|
2021-09-29 08:50:45 -07:00
|
|
|
appearance: none;
|
|
|
|
-webkit-appearance: none;
|
2020-11-25 04:31:34 -08:00
|
|
|
display: block;
|
|
|
|
width: 100%;
|
|
|
|
min-width: 100%;
|
|
|
|
max-width: 100%;
|
|
|
|
min-height: 130px;
|
|
|
|
margin: 0;
|
2021-09-29 08:50:45 -07:00
|
|
|
padding: 12px;
|
2020-11-25 04:31:34 -08:00
|
|
|
font: inherit;
|
|
|
|
font-weight: normal;
|
|
|
|
font-size: 1em;
|
2021-09-29 08:50:45 -07:00
|
|
|
color: var(--fg);
|
2021-12-25 08:42:50 -08:00
|
|
|
background: var(--panel);
|
|
|
|
border: solid 1px var(--panel);
|
2021-09-29 08:50:45 -07:00
|
|
|
border-radius: 6px;
|
2020-11-25 04:31:34 -08:00
|
|
|
outline: none;
|
|
|
|
box-shadow: none;
|
2021-09-29 08:50:45 -07:00
|
|
|
box-sizing: border-box;
|
|
|
|
transition: border-color 0.1s ease-out;
|
2020-11-25 04:31:34 -08:00
|
|
|
|
2021-09-29 08:50:45 -07:00
|
|
|
&:hover {
|
2021-12-25 08:42:50 -08:00
|
|
|
border-color: var(--inputBorderHover) !important;
|
2021-09-29 08:50:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.focused {
|
|
|
|
> textarea {
|
2021-12-25 08:42:50 -08:00
|
|
|
border-color: var(--accent) !important;
|
2020-11-25 04:31:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-29 08:50:45 -07:00
|
|
|
&.disabled {
|
|
|
|
opacity: 0.7;
|
|
|
|
|
|
|
|
&, * {
|
|
|
|
cursor: not-allowed !important;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&.tall {
|
2020-11-25 04:31:34 -08:00
|
|
|
> textarea {
|
|
|
|
min-height: 200px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-29 08:50:45 -07:00
|
|
|
&.pre {
|
2020-11-25 04:31:34 -08:00
|
|
|
> textarea {
|
|
|
|
white-space: pre;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-28 03:07:37 -08:00
|
|
|
|
|
|
|
> .save {
|
|
|
|
margin: 8px 0 0 0;
|
|
|
|
}
|
2020-11-25 04:31:34 -08:00
|
|
|
}
|
|
|
|
</style>
|