From db8f716316162b266ec416bb6c7ed5c5d03b0e2e Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 22 Mar 2021 14:54:54 +0900 Subject: [PATCH] Fix preloading text inputs --- src/components/FormMode/text-input-mixin.js | 10 +++ stories/Formmode.stories.js | 84 +++++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/src/components/FormMode/text-input-mixin.js b/src/components/FormMode/text-input-mixin.js index b5490cf..7285814 100644 --- a/src/components/FormMode/text-input-mixin.js +++ b/src/components/FormMode/text-input-mixin.js @@ -42,6 +42,16 @@ export default { return inputValue === this.upil.symbols.UNRESOLVED ? '' : inputValue }, }, + watch: { + stateInputValue: { + immediate: true, + handler(stateInputValue) { + if (!this.inputValue) { + this.inputValue = stateInputValue + } + }, + }, + }, methods: { compositionEnded() { this.waitingOnIme = false diff --git a/stories/Formmode.stories.js b/stories/Formmode.stories.js index e04d48b..6b982ef 100644 --- a/stories/Formmode.stories.js +++ b/stories/Formmode.stories.js @@ -1,10 +1,12 @@ import FormMode from '@/components/FormMode' import { UPILCore } from '@appsocially/userpil-core' +import { setupListeners } from '@/utils' export default { title: 'Modes/Formmode', args: { templateText: '', + listeners: {}, }, argTypes: { templateText: { @@ -12,6 +14,9 @@ export default { type: 'text', }, }, + listeners: { + type: 'object', + }, }, } @@ -30,6 +35,7 @@ const formmodeTemplate = (args) => { methods: { startUpil() { this.upil = new UPILCore() + setupListeners({ upil: this.upil, listeners: this.listeners }) this.upil.startRaw(this.templateText, { mode: 'form', @@ -65,6 +71,30 @@ BasicTemplate.args = { `, } +export const PreloadedTemplate = formmodeTemplate.bind({}) +PreloadedTemplate.args = { + templateText: ` + DIALOG getName + TEMPLATE + { + formText: "First Name" + } + "What's your name?" + >>name + /TEMPLATE + TEMPLATE "Welcome \${name}" + /DIALOG + RUN getName + `, + listeners: { + 'preload-input': async () => { + return { + name: 'John Doe', + } + }, + }, +} + export const BasicSelect = formmodeTemplate.bind({}) BasicSelect.args = { templateText: ` @@ -85,6 +115,33 @@ BasicSelect.args = { `, } +export const PreloadedSelect = formmodeTemplate.bind({}) +PreloadedSelect.args = { + templateText: ` + DIALOG favColor + SELECT + { + formText: "Favorite color" + } + "Please choose your favorite color" + -("Red", "red") + -("Blue", "blue") + -("Green", "green") + >>color + /SELECT + TEMPLATE "\${color} is a great color!" + /DIALOG + RUN favColor + `, + listeners: { + 'preload-input': async () => { + return { + color: 'green', + } + }, + }, +} + export const BasicMultiSelect = formmodeTemplate.bind({}) BasicMultiSelect.args = { templateText: ` @@ -105,6 +162,33 @@ BasicMultiSelect.args = { `, } +export const PreloadedMultiSelect = formmodeTemplate.bind({}) +PreloadedMultiSelect.args = { + templateText: ` + DIALOG favColor + MULTI_SELECT + { + formText: "Favorite colors" + } + "Please choose all of your favorite colors" + -("Color red", "red") + -("Color blue", "blue") + -("Color green", "green") + >>colors + /MULTI_SELECT + TEMPLATE "Those are all great colors!" + /DIALOG + RUN favColor + `, + listeners: { + 'preload-input': async () => { + return { + colors: ['green', 'blue'], + } + }, + }, +} + export const VariableInFormText = formmodeTemplate.bind({}) VariableInFormText.args = { templateText: `