mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-29 02:49:13 -04:00
feat(c-input-text): handle paste htm
Add paste-html prop to allow pasting html directly
This commit is contained in:
parent
a07806cd15
commit
5641816957
1 changed files with 27 additions and 1 deletions
|
@ -31,6 +31,7 @@ const props = withDefaults(
|
||||||
autosize?: boolean
|
autosize?: boolean
|
||||||
autofocus?: boolean
|
autofocus?: boolean
|
||||||
monospace?: boolean
|
monospace?: boolean
|
||||||
|
pasteHtml?: boolean
|
||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
value: '',
|
value: '',
|
||||||
|
@ -58,13 +59,14 @@ const props = withDefaults(
|
||||||
autosize: false,
|
autosize: false,
|
||||||
autofocus: false,
|
autofocus: false,
|
||||||
monospace: false,
|
monospace: false,
|
||||||
|
pasteHtml: false,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
const emit = defineEmits(['update:value']);
|
const emit = defineEmits(['update:value']);
|
||||||
const value = useVModel(props, 'value', emit);
|
const value = useVModel(props, 'value', emit);
|
||||||
const showPassword = ref(false);
|
const showPassword = ref(false);
|
||||||
|
|
||||||
const { id, placeholder, label, validationRules, labelPosition, labelWidth, labelAlign, autosize, readonly, disabled, clearable, type, multiline, rows, rawText, autofocus, monospace } = toRefs(props);
|
const { id, placeholder, label, validationRules, labelPosition, labelWidth, labelAlign, autosize, readonly, disabled, clearable, type, multiline, rows, rawText, autofocus, monospace, pasteHtml } = toRefs(props);
|
||||||
|
|
||||||
const validation
|
const validation
|
||||||
= props.validation
|
= props.validation
|
||||||
|
@ -81,6 +83,28 @@ const textareaRef = ref<HTMLTextAreaElement>();
|
||||||
const inputRef = ref<HTMLInputElement>();
|
const inputRef = ref<HTMLInputElement>();
|
||||||
const inputWrapperRef = ref<HTMLElement>();
|
const inputWrapperRef = ref<HTMLElement>();
|
||||||
|
|
||||||
|
interface HTMLElementWithValue {
|
||||||
|
value?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPasteInputHtml(evt: ClipboardEvent) {
|
||||||
|
if (!pasteHtml.value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const target = (evt.target as HTMLElementWithValue);
|
||||||
|
if (!target) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
evt.preventDefault();
|
||||||
|
const textHtmlData = evt.clipboardData?.getData('text/html');
|
||||||
|
if (textHtmlData && textHtmlData !== '') {
|
||||||
|
value.value = textHtmlData;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
[value, autosize, multiline, inputWrapperRef, textareaRef],
|
[value, autosize, multiline, inputWrapperRef, textareaRef],
|
||||||
() => nextTick(() => {
|
() => nextTick(() => {
|
||||||
|
@ -171,6 +195,7 @@ defineExpose({
|
||||||
:autocorrect="autocorrect ?? (rawText ? 'off' : undefined)"
|
:autocorrect="autocorrect ?? (rawText ? 'off' : undefined)"
|
||||||
:spellcheck="spellcheck ?? (rawText ? false : undefined)"
|
:spellcheck="spellcheck ?? (rawText ? false : undefined)"
|
||||||
:rows="rows"
|
:rows="rows"
|
||||||
|
@paste="onPasteInputHtml"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
|
@ -192,6 +217,7 @@ defineExpose({
|
||||||
:autocomplete="autocomplete ?? (rawText ? 'off' : undefined)"
|
:autocomplete="autocomplete ?? (rawText ? 'off' : undefined)"
|
||||||
:autocorrect="autocorrect ?? (rawText ? 'off' : undefined)"
|
:autocorrect="autocorrect ?? (rawText ? 'off' : undefined)"
|
||||||
:spellcheck="spellcheck ?? (rawText ? false : undefined)"
|
:spellcheck="spellcheck ?? (rawText ? false : undefined)"
|
||||||
|
@paste="onPasteInputHtml"
|
||||||
>
|
>
|
||||||
|
|
||||||
<c-button v-if="clearable && value" variant="text" circle size="small" @click="value = ''">
|
<c-button v-if="clearable && value" variant="text" circle size="small" @click="value = ''">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue