2021-02-15 21:03:29 +01:00
|
|
|
<script>
|
2021-04-22 16:34:18 +02:00
|
|
|
import { Icon, Input, Drawer, Button } from "@budibase/bbui"
|
2021-02-15 21:03:29 +01:00
|
|
|
import {
|
|
|
|
readableToRuntimeBinding,
|
|
|
|
runtimeToReadableBinding,
|
|
|
|
} from "builderStore/dataBinding"
|
2021-04-30 17:17:57 +02:00
|
|
|
import BindingPanel from "components/common/bindings/BindingPanel.svelte"
|
2021-02-15 21:03:29 +01:00
|
|
|
import { createEventDispatcher } from "svelte"
|
2021-10-12 17:52:56 +02:00
|
|
|
import { isJSBinding } from "@budibase/string-templates"
|
2021-02-15 21:03:29 +01:00
|
|
|
|
2021-02-26 14:53:51 +01:00
|
|
|
export let panel = BindingPanel
|
2021-02-15 21:03:29 +01:00
|
|
|
export let value = ""
|
|
|
|
export let bindings = []
|
2021-02-18 18:44:56 +01:00
|
|
|
export let title = "Bindings"
|
|
|
|
export let placeholder
|
2021-04-22 11:58:04 +02:00
|
|
|
export let label
|
2021-04-30 17:29:53 +02:00
|
|
|
export let disabled = false
|
2021-09-16 15:48:55 +02:00
|
|
|
export let fillWidth
|
2021-10-12 17:52:56 +02:00
|
|
|
export let allowJS = true
|
2021-02-15 21:03:29 +01:00
|
|
|
|
2021-04-22 11:58:04 +02:00
|
|
|
const dispatch = createEventDispatcher()
|
2021-02-15 21:03:29 +01:00
|
|
|
let bindingDrawer
|
2021-07-14 16:45:05 +02:00
|
|
|
let valid = true
|
2021-10-12 17:52:56 +02:00
|
|
|
|
2021-02-15 21:03:29 +01:00
|
|
|
$: readableValue = runtimeToReadableBinding(bindings, value)
|
2021-07-14 15:21:11 +02:00
|
|
|
$: tempValue = readableValue
|
2021-10-12 17:52:56 +02:00
|
|
|
$: isJS = isJSBinding(value)
|
2021-02-15 21:03:29 +01:00
|
|
|
|
2021-07-14 15:21:11 +02:00
|
|
|
const saveBinding = () => {
|
2021-02-15 21:03:29 +01:00
|
|
|
onChange(tempValue)
|
|
|
|
bindingDrawer.hide()
|
|
|
|
}
|
|
|
|
|
|
|
|
const onChange = value => {
|
|
|
|
dispatch("change", readableToRuntimeBinding(bindings, value))
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="control">
|
|
|
|
<Input
|
2021-04-22 11:58:04 +02:00
|
|
|
{label}
|
2021-04-30 17:29:53 +02:00
|
|
|
{disabled}
|
2021-10-12 17:52:56 +02:00
|
|
|
value={isJS ? "(JavaScript function)" : readableValue}
|
2021-04-16 14:07:38 +02:00
|
|
|
on:change={event => onChange(event.detail)}
|
2021-05-04 12:04:42 +02:00
|
|
|
{placeholder}
|
|
|
|
/>
|
2021-04-30 17:29:53 +02:00
|
|
|
{#if !disabled}
|
|
|
|
<div class="icon" on:click={bindingDrawer.show}>
|
|
|
|
<Icon size="S" name="FlashOn" />
|
|
|
|
</div>
|
|
|
|
{/if}
|
2021-02-15 21:03:29 +01:00
|
|
|
</div>
|
2021-09-16 13:15:32 +02:00
|
|
|
<Drawer {fillWidth} bind:this={bindingDrawer} {title}>
|
2021-04-22 16:34:18 +02:00
|
|
|
<svelte:fragment slot="description">
|
|
|
|
Add the objects on the left to enrich your text.
|
|
|
|
</svelte:fragment>
|
2021-07-14 16:45:05 +02:00
|
|
|
<Button cta slot="buttons" disabled={!valid} on:click={saveBinding}>
|
|
|
|
Save
|
|
|
|
</Button>
|
2021-04-22 16:34:18 +02:00
|
|
|
<svelte:component
|
|
|
|
this={panel}
|
2021-05-04 12:04:42 +02:00
|
|
|
slot="body"
|
2021-07-14 16:45:05 +02:00
|
|
|
bind:valid
|
2021-04-22 16:34:18 +02:00
|
|
|
value={readableValue}
|
2021-07-14 15:21:11 +02:00
|
|
|
on:change={event => (tempValue = event.detail)}
|
2021-05-04 12:04:42 +02:00
|
|
|
bindableProperties={bindings}
|
2021-10-12 17:52:56 +02:00
|
|
|
{allowJS}
|
2021-05-04 12:04:42 +02:00
|
|
|
/>
|
2021-02-15 21:03:29 +01:00
|
|
|
</Drawer>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.control {
|
|
|
|
flex: 1;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
.icon {
|
2021-04-19 15:11:46 +02:00
|
|
|
right: 1px;
|
|
|
|
bottom: 1px;
|
2021-02-15 21:03:29 +01:00
|
|
|
position: absolute;
|
2021-04-20 21:06:27 +02:00
|
|
|
justify-content: center;
|
2021-02-15 21:03:29 +01:00
|
|
|
align-items: center;
|
|
|
|
display: flex;
|
2021-04-20 21:06:27 +02:00
|
|
|
flex-direction: row;
|
2021-02-15 21:03:29 +01:00
|
|
|
box-sizing: border-box;
|
2021-04-19 15:11:46 +02:00
|
|
|
border-left: 1px solid var(--spectrum-alias-border-color);
|
|
|
|
border-top-right-radius: var(--spectrum-alias-border-radius-regular);
|
|
|
|
border-bottom-right-radius: var(--spectrum-alias-border-radius-regular);
|
2021-04-20 21:06:27 +02:00
|
|
|
width: 31px;
|
|
|
|
color: var(--spectrum-alias-text-color);
|
|
|
|
background-color: var(--spectrum-global-color-gray-75);
|
|
|
|
transition: background-color
|
|
|
|
var(--spectrum-global-animation-duration-100, 130ms),
|
|
|
|
box-shadow var(--spectrum-global-animation-duration-100, 130ms),
|
|
|
|
border-color var(--spectrum-global-animation-duration-100, 130ms);
|
2021-04-22 11:58:04 +02:00
|
|
|
height: calc(var(--spectrum-alias-item-height-m) - 2px);
|
2021-02-15 21:03:29 +01:00
|
|
|
}
|
2021-04-11 13:02:01 +02:00
|
|
|
|
2021-02-15 21:03:29 +01:00
|
|
|
.icon:hover {
|
|
|
|
cursor: pointer;
|
2021-04-20 21:06:27 +02:00
|
|
|
color: var(--spectrum-alias-text-color-hover);
|
|
|
|
background-color: var(--spectrum-global-color-gray-50);
|
|
|
|
border-color: var(--spectrum-alias-border-color-hover);
|
2021-02-15 21:03:29 +01:00
|
|
|
}
|
|
|
|
</style>
|