Adding a custom editor dialog
To add your custom editor, you should:
- Import the custom Form component for adding/editing tasks
- Use the
api.intercept
method to disable opening the default editor by blocking theshow-editor
action (return false) - Add the Form tag, define tasks and taskTypes, and add the action handler function that triggers the
update-task
ordelete-task
action.
<script>
import { getData } from "../data";
import { Gantt } from "wx-svelte-gantt";
import { Form } from "../custom/Form.svelte";
const data = getData();
const taskTypes = [
{ id: "task", label: "Task" },
{ id: "milestone", label: "Milestone" },
{ id: "summary", label: "Project" },
];
let task;
let api;
let store;
$: {
if (api) {
store = api.getState().tasks;
api.intercept("show-editor", data => {
task = store.byId(data.id);
return false;
});
}
}
function formAction(ev) {
const { action, data } = ev.detail;
switch (action) {
case "close-form":
task = null;
break;
default:
api.exec(action, data); //”update-task”, “delete-task” actions
break;
}
}
</script>
<Gantt
bind:api
tasks={data.tasks}
links={data.links}
scales={data.scales}
/>
{#if task}
<Form {task} {taskTypes} on:action={formAction} />
{/if}