Merge pull request #15545 from Budibase/execute-script-tweaks

Pull out new code editor field and drawer bindable slot into single component
This commit is contained in:
Andrew Kingston 2025-02-13 13:15:09 +00:00 committed by GitHub
commit ca0630c620
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 80 additions and 53 deletions

View File

@ -62,8 +62,7 @@
} from "@budibase/types" } from "@budibase/types"
import PropField from "./PropField.svelte" import PropField from "./PropField.svelte"
import { utils } from "@budibase/shared-core" import { utils } from "@budibase/shared-core"
import { encodeJSBinding } from "@budibase/string-templates" import DrawerBindableCodeEditorField from "@/components/common/bindings/DrawerBindableCodeEditorField.svelte"
import CodeEditorField from "@/components/common/bindings/CodeEditorField.svelte"
export let automation export let automation
export let block export let block
@ -908,32 +907,14 @@
/> />
{:else if value.customType === "code" && stepId === ActionStepID.EXECUTE_SCRIPT_V2} {:else if value.customType === "code" && stepId === ActionStepID.EXECUTE_SCRIPT_V2}
<div class="scriptv2-wrapper"> <div class="scriptv2-wrapper">
<DrawerBindableSlot <DrawerBindableCodeEditorField
title={"Edit Code"}
panel={AutomationBindingPanel}
type={"longform"}
{schema}
on:change={e => onChange({ [key]: e.detail })}
value={inputData[key]}
{bindings} {bindings}
allowJS={true} {schema}
allowHBS={false} panel={AutomationBindingPanel}
updateOnChange={false} on:change={e => onChange({ [key]: e.detail })}
context={$memoContext} context={$memoContext}
> value={inputData[key]}
<div class="field-wrap code-editor"> />
<CodeEditorField
value={inputData[key]}
{bindings}
context={$memoContext}
allowHBS={false}
allowJS
placeholder={"Add bindings by typing $"}
on:blur={e =>
onChange({ [key]: encodeJSBinding(e.detail) })}
/>
</div>
</DrawerBindableSlot>
</div> </div>
{:else if value.customType === "code" && stepId === ActionStepID.EXECUTE_SCRIPT} {:else if value.customType === "code" && stepId === ActionStepID.EXECUTE_SCRIPT}
<!-- DEPRECATED --> <!-- DEPRECATED -->
@ -1086,23 +1067,4 @@
flex: 3; flex: 3;
margin-top: calc((var(--spacing-xl) * -1) + 1px); margin-top: calc((var(--spacing-xl) * -1) + 1px);
} }
.field-wrap :global(.cm-editor),
.field-wrap :global(.cm-scroller) {
border-radius: 4px;
}
.field-wrap {
box-sizing: border-box;
border: 1px solid var(--spectrum-global-color-gray-400);
border-radius: 4px;
}
.field-wrap.code-editor {
height: 180px;
}
.scriptv2-wrapper :global(.icon.slot-icon) {
top: 1px;
border-bottom-left-radius: var(--spectrum-alias-border-radius-regular);
border-right: 0px;
border-bottom: 1px solid var(--spectrum-alias-border-color);
}
</style> </style>

View File

@ -61,6 +61,8 @@
let mode: BindingMode | null let mode: BindingMode | null
let sidePanel: SidePanel | null let sidePanel: SidePanel | null
let initialValueJS = value?.startsWith?.("{{ js ") let initialValueJS = value?.startsWith?.("{{ js ")
let jsValue = initialValueJS ? value : null
let hbsValue = initialValueJS ? null : value
let getCaretPosition: CaretPositionFn | undefined let getCaretPosition: CaretPositionFn | undefined
let insertAtPos: InsertAtPositionFn | undefined let insertAtPos: InsertAtPositionFn | undefined
let targetMode: BindingMode | null = null let targetMode: BindingMode | null = null
@ -69,10 +71,6 @@
let expressionError: string | undefined let expressionError: string | undefined
let evaluating = false let evaluating = false
// Ensure these values are not stale
$: jsValue = initialValueJS ? value : null
$: hbsValue = initialValueJS ? null : value
$: useSnippets = allowSnippets && !$licensing.isFreePlan $: useSnippets = allowSnippets && !$licensing.isFreePlan
$: editorModeOptions = getModeOptions(allowHBS, allowJS) $: editorModeOptions = getModeOptions(allowHBS, allowJS)
$: sidePanelOptions = getSidePanelOptions( $: sidePanelOptions = getSidePanelOptions(

View File

@ -36,6 +36,7 @@
export let context = null export let context = null
export let autofocusEditor = false export let autofocusEditor = false
export let placeholder = null export let placeholder = null
export let height = 180
let getCaretPosition: CaretPositionFn | undefined let getCaretPosition: CaretPositionFn | undefined
let insertAtPos: InsertAtPositionFn | undefined let insertAtPos: InsertAtPositionFn | undefined
@ -131,7 +132,7 @@
} }
</script> </script>
<div class="code-panel"> <div class="code-panel" style="height:{height}px;">
<div class="editor"> <div class="editor">
{#key jsCompletions} {#key jsCompletions}
<CodeEditor <CodeEditor
@ -154,7 +155,6 @@
<style> <style>
.code-panel { .code-panel {
height: 100%;
display: flex; display: flex;
} }

View File

@ -0,0 +1,68 @@
<script>
import { createEventDispatcher } from "svelte"
import {
ClientBindingPanel,
DrawerBindableSlot,
} from "@/components/common/bindings"
import CodeEditorField from "@/components/common/bindings/CodeEditorField.svelte"
export let value = ""
export let panel = ClientBindingPanel
export let schema = null
export let bindings = []
export let context = {}
export let height = 180
const dispatch = createEventDispatcher()
</script>
<div class="wrapper">
<DrawerBindableSlot
{panel}
{schema}
{value}
{bindings}
{context}
title="Edit Code"
type="longform"
allowJS={true}
allowHBS={false}
updateOnChange={false}
on:change={e => {
value = e.detail
dispatch("change", value)
}}
>
<div class="code-editor-wrapper">
<CodeEditorField
{value}
{bindings}
{context}
{height}
allowHBS={false}
allowJS
placeholder={"Add bindings by typing $"}
on:change={e => (value = e.detail)}
on:blur={() => dispatch("change", value)}
/>
</div>
</DrawerBindableSlot>
</div>
<style>
.wrapper :global(.icon.slot-icon) {
top: 1px;
border-radius: 0 4px 0 4px;
border-right: 0;
border-bottom: 1px solid var(--spectrum-alias-border-color);
}
.wrapper :global(.cm-editor),
.wrapper :global(.cm-scroller) {
border-radius: 4px;
}
.code-editor-wrapper {
box-sizing: border-box;
border: 1px solid var(--spectrum-global-color-gray-400);
border-radius: 4px;
}
</style>

View File

@ -22,7 +22,6 @@
export let updateOnChange = true export let updateOnChange = true
export let type export let type
export let schema export let schema
export let allowHBS = true export let allowHBS = true
export let context = {} export let context = {}
@ -174,7 +173,7 @@
{:else} {:else}
<slot /> <slot />
{/if} {/if}
{#if !disabled && type !== "formula" && !disabled && !attachmentTypes.includes(type)} {#if !disabled && type !== "formula" && !attachmentTypes.includes(type)}
<div <div
class={`icon ${getIconClass(value, type)}`} class={`icon ${getIconClass(value, type)}`}
on:click={() => { on:click={() => {