// Copyright 2020 Blue Static // This program is free software licensed under the GNU General Public License, // version 3.0. The full text of the license can be found in LICENSE.txt. // SPDX-License-Identifier: GPL-3.0-only import { createDependentEffect, createMemo, createState } from 'solid-js'; import { For, Show } from 'solid-js/dom'; import { TaxReturn, Form, Line } from 'ustaxlib/core'; import { Edge, getLastTraceList } from 'ustaxlib/core/Trace'; import { graphviz } from 'd3-graphviz'; const S = require('./FormView.css'); interface FormProps { tr: TaxReturn; form: Form; } export default function FormView(props: FormProps) { const lines = createMemo(() => { const keys = Object.keys(props.form.lines); keys.sort((a, b) => a.localeCompare(b, undefined, { numeric: true })); return keys.map(k => props.form.lines[k]); }); return (

Form {props.form.name}

{line => }
); } interface LineProps { tr: TaxReturn; line: Line; } function LineView(props: LineProps) { const { tr, line } = props; const value = createMemo(() => { try { return JSON.stringify(line.value(tr), null, 1); } catch (e) { return {e.message}; } }); const [ state, setState ] = createState({ trace: [] as readonly Edge[], showTrace: false }); createDependentEffect(() => setState('trace', getLastTraceList()), [value]); const toggleTrace = () => setState('showTrace', !state.showTrace); return ( <>
{line.id}
{line.description}
{value()}
setState('showTrace', false)} /> ); } interface TraceProps { line: Line; trace: readonly Edge[]; onClose: () => void; } function TraceViewer(props: TraceProps) { const renderGraph = (ref) => { let graph = ''; for (const edge of props.trace) { graph += `"${edge[1]}" -> "${edge[0]}"; `; } graphviz(ref) .zoomScaleExtent([0.1, 1]) .renderDot(`digraph { ${graph} }`, () => { if (ref.querySelector('svg').clientWidth > ref.parentNode.clientWidth) { ref.parentNode.classList.add(S.large); } }); }; return (

Trace {props.line.id}

); }