2020-02-10 17:58:20 +01:00
|
|
|
<script>
|
|
|
|
import { ArrowDownIcon } from "../common/Icons/";
|
|
|
|
import { store } from "../builderStore";
|
|
|
|
import { isBinding, getBinding, setBinding } from "../common/binding";
|
|
|
|
|
|
|
|
export let onChanged = () => {};
|
2020-02-10 18:11:22 +01:00
|
|
|
export let value = "";
|
2020-02-10 17:58:20 +01:00
|
|
|
|
|
|
|
let isOpen = false;
|
|
|
|
let stateBindings = [];
|
|
|
|
|
|
|
|
let bindingPath = "";
|
|
|
|
let bindingFallbackValue = "";
|
|
|
|
let bindingSource = "store";
|
2020-02-12 11:12:08 +01:00
|
|
|
let bindingValue = "";
|
2020-02-10 17:58:20 +01:00
|
|
|
|
|
|
|
const bind = (path, fallback, source) => {
|
|
|
|
if (!path) {
|
2020-02-12 11:12:08 +01:00
|
|
|
onChanged(fallback);
|
2020-02-10 17:58:20 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const binding = setBinding({ path, fallback, source });
|
|
|
|
onChanged(binding);
|
|
|
|
};
|
|
|
|
|
2020-02-10 18:11:22 +01:00
|
|
|
const setBindingPath = value =>
|
2020-02-10 17:58:20 +01:00
|
|
|
bind(value, bindingFallbackValue, bindingSource);
|
|
|
|
|
|
|
|
const setBindingFallback = value => bind(bindingPath, value, bindingSource);
|
|
|
|
|
|
|
|
const setBindingSource = value =>
|
|
|
|
bind(bindingPath, bindingFallbackValue, value);
|
|
|
|
|
|
|
|
$: {
|
2020-02-10 18:11:22 +01:00
|
|
|
const binding = getBinding(value);
|
2020-02-12 11:12:08 +01:00
|
|
|
if (bindingPath !== binding.path) isOpen = false;
|
2020-02-10 22:04:11 +01:00
|
|
|
bindingPath = binding.path;
|
2020-02-12 11:12:08 +01:00
|
|
|
bindingValue = typeof value === "object" ? "" : value;
|
|
|
|
bindingFallbackValue = binding.fallback || bindingValue;
|
|
|
|
|
2020-02-10 17:58:20 +01:00
|
|
|
const currentScreen = $store.screens.find(
|
2020-02-11 17:36:16 +01:00
|
|
|
({ name }) => name === $store.currentPreviewItem.name
|
2020-02-10 17:58:20 +01:00
|
|
|
);
|
|
|
|
stateBindings = currentScreen ? currentScreen.stateOrigins : [];
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="cascader">
|
|
|
|
<div class="input-box">
|
|
|
|
<input
|
2020-02-12 11:12:08 +01:00
|
|
|
class:bold={!bindingFallbackValue && bindingPath}
|
2020-02-10 17:58:20 +01:00
|
|
|
class="uk-input uk-form-small"
|
2020-02-12 11:12:08 +01:00
|
|
|
value={bindingFallbackValue || bindingPath}
|
2020-02-10 18:11:22 +01:00
|
|
|
on:change={e => {
|
|
|
|
setBindingFallback(e.target.value);
|
2020-02-10 22:04:11 +01:00
|
|
|
onChanged(e.target.value);
|
2020-02-10 18:11:22 +01:00
|
|
|
}} />
|
2020-02-10 17:58:20 +01:00
|
|
|
<button on:click={() => (isOpen = !isOpen)}>
|
2020-02-11 18:23:25 +01:00
|
|
|
<div
|
2020-02-10 17:58:20 +01:00
|
|
|
class="icon"
|
2020-02-12 11:12:08 +01:00
|
|
|
class:highlighted={bindingPath}
|
|
|
|
style={`transform: rotate(${isOpen ? 0 : 90}deg);`}>
|
2020-02-10 17:58:20 +01:00
|
|
|
<ArrowDownIcon size={36} />
|
2020-02-11 18:23:25 +01:00
|
|
|
</div>
|
2020-02-10 17:58:20 +01:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
{#if isOpen}
|
|
|
|
<ul class="options">
|
|
|
|
{#each Object.keys(stateBindings) as stateBinding}
|
|
|
|
<li
|
2020-02-12 11:12:08 +01:00
|
|
|
class:bold={stateBinding === bindingPath}
|
2020-02-10 17:58:20 +01:00
|
|
|
on:click={() => {
|
|
|
|
setBindingPath(stateBinding === bindingPath ? null : stateBinding);
|
|
|
|
}}>
|
|
|
|
{stateBinding}
|
|
|
|
</li>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
2020-02-12 11:12:08 +01:00
|
|
|
.bold {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
.highlighted {
|
|
|
|
color: rgba(0, 85, 255, 0.8);
|
|
|
|
}
|
|
|
|
|
2020-02-10 17:58:20 +01:00
|
|
|
button {
|
|
|
|
cursor: pointer;
|
|
|
|
outline: none;
|
|
|
|
border: none;
|
|
|
|
border-radius: 5px;
|
|
|
|
background: rgba(249, 249, 249, 1);
|
|
|
|
|
|
|
|
font-size: 1.6rem;
|
|
|
|
font-weight: 700;
|
|
|
|
color: rgba(22, 48, 87, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
.cascader {
|
|
|
|
position: relative;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.input-box {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.options {
|
|
|
|
width: 172px;
|
|
|
|
margin: 0;
|
|
|
|
position: absolute;
|
|
|
|
top: 35px;
|
|
|
|
padding: 10px;
|
|
|
|
z-index: 1;
|
|
|
|
background: rgba(249, 249, 249, 1);
|
|
|
|
min-height: 50px;
|
|
|
|
border-radius: 2px;
|
|
|
|
}
|
|
|
|
|
|
|
|
li {
|
2020-02-10 22:04:11 +01:00
|
|
|
list-style-type: none;
|
2020-02-10 17:58:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
li:hover {
|
|
|
|
cursor: pointer;
|
2020-02-10 22:04:11 +01:00
|
|
|
font-weight: bold;
|
2020-02-10 17:58:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
input {
|
|
|
|
margin-right: 5px;
|
|
|
|
border: 1px solid #dbdbdb;
|
|
|
|
border-radius: 2px;
|
|
|
|
opacity: 0.5;
|
|
|
|
height: 40px;
|
|
|
|
}
|
|
|
|
</style>
|