eval preserves labeled objects

This commit is contained in:
Clement Zhang
2024-11-07 12:19:50 +01:00
parent 756b07b16c
commit 59a9458ca8
2 changed files with 14 additions and 14 deletions
@@ -11,7 +11,7 @@
import RefreshDatabaseStudioTable from './RefreshDatabaseStudioTable.svelte'
import { isObjectOptionArray, isStringArray } from '$lib/components/multiselect/types'
export let componentInput: StaticInput<any[]> & { loading?: boolean }
export let componentInput: StaticInput<any[]> & { loading?: boolean; expr?: string }
export let subFieldType: InputType | undefined = undefined
export let selectOptions: StaticOptions['selectOptions'] | undefined = undefined
export let id: string | undefined
@@ -20,6 +20,15 @@
const dispatch = createEventDispatcher()
const flipDurationMs = 200
let items = getItems(componentInput)
let raw: boolean = false
let labeled: boolean = subFieldType === 'labeledselect'
$: subFieldType === 'db-explorer' && clearTableOnComponentReset(componentInput?.value)
$: labeled !== undefined && handleLabeledChange()
$: items !== undefined && handleItemsChange()
function addElementByType() {
if (!Array.isArray(componentInput.value)) {
componentInput.value = []
@@ -196,8 +205,6 @@
componentInput.value = reorderedValues
}
let items = getItems(componentInput)
function getItems(componentInput: StaticInput<any[]> & { loading?: boolean }) {
return (Array.isArray(componentInput.value) ? componentInput.value : [])
.filter((x) => x != undefined)
@@ -212,14 +219,10 @@
}
}
$: subFieldType === 'db-explorer' && clearTableOnComponentReset(componentInput?.value)
let raw: boolean = false
let labeled: boolean = subFieldType === 'labeledselect'
function handleItemsChange() {
const newComponentInput = { ...componentInput }
newComponentInput.value = items.map((item) => item.value).filter((item) => item != undefined)
newComponentInput.expr = JSON.stringify(newComponentInput.value)
const newSubFieldType = labeled ? 'labeledselect' : 'simplestringselect'
@@ -241,9 +244,6 @@
}
}
$: labeled !== undefined && handleLabeledChange()
$: items !== undefined && handleItemsChange()
// let mounted = false
// $: if (componentInput.value && mounted) {
@@ -30,6 +30,9 @@
editor?.setCode(code)
}
let fullscreen = false
let focus = false
$: extraLib =
componentInput?.expr && $worldStore
? buildExtraLib($worldStore?.outputsById ?? {}, acceptSelf ? '' : id, $state, false)
@@ -52,9 +55,6 @@
inferDeps(code, $worldStore.outputsById, componentInput, app)
}
}
let fullscreen = false
let focus = false
</script>
{#if componentInput?.type === 'evalv2'}