auto update state origins when attaching click handlers
This commit is contained in:
parent
7a39e16e32
commit
c976a133c0
|
@ -462,22 +462,18 @@ const saveScreen = store => screen => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const _saveScreen = (store, s, screen) => {
|
const _saveScreen = (store, s, screen) => {
|
||||||
const screens = pipe(s.pages[s.currentPageName]._screens, [
|
s.currentFrontEndItem = screen
|
||||||
filter(c => c.name !== screen.name),
|
s.currentComponentInfo = getScreenInfo(s.components, screen)
|
||||||
concat([screen]),
|
|
||||||
])
|
|
||||||
// console.log('saveScreen', screens, screen)
|
|
||||||
s.pages[s.currentPageName]._screens = screens
|
|
||||||
s.screens = s.pages[s.currentPageName]._screens
|
|
||||||
// s.currentPreviewItem = screen
|
|
||||||
// s.currentComponentInfo = screen.props
|
|
||||||
|
|
||||||
api
|
api
|
||||||
.post(
|
.post(`/_builder/api/${s.appname}/screen`, screen)
|
||||||
`/_builder/api/${s.appname}/pages/${s.currentPageName}/screen`,
|
.then(async savedScreen => {
|
||||||
screen
|
const updatedScreen = await savedScreen.json();
|
||||||
)
|
const screens = [...s.screens.filter(storeScreen => storeScreen.name !== updatedScreen.name), updatedScreen];
|
||||||
.then(() => _savePage(s))
|
s.pages[s.currentPageName]._screens = screens
|
||||||
|
s.screens = screens
|
||||||
|
_savePage(s);
|
||||||
|
});
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -580,7 +576,7 @@ const renameScreen = store => (oldname, newname) => {
|
||||||
const saveAllChanged = async () => {
|
const saveAllChanged = async () => {
|
||||||
for (let screenName of changedScreens) {
|
for (let screenName of changedScreens) {
|
||||||
const changedScreen = getExactComponent(screens, screenName)
|
const changedScreen = getExactComponent(screens, screenName)
|
||||||
await api.post(`/_builder/api/${s.appname}/screen`, changedScreen)
|
const updatedScreen = await api.post(`/_builder/api/${s.appname}/screen`, changedScreen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,28 @@
|
||||||
<script>
|
<script>
|
||||||
import IconButton from "../../common/IconButton.svelte"
|
import IconButton from "../../common/IconButton.svelte";
|
||||||
import PlusButton from "../../common/PlusButton.svelte"
|
import PlusButton from "../../common/PlusButton.svelte";
|
||||||
import Select from "../../common/Select.svelte"
|
import Select from "../../common/Select.svelte";
|
||||||
import StateBindingControl from "../StateBindingControl.svelte"
|
import Input from "../../common/Input.svelte";
|
||||||
import { find, map, keys, reduce, keyBy } from "lodash/fp"
|
import StateBindingControl from "../StateBindingControl.svelte";
|
||||||
import { pipe, userWithFullAccess } from "../../common/core"
|
import { find, map, keys, reduce, keyBy } from "lodash/fp";
|
||||||
|
import { pipe, userWithFullAccess } from "../../common/core";
|
||||||
import {
|
import {
|
||||||
EVENT_TYPE_MEMBER_NAME,
|
EVENT_TYPE_MEMBER_NAME,
|
||||||
allHandlers,
|
allHandlers,
|
||||||
} from "../../common/eventHandlers"
|
} from "../../common/eventHandlers";
|
||||||
import { store } from "../../builderStore"
|
import { store } from "../../builderStore";
|
||||||
|
|
||||||
export let handler
|
export let handler;
|
||||||
export let onCreate
|
export let onCreate;
|
||||||
export let onChanged
|
export let onChanged;
|
||||||
export let onRemoved
|
export let onRemoved;
|
||||||
|
|
||||||
export let index
|
export let index;
|
||||||
export let newHandler
|
export let newHandler;
|
||||||
|
|
||||||
let eventOptions
|
let eventOptions;
|
||||||
let handlerType
|
let handlerType;
|
||||||
let parameters = []
|
let parameters = [];
|
||||||
|
|
||||||
$: eventOptions = allHandlers(
|
$: eventOptions = allHandlers(
|
||||||
{ hierarchy: $store.hierarchy },
|
{ hierarchy: $store.hierarchy },
|
||||||
|
@ -29,53 +30,53 @@
|
||||||
hierarchy: $store.hierarchy,
|
hierarchy: $store.hierarchy,
|
||||||
actions: keyBy("name")($store.actions),
|
actions: keyBy("name")($store.actions),
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (handler) {
|
if (handler) {
|
||||||
handlerType = handler[EVENT_TYPE_MEMBER_NAME]
|
handlerType = handler[EVENT_TYPE_MEMBER_NAME];
|
||||||
parameters = Object.entries(handler.parameters).map(([name, value]) => ({
|
parameters = Object.entries(handler.parameters).map(([name, value]) => ({
|
||||||
name,
|
name,
|
||||||
value,
|
value,
|
||||||
}))
|
}));
|
||||||
} else {
|
} else {
|
||||||
// Empty Handler
|
// Empty Handler
|
||||||
handlerType = ""
|
handlerType = "";
|
||||||
parameters = []
|
parameters = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlerChanged = (type, params) => {
|
const handlerChanged = (type, params) => {
|
||||||
const handlerParams = {}
|
const handlerParams = {};
|
||||||
for (let param of params) {
|
for (let param of params) {
|
||||||
handlerParams[param.name] = param.value
|
handlerParams[param.name] = param.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedHandler = {
|
const updatedHandler = {
|
||||||
[EVENT_TYPE_MEMBER_NAME]: type,
|
[EVENT_TYPE_MEMBER_NAME]: type,
|
||||||
parameters: handlerParams,
|
parameters: handlerParams,
|
||||||
}
|
};
|
||||||
|
|
||||||
onChanged(updatedHandler, index)
|
onChanged(updatedHandler, index);
|
||||||
}
|
};
|
||||||
|
|
||||||
const handlerTypeChanged = e => {
|
const handlerTypeChanged = e => {
|
||||||
const handlerType = eventOptions.find(
|
const handlerType = eventOptions.find(
|
||||||
handler => handler.name === e.target.value
|
handler => handler.name === e.target.value
|
||||||
)
|
);
|
||||||
const defaultParams = handlerType.parameters.map(param => ({
|
const defaultParams = handlerType.parameters.map(param => ({
|
||||||
name: param,
|
name: param,
|
||||||
value: "",
|
value: "",
|
||||||
}))
|
}));
|
||||||
|
|
||||||
handlerChanged(handlerType.name, defaultParams)
|
handlerChanged(handlerType.name, defaultParams);
|
||||||
}
|
};
|
||||||
|
|
||||||
const onParameterChanged = index => e => {
|
const onParameterChanged = index => e => {
|
||||||
const newParams = [...parameters]
|
const newParams = [...parameters];
|
||||||
newParams[index].value = e.target.value
|
newParams[index].value = e.target.value;
|
||||||
handlerChanged(handlerType, newParams)
|
handlerChanged(handlerType, newParams);
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="type-selector-container {newHandler && 'new-handler'}">
|
<div class="type-selector-container {newHandler && 'new-handler'}">
|
||||||
|
@ -93,10 +94,7 @@
|
||||||
{#each parameters as param, idx}
|
{#each parameters as param, idx}
|
||||||
<div class="handler-option">
|
<div class="handler-option">
|
||||||
<span>{param.name}</span>
|
<span>{param.name}</span>
|
||||||
<input
|
<Input on:change={onParameterChanged(idx)} value={param.value} />
|
||||||
on:change={onParameterChanged(idx)}
|
|
||||||
value={param.value}
|
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
<span
|
<span
|
||||||
class="icon"
|
class="icon"
|
||||||
style={`
|
style={`
|
||||||
transform: rotate(${isOpen ? 0 : 90}deg);
|
transform: rotate(${isOpen ? 180 : -90}deg);
|
||||||
color: ${bindingPath ? 'rgba(0, 85, 255, 0.8)' : 'inherit'}
|
color: ${bindingPath ? 'rgba(0, 85, 255, 0.8)' : 'inherit'}
|
||||||
`}>
|
`}>
|
||||||
<ArrowDownIcon size={36} />
|
<ArrowDownIcon size={36} />
|
||||||
|
@ -119,7 +119,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
li {
|
li {
|
||||||
transition: 0.2s all;
|
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,8 @@ module.exports.saveScreen = async (config, appname, pagename, screen) => {
|
||||||
flag: "w",
|
flag: "w",
|
||||||
spaces: 2,
|
spaces: 2,
|
||||||
})
|
})
|
||||||
|
component.stateOrigins = buildStateOrigins(component);
|
||||||
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.renameScreen = async (
|
module.exports.renameScreen = async (
|
||||||
|
@ -167,6 +169,8 @@ const buildStateOrigins = screenDefinition => {
|
||||||
return origins;
|
return origins;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.buildStateOrigins = buildStateOrigins;
|
||||||
|
|
||||||
const fetchscreens = async (appPath, relativePath = "") => {
|
const fetchscreens = async (appPath, relativePath = "") => {
|
||||||
const currentDir = join(appPath, "components", relativePath)
|
const currentDir = join(appPath, "components", relativePath)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue