Final part to get TS building.
This commit is contained in:
parent
0b909b434a
commit
7db70a602d
|
@ -1,3 +1,4 @@
|
||||||
declare module "./helpers" {
|
declare module "./helpers" {
|
||||||
export const cloneDeep: <T>(obj: T) => T
|
export const cloneDeep: <T>(obj: T) => T
|
||||||
|
export const copyToClipboard: (value: any) => any
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,40 +1,42 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { JsonFormatter } from "@budibase/frontend-core"
|
import { JsonFormatter } from "@budibase/frontend-core"
|
||||||
import { Icon, ProgressCircle, notifications } from "@budibase/bbui"
|
import { Icon, ProgressCircle, notifications } from "@budibase/bbui"
|
||||||
import { copyToClipboard } from "@budibase/bbui/helpers"
|
import { Helpers } from "@budibase/bbui"
|
||||||
import { fade } from "svelte/transition"
|
import { fade } from "svelte/transition"
|
||||||
import { UserScriptError } from "@budibase/string-templates"
|
import { UserScriptError } from "@budibase/string-templates"
|
||||||
|
|
||||||
export let expressionResult
|
export let expressionResult
|
||||||
export let expressionError
|
export let expressionError
|
||||||
export let evaluating = false
|
export let evaluating = false
|
||||||
export let expression = null
|
export let expression: string | null = null
|
||||||
|
|
||||||
$: error = expressionError != null
|
$: error = expressionError != null
|
||||||
$: empty = expression == null || expression?.trim() === ""
|
$: empty = expression == null || expression?.trim() === ""
|
||||||
$: success = !error && !empty
|
$: success = !error && !empty
|
||||||
$: highlightedResult = highlight(expressionResult)
|
$: highlightedResult = highlight(expressionResult)
|
||||||
|
|
||||||
const formatError = err => {
|
const formatError = (err: any) => {
|
||||||
if (err.code === UserScriptError.code) {
|
if (err.code === UserScriptError.code) {
|
||||||
return err.userScriptError.toString()
|
return err.userScriptError.toString()
|
||||||
}
|
}
|
||||||
return err.toString()
|
return err.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
const highlight = json => {
|
const highlight = (json: string | null) => {
|
||||||
if (json == null) {
|
if (json == null) {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to parse and then stringify, in case this is valid result
|
// Attempt to parse and then stringify, in case this is valid result
|
||||||
|
let jsonString: string
|
||||||
try {
|
try {
|
||||||
json = JSON.stringify(JSON.parse(json), null, 2)
|
jsonString = JSON.stringify(JSON.parse(json), null, 2)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Ignore
|
// Ignore
|
||||||
|
jsonString = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return JsonFormatter.format(json, {
|
return JsonFormatter.format(jsonString, {
|
||||||
keyColor: "#e06c75",
|
keyColor: "#e06c75",
|
||||||
numberColor: "#e5c07b",
|
numberColor: "#e5c07b",
|
||||||
stringColor: "#98c379",
|
stringColor: "#98c379",
|
||||||
|
@ -49,7 +51,7 @@
|
||||||
if (typeof clipboardVal === "object") {
|
if (typeof clipboardVal === "object") {
|
||||||
clipboardVal = JSON.stringify(clipboardVal, null, 2)
|
clipboardVal = JSON.stringify(clipboardVal, null, 2)
|
||||||
}
|
}
|
||||||
copyToClipboard(clipboardVal)
|
Helpers.copyToClipboard(clipboardVal)
|
||||||
notifications.success("Value copied to clipboard")
|
notifications.success("Value copied to clipboard")
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue