Skip to content

Commit e6ccf4e

Browse files
committed
manage input value changes
1 parent 126d724 commit e6ccf4e

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

components/Input/index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class Input extends Rect {
123123

124124
switch (key) {
125125
case 'return':
126-
if (this.state.search && this.onNavigate) {
127-
this.onNavigate(this.state.search);
126+
if (this.state.input[component.id] && this.onNavigate) {
127+
this.onNavigate(this.state.input[component.id]);
128128

129129
return;
130130
}
@@ -140,21 +140,21 @@ class Input extends Rect {
140140
break;
141141

142142
case 'space':
143-
this.state.search += ' ';
143+
this.state.input[component.id] += ' ';
144144

145145
break;
146146

147147
case 'tab':
148-
this.state.search += ' ';
148+
this.state.input[component.id] += ' ';
149149

150150
break;
151151

152152
case 'backspace':
153153
if (event.ctrl) {
154-
this.state.search = '';
154+
this.state.input[component.id] = '';
155155
} else {
156-
this.state.search = (
157-
this.state.search.substring(0, this.state.search.length - 1)
156+
this.state.input[component.id] = (
157+
this.state.input[component.id].substring(0, this.state.input[component.id].length - 1)
158158
);
159159
}
160160

@@ -178,7 +178,7 @@ class Input extends Rect {
178178
}
179179

180180
if (PRINTABLE_KEYS.includes(key.toLowerCase())) {
181-
this.state.search += key;
181+
this.state.input[component.id] += key;
182182
}
183183
}
184184

@@ -190,7 +190,7 @@ class Input extends Rect {
190190
textComponent: {
191191
...component.textComponent,
192192

193-
text: this.state.search,
193+
text: this.state.input[component.id],
194194
style: 'white',
195195

196196
attributes: {

renderers/Vasari/index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
* states
1111
*******************************************/
1212

13+
import { exec } from 'child_process';
1314
import { randomUUID } from 'crypto';
15+
1416
import sdl from '@kmamal/sdl';
1517
import HTMLParser from 'node-html-parser';
1618
import Canvas from 'canvas';
@@ -67,7 +69,7 @@ class Vasari extends App {
6769
elements: {},
6870
components: {},
6971
baseUrl: DEFAULT_PATH,
70-
search: ''
72+
input: {}
7173
};
7274

7375
this.window = window;
@@ -687,7 +689,7 @@ class Vasari extends App {
687689
break;
688690

689691
case 'INPUT':
690-
if (!component || component.value !== this.state.search) {
692+
if (!component || component.value !== this.state.input[component.id]) {
691693
const placeholder = (
692694
component?.placeholder || 'Search apps & content...'
693695
);
@@ -712,7 +714,7 @@ class Vasari extends App {
712714
component = this.state.components[id] = input;
713715

714716
if (component?.value) {
715-
this.state.search = component.value;
717+
this.state.input[component.id] = component.value;
716718
}
717719

718720
const inputRectGradient = this.state.canvas.context.createLinearGradient(
@@ -762,7 +764,7 @@ class Vasari extends App {
762764
attributes.width = textComponent.attributes.width;
763765
attributes.height = textComponent.attributes.height;
764766

765-
if (this.state.search) {
767+
if (this.state.input[component.id]) {
766768
this.state.canvas.context.fillStyle = textComponent.attributes.style;
767769

768770
this.state.canvas.context.font = (
@@ -779,7 +781,7 @@ class Vasari extends App {
779781
this.state.canvas.context.textRendering = 'optimizeLegibility';
780782

781783
this.state.canvas.context.fillText(
782-
this.state.search || placeholder,
784+
this.state.input[component.id] || placeholder,
783785
textComponent.attributes.x,
784786
textComponent.attributes.y,
785787
textComponent.attributes.width
@@ -991,7 +993,11 @@ class Vasari extends App {
991993
if (element.childNodes?.length) {
992994
const [{ _rawText } = {}] = element.childNodes;
993995

994-
const state = this.docState;
996+
const state = {
997+
...this.docState,
998+
999+
exec
1000+
};
9951001

9961002
eval(`(() => { ${_rawText} })()`);
9971003
}
@@ -1002,7 +1008,11 @@ class Vasari extends App {
10021008
this.events[id] = event => {
10031009
const [{ _rawText } = {}] = element.childNodes;
10041010

1005-
const state = this.docState;
1011+
const state = {
1012+
...this.docState,
1013+
1014+
exec
1015+
};
10061016

10071017
eval(`(() => { ${_rawText} })()`);
10081018
};

renderers/Vespucci/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class Vespucci extends Vasari {
232232
break;
233233
}
234234

235-
this.state.search = path;
235+
this.state.input.search = path;
236236
this.events = {};
237237
this.listeners = {};
238238

0 commit comments

Comments
 (0)