Adds a default template to resolver, adds "last" variable
This commit is contained in:
parent
9c9edd9e90
commit
1799c8da79
@ -34,8 +34,8 @@ export function OnDemandResolver({
|
||||
const res = useRef(new TTCQueryResolver(parser));
|
||||
const [content, setContent] = useState<ReactNode>("");
|
||||
const generateContent = useCallback(() => {
|
||||
let content = template;
|
||||
const stackIdxs = Array.from(new Set(template.match(/\$\d/g)));
|
||||
let content = template || "$x";
|
||||
const stackIdxs = Array.from(new Set(content.match(/\$(?:\d+|x)/g)));
|
||||
for (const idx of stackIdxs) {
|
||||
let thing = res.current.getFromStack(idx);
|
||||
if (Array.isArray(thing)) thing = thing.at(0);
|
||||
@ -52,12 +52,16 @@ export function OnDemandResolver({
|
||||
}, [res, resolver, generateContent]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<button onMouseDown={() => setContent("")} onClick={resolve}>
|
||||
<div className="my-2 rounded-md p-1 bg-black/20 w-min">
|
||||
<button
|
||||
className="text-primary-600"
|
||||
onMouseDown={() => setContent("")}
|
||||
onClick={resolve}
|
||||
>
|
||||
{title ?? "Resolve"}
|
||||
</button>
|
||||
<br />
|
||||
{!!content && <span>{content}</span>}
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -165,6 +165,7 @@ export class TTCQueryResolver {
|
||||
}
|
||||
|
||||
public getFromStack(stackIndex: string): StackItem {
|
||||
if (stackIndex === "$x") return this.stack.at(-1)!;
|
||||
const i = Number(stackIndex.replace("$", ""));
|
||||
const val = this.stack[i];
|
||||
return val;
|
||||
|
Loading…
x
Reference in New Issue
Block a user