tests / ci (push) Canceled after 0s
O campo numérico do navegador segue a língua do navegador: «25.000» era lido como 25 e a vírgula decimal podia ser recusada, pelo que o investidor via o valor mudar ou não conseguia escrever. Os campos de montantes do simulador, do plano de negócio e do orçamento inicial passam a usar um campo de texto decimal que lê os números como se escrevem em Moçambique, mostra «Lido como …» quando reinterpreta e deixa o texto inválido chegar à validação, que o explica. Os campos inteiros (horizonte, prazo de entrega, vida útil, mês económico) deixam de saltar para 1 quando se apaga para reescrever; se o valor escrito não for aceite, ao sair do campo volta o valor em vigor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
// The real DecimalInput, compiled for the harnesses that load components with
|
|
// their own `require`, plus helpers to type into it from a walked element tree.
|
|
import fs from 'node:fs';
|
|
import { compileFunction } from 'node:vm';
|
|
import { createRequire } from 'node:module';
|
|
import React from 'react';
|
|
import ts from 'typescript';
|
|
import * as decimal from '../../../resources/js/lib/decimal-input.ts';
|
|
|
|
const require = createRequire(import.meta.url);
|
|
const module = { exports: {} };
|
|
compileFunction(
|
|
ts.transpileModule(
|
|
fs.readFileSync(
|
|
new URL(
|
|
'../../../resources/js/components/decimal-input.tsx',
|
|
import.meta.url,
|
|
),
|
|
'utf8',
|
|
),
|
|
{
|
|
compilerOptions: {
|
|
module: ts.ModuleKind.CommonJS,
|
|
jsx: ts.JsxEmit.ReactJSX,
|
|
},
|
|
},
|
|
).outputText,
|
|
['require', 'module', 'exports'],
|
|
)(
|
|
(id) =>
|
|
id === 'react'
|
|
? React
|
|
: id === '@/lib/decimal-input'
|
|
? decimal
|
|
: require(id),
|
|
module,
|
|
module.exports,
|
|
);
|
|
|
|
export const decimalInputModule = module.exports;
|
|
export const DecimalInput = module.exports.DecimalInput;
|
|
|
|
/** A number field in a walked tree: the decimal field or a plain number input. */
|
|
export const isNumberField = (node) =>
|
|
node?.type === DecimalInput ||
|
|
(node?.type === 'input' && node.props?.type === 'number');
|
|
|
|
/** Types `value` as the investor would, through whichever field the tree holds. */
|
|
export function typeNumber(node, value) {
|
|
const text = String(value);
|
|
if (node.type === DecimalInput) {
|
|
const normalized = decimal.normalizeDecimalInput(text);
|
|
node.props.onValueChange(normalized === null ? text : normalized);
|
|
return;
|
|
}
|
|
node.props.onChange({ target: { value: text } });
|
|
}
|