diff --git a/frontend/src/lib/components/apps/components/dateInputs/AppDateInput.svelte b/frontend/src/lib/components/apps/components/dateInputs/AppDateInput.svelte index dbfba0c3d8..fb7afee03a 100644 --- a/frontend/src/lib/components/apps/components/dateInputs/AppDateInput.svelte +++ b/frontend/src/lib/components/apps/components/dateInputs/AppDateInput.svelte @@ -4,6 +4,7 @@ import type { Output } from '../../rx' import type { AppEditorContext } from '../../types' import AlignWrapper from '../helpers/AlignWrapper.svelte' + import InputDefaultValue from '../helpers/InputDefaultValue.svelte' import InputValue from '../helpers/InputValue.svelte' export let id: string @@ -17,6 +18,7 @@ let labelValue: string = 'Title' let minValue: string = '' let maxValue: string = '' + let defaultValue: string | undefined = undefined $: outputs = $worldStore?.outputsById[id] as { result: Output @@ -25,11 +27,16 @@ function handleInput() { outputs?.result.set(input.value) } + + $: input && handleInput() + + + + type InputType = string | number | boolean + export let input: HTMLInputElement | undefined = undefined + export let defaultValue: InputType | undefined = undefined + + function setInputValueToDefaultValue() { + if (defaultValue !== undefined && input) { + input.value = String(defaultValue) + } + } + + function clearInputValue() { + if (input) { + input.value = '' + } + } + + $: input && defaultValue && setInputValueToDefaultValue() + $: input && + (defaultValue === '' || defaultValue === undefined || defaultValue === null) && + clearInputValue() + diff --git a/frontend/src/lib/components/apps/components/numberInputs/AppNumberInput.svelte b/frontend/src/lib/components/apps/components/numberInputs/AppNumberInput.svelte index bf99c94ad5..7f5597b9cc 100644 --- a/frontend/src/lib/components/apps/components/numberInputs/AppNumberInput.svelte +++ b/frontend/src/lib/components/apps/components/numberInputs/AppNumberInput.svelte @@ -4,6 +4,7 @@ import type { Output } from '../../rx' import type { AppEditorContext } from '../../types' import AlignWrapper from '../helpers/AlignWrapper.svelte' + import InputDefaultValue from '../helpers/InputDefaultValue.svelte' import InputValue from '../helpers/InputValue.svelte' export let id: string @@ -12,31 +13,39 @@ export const staticOutputs: string[] = ['result'] const { worldStore } = getContext('AppEditorContext') - let value: number - let labelValue: string = 'Title' + let input: HTMLInputElement + + let defaultValue: number | undefined = undefined + let placeholder: string | undefined = undefined $: outputs = $worldStore?.outputsById[id] as { result: Output } - $: if (value || !value) { - // Disallow 'e' character in numbers - // if(value && value.toString().includes('e')) { - // value = +value.toString().replaceAll('e', '') - // } + + function handleInput() { + const value = input?.value const num = isNaN(+value) ? null : +value outputs?.result.set(num) } + + $: input && handleInput() - + + + { + e?.stopPropagation() + window.dispatchEvent(new Event('pointerup')) + }} type="number" inputmode="numeric" pattern="\d*" - placeholder="Type..." - class="h-full" + {placeholder} /> diff --git a/frontend/src/lib/components/apps/components/textInputs/AppTextInput.svelte b/frontend/src/lib/components/apps/components/textInputs/AppTextInput.svelte index e94b170d6a..6b22e2a045 100644 --- a/frontend/src/lib/components/apps/components/textInputs/AppTextInput.svelte +++ b/frontend/src/lib/components/apps/components/textInputs/AppTextInput.svelte @@ -4,6 +4,7 @@ import type { Output } from '../../rx' import type { AppEditorContext } from '../../types' import AlignWrapper from '../helpers/AlignWrapper.svelte' + import InputDefaultValue from '../helpers/InputDefaultValue.svelte' import InputValue from '../helpers/InputValue.svelte' export let id: string @@ -16,6 +17,7 @@ let input: HTMLInputElement let placeholder: string | undefined = undefined + let defaultValue: string | undefined = undefined $: outputs = $worldStore?.outputsById[id] as { result: Output @@ -24,9 +26,13 @@ function handleInput() { outputs?.result.set(input.value) } + + $: input && handleInput() + + {:else if componentInput.fieldType === 'textarea'}