Inline edit and checklist improvements [SCI-7031] (#4340)

* Inline edit and checklist improvements [SCI-7031]

* Fix smart annotations in inline edit [SCI-7031]
This commit is contained in:
artoscinote 2022-08-10 14:43:23 +02:00 committed by GitHub
parent f1013c59fd
commit a37c236518
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 26 deletions

View file

@ -4,20 +4,15 @@
column-gap: .25em; column-gap: .25em;
display: grid; display: grid;
grid-template-columns: auto repeat(2, max-content); grid-template-columns: auto repeat(2, max-content);
margin-top: .3em; transition: .4s $timing-function-sharp border;
transition: .4s $timing-function-sharp;
&.editing .sci-inline-edit__content { &.editing .sci-inline-edit__content {
background-color: $color-white;
.sci-inline-edit__content { .sci-inline-edit__content {
padding-top: 0; padding-top: 0;
} }
} }
.sci-inline-edit__content { .sci-inline-edit__content {
border: $border-transparent;
border-radius: 4px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin-left: -.25em; margin-left: -.25em;
@ -26,7 +21,14 @@
position: relative; position: relative;
width: 100%; width: 100%;
textarea,
.sci-inline-edit__view { .sci-inline-edit__view {
min-height: 36px;
padding: .3em .2em .2em;
}
.sci-inline-edit__view {
border: 1px solid transparent;
cursor: pointer; cursor: pointer;
white-space: pre-wrap; white-space: pre-wrap;
width: 100%; width: 100%;
@ -37,12 +39,11 @@
} }
textarea { textarea {
background: transparent; background-color: $color-white;
border: 0; border: 1px solid $brand-focus;
min-height: 1em; border-radius: 4px;
outline: none; outline: none;
overflow: hidden; overflow: hidden;
padding: 0;
width: 100%; width: 100%;
&:focus { &:focus {
@ -61,14 +62,16 @@
} }
&.editing { &.editing {
margin-top: 0;
.sci-inline-edit__content { .sci-inline-edit__content {
background-color: $color-white;
border-color: $brand-focus;
&.error { &.error {
border-color: $brand-danger; border-color: $brand-danger;
margin-bottom: 16px; margin-bottom: 16px;
textarea {
border-color: $brand-danger;
}
} }
} }

View file

@ -61,7 +61,7 @@
} }
.sci-checkbox-container { .sci-checkbox-container {
margin: 8px 0; margin: 11px 0;
&.disabled { &.disabled {
pointer-events: none; pointer-events: none;

View file

@ -157,14 +157,10 @@
padding-left: calc(var(--left-component-padding) * 2); padding-left: calc(var(--left-component-padding) * 2);
.step-element-name { .step-element-name {
.sci-inline-edit__view { .sci-inline-edit__view,
margin-bottom: .25em; textarea {
padding-top: .25em; padding-bottom: .1em;
} padding-top: .5em;
.sci-inline-edit__content textarea {
margin-bottom: .25em;
margin-top: .25em;
} }
} }
} }

View file

@ -1,5 +1,5 @@
<template> <template>
<div class="step-checklist-item" :class="{ 'step-element--locked': !(updateUrl || toggleUrl) }"> <div class="step-checklist-item" :class="{ 'step-element--locked': checklistItem.id && !(updateUrl || toggleUrl) }">
<div class="step-element-header" :class="{ 'locked': locked || editingText, 'editing-name': editingText }"> <div class="step-element-header" :class="{ 'locked': locked || editingText, 'editing-name': editingText }">
<div v-if="reorderChecklistItemUrl" class="step-element-grip step-element-grip--draggable" :class="{ 'step-element-grip--disabled': !draggable }"> <div v-if="reorderChecklistItemUrl" class="step-element-grip step-element-grip--draggable" :class="{ 'step-element-grip--disabled': !draggable }">
<i class="fas fa-grip-vertical"></i> <i class="fas fa-grip-vertical"></i>
@ -18,7 +18,7 @@
<div v-else class="sci-checkbox-view-mode"></div> <div v-else class="sci-checkbox-view-mode"></div>
<div class="step-checklist-text"> <div class="step-checklist-text">
<InlineEdit <InlineEdit
:class="{ 'step-element--locked': !updateUrl }" :class="{ 'step-element--locked': checklistItem.id && !updateUrl }"
:value="checklistItem.attributes.text" :value="checklistItem.attributes.text"
:sa_value="checklistItem.attributes.sa_text" :sa_value="checklistItem.attributes.sa_text"
:characterLimit="10000" :characterLimit="10000"

View file

@ -13,7 +13,7 @@
@blur="handleBlur" @blur="handleBlur"
@keyup.escape="cancelEdit" @keyup.escape="cancelEdit"
></textarea> ></textarea>
<div v-else @click="enableEdit($event)" class="sci-inline-edit__view" v-html="sa_value || value || placeholder" :class="{ 'blank': isBlank }"></div> <div v-else @click="enableEdit($event)" class="sci-inline-edit__view" v-html="(smartAnnotation ? sa_value : value) || placeholder" :class="{ 'blank': isBlank }"></div>
<div v-if="editing && error" class="sci-inline-edit__error"> <div v-if="editing && error" class="sci-inline-edit__error">
{{ error }} {{ error }}
</div> </div>
@ -52,6 +52,7 @@
data() { data() {
return { return {
editing: false, editing: false,
dirty: false,
newValue: '' newValue: ''
} }
}, },
@ -142,6 +143,8 @@
this.$emit('editingDisabled'); this.$emit('editingDisabled');
}, },
handlePaste(e) { handlePaste(e) {
this.dirty = true;
if (!this.multilinePaste) return; if (!this.multilinePaste) return;
let lines = (e.originalEvent || e).clipboardData.getData('text/plain').split(/[\n\r]/); let lines = (e.originalEvent || e).clipboardData.getData('text/plain').split(/[\n\r]/);
lines = lines.filter((l) => l).map((l) => l.trim()); lines = lines.filter((l) => l).map((l) => l.trim());
@ -152,6 +155,7 @@
} }
}, },
handleInput() { handleInput() {
this.dirty = true;
if (!this.allowNewLine) { if (!this.allowNewLine) {
this.newValue = this.newValue.replace(/^[\n\r]+|[\n\r]+$/g, ''); this.newValue = this.newValue.replace(/^[\n\r]+|[\n\r]+$/g, '');
} }
@ -162,6 +166,8 @@
this.cancelEdit(); this.cancelEdit();
} else if (e.key == 'Enter' && this.saveOnEnter) { } else if (e.key == 'Enter' && this.saveOnEnter) {
this.update(); this.update();
} else {
this.dirty = true;
} }
}, },
resize() { resize() {
@ -171,9 +177,14 @@
this.$refs.input.style.height = (this.$refs.input.scrollHeight) + "px"; this.$refs.input.style.height = (this.$refs.input.scrollHeight) + "px";
}, },
update() { update() {
if (!this.dirty && !this.isBlank) {
this.editing = false;
return;
}
setTimeout(() => { setTimeout(() => {
if(this.error) return; if(this.error) return;
if(!this.editing) return; if(!this.$refs.input) return;
this.newValue = this.$refs.input.value // Fix for smart annotation this.newValue = this.$refs.input.value // Fix for smart annotation
this.newValue = this.newValue.trim(); this.newValue = this.newValue.trim();
this.editing = false; this.editing = false;