mirror of https://github.com/Budibase/budibase.git
31 changed files with 180 additions and 148 deletions
@ -1,19 +1,19 @@ |
|||
<script> |
|||
import { getContext, setContext } from "svelte" |
|||
import { createDataContextStore } from "../store" |
|||
import { createDataStore } from "../store" |
|||
|
|||
export let row |
|||
|
|||
// Get current contexts |
|||
const dataContext = getContext("data") |
|||
const styles = getContext("style") |
|||
const data = getContext("data") |
|||
const component = getContext("component") |
|||
|
|||
// Clone current context to this context |
|||
const newDataContext = createDataContextStore($dataContext) |
|||
setContext("data", newDataContext) |
|||
const newData = createDataStore($data) |
|||
setContext("data", newData) |
|||
|
|||
// Add additional layer to context |
|||
$: newDataContext.actions.addContext(row, $styles.id) |
|||
$: newData.actions.addContext(row, $component.id) |
|||
</script> |
|||
|
|||
<slot /> |
|||
|
|||
@ -0,0 +1,21 @@ |
|||
import { writable } from "svelte/store" |
|||
|
|||
const createBindingStore = () => { |
|||
const store = writable({}) |
|||
|
|||
const setBindableValue = (value, componentId) => { |
|||
store.update(state => { |
|||
if (componentId) { |
|||
state[componentId] = value |
|||
} |
|||
return state |
|||
}) |
|||
} |
|||
|
|||
return { |
|||
subscribe: store.subscribe, |
|||
actions: { setBindableValue }, |
|||
} |
|||
} |
|||
|
|||
export const bindingStore = createBindingStore() |
|||
@ -0,0 +1,27 @@ |
|||
import { writable } from "svelte/store" |
|||
import { cloneDeep } from "lodash/fp" |
|||
|
|||
const initialValue = { |
|||
data: null, |
|||
} |
|||
|
|||
export const createDataStore = existingContext => { |
|||
const initial = existingContext ? cloneDeep(existingContext) : initialValue |
|||
const store = writable(initial) |
|||
|
|||
// Adds a context layer to the data context tree
|
|||
const addContext = (row, componentId) => { |
|||
store.update(state => { |
|||
if (componentId) { |
|||
state[componentId] = row |
|||
state.data = row |
|||
} |
|||
return state |
|||
}) |
|||
} |
|||
|
|||
return { |
|||
subscribe: store.subscribe, |
|||
actions: { addContext }, |
|||
} |
|||
} |
|||
@ -1,39 +0,0 @@ |
|||
import { writable, get } from "svelte/store" |
|||
import { enrichDataBinding } from "../utils" |
|||
import { cloneDeep } from "lodash/fp" |
|||
|
|||
const initialValue = { |
|||
data: null, |
|||
} |
|||
|
|||
export const createDataContextStore = existingContext => { |
|||
const initial = existingContext ? cloneDeep(existingContext) : initialValue |
|||
const store = writable(initial) |
|||
|
|||
// Adds a context layer to the data context tree
|
|||
const addContext = (row, componentId) => { |
|||
store.update(state => { |
|||
if (row && componentId) { |
|||
state[componentId] = row |
|||
state.data = row |
|||
} |
|||
return state |
|||
}) |
|||
} |
|||
|
|||
// Enriches props by running mustache and filling in any data bindings present
|
|||
// in the prop values
|
|||
const enrichDataBindings = props => { |
|||
const state = get(store) |
|||
let enrichedProps = {} |
|||
Object.entries(props).forEach(([key, value]) => { |
|||
enrichedProps[key] = enrichDataBinding(value, state) |
|||
}) |
|||
return enrichedProps |
|||
} |
|||
|
|||
return { |
|||
subscribe: store.subscribe, |
|||
actions: { addContext, enrichDataBindings }, |
|||
} |
|||
} |
|||
@ -1,5 +1,8 @@ |
|||
export { authStore } from "./auth" |
|||
export { routeStore } from "./routes" |
|||
export { screenStore } from "./screens" |
|||
export { createDataContextStore } from "./dataContext" |
|||
export { builderStore } from "./builder" |
|||
export { bindingStore } from "./binding" |
|||
|
|||
// Data stores are layered and duplicated, so it is not a singleton
|
|||
export { createDataStore } from "./data" |
|||
|
|||
@ -1,21 +1,12 @@ |
|||
<script> |
|||
import { getContext } from "svelte" |
|||
|
|||
const { styleable } = getContext("sdk") |
|||
const styles = getContext("style") |
|||
const { styleable, setBindableValue } = getContext("sdk") |
|||
const component = getContext("component") |
|||
|
|||
export let value = "" |
|||
export let className = "" |
|||
export let type = "text" |
|||
|
|||
const onchange = ev => { |
|||
value = ev.target.value |
|||
} |
|||
// Keep bindable value up to date |
|||
let value |
|||
$: setBindableValue(value, $component.id) |
|||
</script> |
|||
|
|||
<input |
|||
class={className} |
|||
{type} |
|||
{value} |
|||
on:change={onchange} |
|||
use:styleable={$styles} /> |
|||
<input bind:value on:change={onchange} use:styleable={$component.styles} /> |
|||
|
|||
Loading…
Reference in new issue