feat: tooltip on hovering environment variables
This commit is contained in:
@@ -21,9 +21,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { defineComponent } from "@nuxtjs/composition-api"
|
||||||
import IntervalTree from "node-interval-tree"
|
import IntervalTree from "node-interval-tree"
|
||||||
import debounce from "lodash/debounce"
|
import debounce from "lodash/debounce"
|
||||||
import isUndefined from "lodash/isUndefined"
|
import isUndefined from "lodash/isUndefined"
|
||||||
|
import { tippy } from "vue-tippy"
|
||||||
import { getCurrentEnvironment } from "~/newstore/environments"
|
import { getCurrentEnvironment } from "~/newstore/environments"
|
||||||
|
|
||||||
const tagsToReplace = {
|
const tagsToReplace = {
|
||||||
@@ -32,7 +34,7 @@ const tagsToReplace = {
|
|||||||
">": ">",
|
">": ">",
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
value: {
|
value: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -47,6 +49,7 @@ export default {
|
|||||||
default: "",
|
default: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
internalValue: "",
|
internalValue: "",
|
||||||
@@ -55,7 +58,7 @@ export default {
|
|||||||
highlight: [
|
highlight: [
|
||||||
{
|
{
|
||||||
text: /(<<\w+>>)/g,
|
text: /(<<\w+>>)/g,
|
||||||
style: "text-white rounded px-1 mx-0.5",
|
style: "text-white cursor-help rounded px-1 mx-0.5",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
highlightEnabled: true,
|
highlightEnabled: true,
|
||||||
@@ -65,6 +68,7 @@ export default {
|
|||||||
fireOnEnabled: true,
|
fireOnEnabled: true,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
highlightStyle() {
|
highlightStyle() {
|
||||||
this.processHighlights()
|
this.processHighlights()
|
||||||
@@ -90,6 +94,7 @@ export default {
|
|||||||
this.restoreSelection(this.$refs.editor, selection)
|
this.restoreSelection(this.$refs.editor, selection)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.fireOnEnabled)
|
if (this.fireOnEnabled)
|
||||||
this.$refs.editor.addEventListener(this.fireOn, this.handleChange)
|
this.$refs.editor.addEventListener(this.fireOn, this.handleChange)
|
||||||
@@ -108,6 +113,8 @@ export default {
|
|||||||
this.debouncedHandler()
|
this.debouncedHandler()
|
||||||
},
|
},
|
||||||
processHighlights() {
|
processHighlights() {
|
||||||
|
this.renderTippy()
|
||||||
|
|
||||||
if (!this.highlightEnabled) {
|
if (!this.highlightEnabled) {
|
||||||
this.htmlOutput = this.internalValue
|
this.htmlOutput = this.internalValue
|
||||||
this.$emit("input", this.internalValue)
|
this.$emit("input", this.internalValue)
|
||||||
@@ -183,9 +190,9 @@ export default {
|
|||||||
?.value === undefined
|
?.value === undefined
|
||||||
? "bg-red-500"
|
? "bg-red-500"
|
||||||
: "bg-accentDark"
|
: "bg-accentDark"
|
||||||
}" title="Environment: ${
|
}" v-tippy data-tippy-content="environment: ${
|
||||||
getCurrentEnvironment().name
|
getCurrentEnvironment().name
|
||||||
} \xA0-\xA0 Value: ${
|
} • value: ${
|
||||||
getCurrentEnvironment().variables.find((k) => k.key === envVar)?.value
|
getCurrentEnvironment().variables.find((k) => k.key === envVar)?.value
|
||||||
}">${this.safe_tags_replace(
|
}">${this.safe_tags_replace(
|
||||||
this.internalValue.substring(position.start, position.end + 1)
|
this.internalValue.substring(position.start, position.end + 1)
|
||||||
@@ -206,6 +213,25 @@ export default {
|
|||||||
this.htmlOutput = result
|
this.htmlOutput = result
|
||||||
this.$emit("input", this.internalValue)
|
this.$emit("input", this.internalValue)
|
||||||
},
|
},
|
||||||
|
renderTippy() {
|
||||||
|
const tippable = document.querySelectorAll("[v-tippy]")
|
||||||
|
tippable.forEach((t) => {
|
||||||
|
tippy(t, {
|
||||||
|
content: t.dataset["tippy-content"],
|
||||||
|
theme: "tooltip",
|
||||||
|
popperOptions: {
|
||||||
|
modifiers: {
|
||||||
|
preventOverflow: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
hide: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
},
|
||||||
insertRange(start, end, highlightObj, intervalTree) {
|
insertRange(start, end, highlightObj, intervalTree) {
|
||||||
const overlap = intervalTree.search(start, end)
|
const overlap = intervalTree.search(start, end)
|
||||||
const maxLengthOverlap = overlap.reduce((max, o) => {
|
const maxLengthOverlap = overlap.reduce((max, o) => {
|
||||||
@@ -413,7 +439,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user