{#if $copilotCurrentStepStore !== undefined}
{/if}
{#if !disableSettings}
{/if}
{#if !disableStaticInputs}
{/if}
{
let e = detail.detail
dependents = getDependentComponents(e.id, $flowStore)
const cb = () => {
push(history, $flowStore)
if (e.id === 'preprocessor') {
$selectedId = 'Input'
$flowStore.value.preprocessor_module = undefined
} else {
selectNextId(e.id)
removeAtId($flowStore.value.modules, e.id)
if ($flowInputsStore) {
delete $flowInputsStore[e.id]
}
}
$flowStore = $flowStore
updateFlowInputsStore()
}
if (Object.keys(dependents).length > 0) {
deleteCallback = cb
} else {
cb()
}
}}
on:insert={async ({ detail }) => {
if (shouldRunTutorial('forloop', detail.detail, 1)) {
flowTutorials?.runTutorialById('forloop', detail.index)
} else if (shouldRunTutorial('branchone', detail.detail, 2)) {
flowTutorials?.runTutorialById('branchone')
} else if (shouldRunTutorial('branchall', detail.detail, 3)) {
flowTutorials?.runTutorialById('branchall')
} else {
if (detail.modules && Array.isArray(detail.modules)) {
await tick()
if ($moving) {
push(history, $flowStore)
let indexToRemove = $moving.modules.findIndex((m) => $moving?.module?.id == m.id)
$moving.modules.splice(indexToRemove, 1)
detail.modules.splice(detail.index, 0, $moving.module)
$selectedId = $moving.module.id
$moving = undefined
} else {
if (detail.detail === 'preprocessor') {
insertNewPreprocessorModule(
flowStore,
flowStateStore,
detail.inlineScript,
detail.script
)
$selectedId = 'preprocessor'
} else {
const index = detail.index ?? 0
await insertNewModuleAtIndex(
detail.modules,
index,
detail.kind,
detail.script,
detail.flow,
detail.inlineScript
)
const id = detail.modules[detail.index ?? 0].id
$selectedId = id
if (detail.kind == 'trigger') {
await insertNewModuleAtIndex(
detail.modules,
index + 1,
'forloop',
undefined,
undefined,
undefined
)
setExpr(detail.modules[index + 1], `results.${id}`)
setScheduledPollSchedule(primarySchedule, triggersCount)
}
}
}
if (['branchone', 'branchall'].includes(detail.kind)) {
await addBranch(detail.modules[detail.index ?? 0])
}
$flowStateStore = $flowStateStore
$flowStore = $flowStore
dispatch('change')
}
}
}}
on:newBranch={async ({ detail }) => {
if (detail.module) {
await addBranch(detail.module)
$flowStore = $flowStore
}
}}
on:select={async ({ detail }) => {
flowPropPickerConfig.set(undefined)
}}
on:changeId={({ detail }) => {
let { id, newId, deps } = detail
dfs($flowStore.value.modules, (mod) => {
if (deps[mod.id]) {
deps[mod.id].forEach((dep) => {
if (
mod.value.type == 'rawscript' ||
mod.value.type == 'script' ||
mod.value.type == 'flow'
) {
mod.value.input_transforms = Object.fromEntries(
Object.entries(mod.value.input_transforms).map(([k, v]) => {
if (v.type == 'javascript') {
return [k, { ...v, expr: replaceId(v.expr, id, newId) }]
} else {
return [k, v]
}
})
)
} else if (mod?.value?.type === 'forloopflow') {
if (mod.value.iterator.type === 'javascript') {
mod.value.iterator.expr = replaceId(mod.value.iterator.expr, id, newId)
}
} else if (mod?.value?.type === 'branchone') {
mod.value.branches.forEach((branch) => {
branch.expr = replaceId(branch.expr, id, newId)
})
}
})
}
if (mod.id == id) {
mod.id = newId
}
})
$flowStore = $flowStore
$selectedId = newId
}}
on:deleteBranch={async ({ detail }) => {
if (detail.module) {
await removeBranch(detail.module, detail.index)
$flowStore = $flowStore
$selectedId = detail.module.id
}
}}
on:move={async ({ detail }) => {
if (!$moving || $moving.module.id !== detail.module.id) {
if (detail.module && detail.modules) {
$moving = { module: detail.module, modules: detail.modules }
}
} else {
$moving = undefined
}
}}
/>
{#if !disableTutorials}