2019-08-16 16:48:45 +02:00
|
|
|
<script>
|
|
|
|
|
|
|
|
import PropsView from "./PropsView.svelte";
|
|
|
|
import { store } from "../builderStore";
|
|
|
|
import { isRootComponent } from "./pagesParsing/searchComponents";
|
|
|
|
import IconButton from "../common/IconButton.svelte";
|
|
|
|
import Textbox from "../common/Textbox.svelte";
|
|
|
|
import UIkit from "uikit";
|
|
|
|
import { pipe } from "../common/core";
|
|
|
|
import {
|
2020-01-18 00:06:42 +01:00
|
|
|
getScreenInfo
|
2019-08-16 16:48:45 +02:00
|
|
|
} from "./pagesParsing/createProps";
|
|
|
|
import Button from "../common/Button.svelte";
|
|
|
|
import ButtonGroup from "../common/ButtonGroup.svelte";
|
|
|
|
|
|
|
|
import {
|
|
|
|
cloneDeep,
|
|
|
|
join,
|
|
|
|
split,
|
|
|
|
map,
|
|
|
|
keys,
|
|
|
|
isUndefined,
|
|
|
|
last
|
|
|
|
} from "lodash/fp";
|
|
|
|
import { assign } from "lodash";
|
|
|
|
|
|
|
|
let component;
|
|
|
|
let name = "";
|
|
|
|
let description = "";
|
|
|
|
let tagsString = "";
|
|
|
|
let nameInvalid = "";
|
|
|
|
let componentInfo;
|
|
|
|
let modalElement
|
|
|
|
let propsValidationErrors = [];
|
2019-10-03 07:12:13 +02:00
|
|
|
let originalName="";
|
2020-01-18 00:06:42 +01:00
|
|
|
let components;
|
2019-10-03 07:12:13 +02:00
|
|
|
let ignoreStore = false;
|
2019-08-19 09:51:01 +02:00
|
|
|
|
2019-08-16 16:48:45 +02:00
|
|
|
$: shortName = last(name.split("/"));
|
|
|
|
|
|
|
|
store.subscribe(s => {
|
2019-10-03 07:12:13 +02:00
|
|
|
if(ignoreStore) return;
|
2019-08-16 16:48:45 +02:00
|
|
|
component = s.currentFrontEndItem;
|
|
|
|
if(!component) return;
|
2019-10-03 07:12:13 +02:00
|
|
|
originalName = component.name;
|
2019-08-16 16:48:45 +02:00
|
|
|
name = component.name;
|
|
|
|
description = component.description;
|
|
|
|
tagsString = join(", ")(component.tags);
|
|
|
|
componentInfo = s.currentComponentInfo;
|
2020-01-18 00:06:42 +01:00
|
|
|
components = s.components;
|
2019-08-16 16:48:45 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const save = () => {
|
|
|
|
|
2019-10-03 07:12:13 +02:00
|
|
|
ignoreStore = true;
|
|
|
|
if(!validate()) {
|
|
|
|
ignoreStore = false;
|
|
|
|
return;
|
|
|
|
}
|
2019-08-16 16:48:45 +02:00
|
|
|
|
2019-10-07 07:03:41 +02:00
|
|
|
component.name = originalName || name;
|
2019-08-16 16:48:45 +02:00
|
|
|
component.description = description;
|
|
|
|
component.tags = pipe(tagsString, [
|
|
|
|
split(","),
|
|
|
|
map(s => s.trim())
|
|
|
|
]);
|
|
|
|
|
2020-01-18 00:06:42 +01:00
|
|
|
store.saveScreen(component);
|
2019-10-03 07:12:13 +02:00
|
|
|
|
|
|
|
ignoreStore = false;
|
|
|
|
// now do the rename
|
|
|
|
if(name !== originalName) {
|
2020-01-18 00:06:42 +01:00
|
|
|
store.renameScreen(originalName, name);
|
2019-10-03 07:12:13 +02:00
|
|
|
}
|
2019-08-16 16:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const deleteComponent = () => {
|
|
|
|
showDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
const confirmDeleteComponent = () => {
|
2020-01-18 00:06:42 +01:00
|
|
|
store.deleteScreen(component.name);
|
2019-08-16 16:48:45 +02:00
|
|
|
hideDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
const onPropsValidate = result => {
|
|
|
|
propsValidationErrors = result;
|
|
|
|
}
|
|
|
|
|
2019-08-19 09:51:01 +02:00
|
|
|
const updateComponent = doChange => {
|
|
|
|
const newComponent = cloneDeep(component);
|
|
|
|
doChange(newComponent);
|
|
|
|
component = newComponent;
|
2020-01-18 00:06:42 +01:00
|
|
|
componentInfo = getScreenInfo(components, newComponent);
|
2019-08-19 09:51:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const onPropsChanged = newProps => {
|
|
|
|
updateComponent(newComponent =>
|
|
|
|
assign(newComponent.props, newProps));
|
|
|
|
|
2019-08-16 16:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const validate = () => {
|
|
|
|
const fieldInvalid = (field, err) =>
|
|
|
|
errors[field] = err;
|
|
|
|
const fieldValid = field =>
|
|
|
|
errors[field] && delete errors[field];
|
|
|
|
|
|
|
|
if(!name) nameInvalid = "component name i not supplied";
|
|
|
|
else nameInvalid = "";
|
|
|
|
|
|
|
|
return (!nameInvalid && propsValidationErrors.length === 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
const hideDialog = () => {
|
|
|
|
UIkit.modal(modalElement).hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
const showDialog = () => {
|
|
|
|
UIkit.modal(modalElement).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="root">
|
|
|
|
|
|
|
|
<div class="title">
|
|
|
|
<div>{shortName}</div>
|
|
|
|
<div>
|
|
|
|
<IconButton icon="save"
|
|
|
|
on:click={save}
|
2019-09-25 21:53:52 +02:00
|
|
|
color="var(--secondary100)"
|
|
|
|
hoverColor="var(--primary100)"/>
|
2019-08-16 16:48:45 +02:00
|
|
|
<IconButton icon="trash"
|
|
|
|
on:click={deleteComponent}
|
2019-09-25 21:53:52 +02:00
|
|
|
color="var(--secondary100)"
|
|
|
|
hoverColor="var(--primary100)"/>
|
2019-08-16 16:48:45 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2019-10-03 07:12:13 +02:00
|
|
|
<div class="component-props-container">
|
2019-08-16 16:48:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
<PropsView onValidate={onPropsValidate}
|
|
|
|
{componentInfo}
|
2020-01-18 00:06:42 +01:00
|
|
|
{onPropsChanged} />
|
2019-08-16 16:48:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div bind:this={modalElement} uk-modal>
|
|
|
|
<div class="uk-modal-dialog">
|
|
|
|
|
|
|
|
<div class="uk-modal-header">
|
2019-10-03 07:12:13 +02:00
|
|
|
Delete {name} ?
|
2019-08-16 16:48:45 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="uk-modal-body">
|
|
|
|
Are you sure you want to delete this component ?
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="uk-modal-footer">
|
|
|
|
<ButtonGroup>
|
|
|
|
<Button grouped
|
|
|
|
on:click={confirmDeleteComponent}>
|
|
|
|
OK
|
|
|
|
</Button>
|
|
|
|
<Button grouped
|
|
|
|
on:click={hideDialog}
|
|
|
|
color="secondary" >
|
|
|
|
Cancel
|
|
|
|
</Button>
|
|
|
|
</ButtonGroup>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
|
.root {
|
|
|
|
height: 100%;
|
2019-09-25 21:53:52 +02:00
|
|
|
display: flex;
|
2019-09-20 10:02:22 +02:00
|
|
|
flex-direction: column;
|
2020-01-18 00:06:42 +01:00
|
|
|
border-style: solid;
|
|
|
|
border-width: 1px 0 0 0;
|
|
|
|
border-color: var(--slate);
|
2019-08-16 16:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.title {
|
2020-01-18 00:06:42 +01:00
|
|
|
padding: 1rem;
|
2019-08-16 16:48:45 +02:00
|
|
|
display: grid;
|
|
|
|
grid-template-columns: [name] 1fr [actions] auto;
|
2019-09-25 21:53:52 +02:00
|
|
|
color: var(--secondary100);
|
|
|
|
font-size: .9rem;
|
|
|
|
font-weight: bold;
|
2019-08-16 16:48:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.title > div:nth-child(1) {
|
|
|
|
grid-column-start: name;
|
|
|
|
color: var(--secondary100);
|
|
|
|
}
|
|
|
|
|
|
|
|
.title > div:nth-child(2) {
|
|
|
|
grid-column-start: actions;
|
|
|
|
}
|
|
|
|
|
2019-09-20 10:02:22 +02:00
|
|
|
.component-props-container {
|
|
|
|
flex: 1 1 auto;
|
|
|
|
overflow-y: auto;
|
|
|
|
}
|
2019-08-16 16:48:45 +02:00
|
|
|
</style>
|