@@ -80,15 +80,26 @@ export function makeDefaultValues(variables: Variable[]): Record<string, number>
8080
8181export function initializeRows (
8282 variables : Variable [ ] ,
83- defaultRows ?: Array < Record < string , number > > ,
83+ defaultRows ?: Array < Record < string , number | string > > ,
8484 count : number = 1 ,
8585) : RowData [ ] {
8686 const defaults = makeDefaultValues ( variables ) ;
8787 if ( defaultRows ) {
88- return defaultRows . map ( overrides => ( {
89- id : nanoid ( ) ,
90- values : { ...defaults , ...overrides } ,
91- } ) ) ;
88+ return defaultRows . map ( overrides => {
89+ const resolved : Record < string , number > = { } ;
90+ for ( const [ key , val ] of Object . entries ( overrides ) ) {
91+ if ( typeof val === 'string' ) {
92+ try {
93+ resolved [ key ] = new Function ( `return (${ val } )` ) ( ) as number ;
94+ } catch {
95+ resolved [ key ] = parseFloat ( val ) || 0 ;
96+ }
97+ } else {
98+ resolved [ key ] = val ;
99+ }
100+ }
101+ return { id : nanoid ( ) , values : { ...defaults , ...resolved } } ;
102+ } ) ;
92103 }
93104 return Array . from ( { length : count } , ( ) => ( {
94105 id : nanoid ( ) ,
@@ -271,13 +282,7 @@ export function getFormulaBoxStyle(isDark: boolean): React.CSSProperties {
271282 } ;
272283}
273284
274- export function getButtonStyle ( isDark : boolean ) : React . CSSProperties {
275- return {
276- backgroundColor : isDark ? 'rgba(24, 24, 27, 0.7)' : '#ffffff' ,
277- borderColor : isDark ? 'rgba(63, 63, 70, 0.5)' : '#e5e7eb' ,
278- color : isDark ? '#f1f5f9' : '#0a0a0a' ,
279- } ;
280- }
285+ export const getButtonStyle = getInputStyle ;
281286
282287export function getAddButtonStyle ( isDark : boolean ) : React . CSSProperties {
283288 return {
@@ -378,6 +383,32 @@ export const VariableInput: React.FC<{
378383 ) ;
379384} ;
380385
386+ export const LabeledVariableInput : React . FC < {
387+ variable : Variable ;
388+ value : number | string ;
389+ onChange : ( value : string ) => void ;
390+ isDark : boolean ;
391+ centered ?: boolean ;
392+ } > = ( { variable, value, onChange, isDark, centered } ) => (
393+ < div className = { `flex items-center gap-3${ centered ? ' justify-center' : '' } ` } >
394+ < VariableInput
395+ variable = { variable }
396+ value = { value }
397+ onChange = { onChange }
398+ isDark = { isDark }
399+ className = "w-24"
400+ />
401+ < span
402+ className = "calculator-formula text-sm font-medium shrink-0"
403+ style = { { color : getLabelColor ( isDark ) } }
404+ dangerouslySetInnerHTML = { { __html : renderKatexInline ( variable . nameInTheFormula ) } }
405+ />
406+ < span className = "text-sm" style = { { color : getSubtextColor ( isDark ) } } >
407+ { variable . variableDescription }
408+ </ span >
409+ </ div >
410+ ) ;
411+
381412export const ColumnHeaders : React . FC < {
382413 variables : Variable [ ] ;
383414 isDark : boolean ;
0 commit comments