full switch to jotai, finishes schema version query fixes

This commit is contained in:
2024-09-05 05:22:29 -06:00
parent b529445851
commit 84cbea8ce1
12 changed files with 148 additions and 91 deletions

View File

@@ -1,10 +1,10 @@
import { PublicationAtom } from "@/recoil/atoms/publication";
import { useState, useEffect, useCallback, useRef, ReactNode } from "react";
import { useRecoilValue } from "recoil";
import { TTCQueryResolver } from "../ttcQuery/TTCResolvers";
import { useAtom } from "jotai";
export function Resolver({ resolver }: { resolver: string }) {
const parser = useRecoilValue(PublicationAtom);
const [parser] = useAtom(PublicationAtom);
const [res] = useState(new TTCQueryResolver(parser));
const [content, setContent] = useState<ReactNode>("");
useEffect(() => {
@@ -15,7 +15,7 @@ export function Resolver({ resolver }: { resolver: string }) {
<resolved.display />
) : (
resolved?.display
)
),
);
}, [resolver, res]);
return <span>{content}</span>;
@@ -31,7 +31,7 @@ export function OnDemandResolver({
template: string;
title?: string;
}) {
const parser = useRecoilValue(PublicationAtom);
const [parser] = useAtom(PublicationAtom);
const res = useRef(new TTCQueryResolver(parser));
const [content, setContent] = useState<ReactNode>("");
const generateContent = useCallback(() => {

View File

@@ -5,11 +5,13 @@ import { Poppable } from "../poppables/components/poppable";
import { Accordion, AccordionContent } from "../accordion";
import { OnDemandResolver, Resolver } from "./Resolver";
// import "crypto";
export const TokenRenderers = new Map<string, TokenRenderer<any>>();
export function buildIdentifierMap(): [
TokenIdentifierMap,
IdentifierRegistration
IdentifierRegistration,
] {
const TokenIdentifiers = new Map<string, TokenIdentifier<any>>();
@@ -17,7 +19,7 @@ export function buildIdentifierMap(): [
type: string,
match: RegExp,
parseFunction: (s: string, rx: RegExp) => IdentifiedToken<M>,
renderFunction: TokenRenderer<M>
renderFunction: TokenRenderer<M>,
): void;
function registerIdentifier<M>(
type: string,
@@ -25,7 +27,7 @@ export function buildIdentifierMap(): [
parseFunction: (s: string, rx: RegExp) => IdentifiedToken<M>,
renderFunction: TokenRenderer<M>,
openTagRx: RegExp,
closeTagRx: RegExp
closeTagRx: RegExp,
): void;
function registerIdentifier<M = Record<string, string>>(
type: string,
@@ -33,7 +35,7 @@ export function buildIdentifierMap(): [
parseFunction: (s: string, rx: RegExp) => IdentifiedToken<M>,
renderFunction: TokenRenderer<M>,
openTagRx?: RegExp,
closeTagRx?: RegExp
closeTagRx?: RegExp,
) {
TokenIdentifiers.set(type, {
rx: match,
@@ -54,7 +56,7 @@ export function buildIdentifierMap(): [
start,
end,
new RegExp(openTagRx, "g"),
new RegExp(closeTagRx, "g")
new RegExp(closeTagRx, "g"),
);
}
: undefined,
@@ -125,7 +127,7 @@ export const buildOnlyDefaultElements = () => {
);
},
/(?<![\/\?])(?:\[\])+/g,
/\/\[\]/g
/\/\[\]/g,
);
// card
@@ -170,7 +172,7 @@ export const buildOnlyDefaultElements = () => {
);
},
/\[\[/g,
/\]\]/g
/\]\]/g,
);
// fenced code block
@@ -192,7 +194,7 @@ export const buildOnlyDefaultElements = () => {
{token.content}
</pre>
);
}
},
);
// list
@@ -231,7 +233,7 @@ export const buildOnlyDefaultElements = () => {
</ul>
</>
);
}
},
);
// ordered-list
@@ -271,7 +273,7 @@ export const buildOnlyDefaultElements = () => {
</ol>
</>
);
}
},
);
// ordered list-item
@@ -300,7 +302,7 @@ export const buildOnlyDefaultElements = () => {
))}
</li>
);
}
},
);
// heading
@@ -336,7 +338,7 @@ export const buildOnlyDefaultElements = () => {
{token.content}
</div>
);
}
},
);
// image
@@ -373,7 +375,7 @@ export const buildOnlyDefaultElements = () => {
}
// eslint-disable-next-line @next/next/no-img-element
return <img src={metadata.src} alt={token.content} />;
}
},
);
// anchor
@@ -417,7 +419,7 @@ export const buildOnlyDefaultElements = () => {
{token.content}
</Link>
);
}
},
);
// inline-code
@@ -440,7 +442,7 @@ export const buildOnlyDefaultElements = () => {
{token.content}
</span>
);
}
},
);
// bold
@@ -458,7 +460,7 @@ export const buildOnlyDefaultElements = () => {
},
(token) => {
return <span className="font-bold">{token.content}</span>;
}
},
);
// italic
@@ -477,7 +479,7 @@ export const buildOnlyDefaultElements = () => {
},
(token) => {
return <span className="italic">{token.content}</span>;
}
},
);
// popover
@@ -513,7 +515,7 @@ export const buildOnlyDefaultElements = () => {
</span>
</Poppable>
);
}
},
);
// accordion
@@ -543,7 +545,7 @@ export const buildOnlyDefaultElements = () => {
</Accordion>
</div>
);
}
},
);
// paragraph
@@ -569,7 +571,7 @@ export const buildOnlyDefaultElements = () => {
})}
</div>
);
}
},
);
// horizontal rule
@@ -587,7 +589,7 @@ export const buildOnlyDefaultElements = () => {
},
() => {
return <div className="w-full border-b border-mixed-500 my-3"></div>;
}
},
);
// comment
@@ -605,7 +607,7 @@ export const buildOnlyDefaultElements = () => {
},
() => {
return <></>;
}
},
);
// frontmatter
@@ -624,7 +626,7 @@ export const buildOnlyDefaultElements = () => {
},
(token) => {
return <>{token.raw}</>;
}
},
);
// table
@@ -655,8 +657,8 @@ export const buildOnlyDefaultElements = () => {
r
.split("|")
.map((c) => c.trim())
.filter((c) => !!c)
)
.filter((c) => !!c),
),
);
let headerRows: string[][] = [],
@@ -679,7 +681,7 @@ export const buildOnlyDefaultElements = () => {
}
const maxColumns = Math.max(
...[...headerRows, ...bodyRows, ...footerRows].map((r) => r.length)
...[...headerRows, ...bodyRows, ...footerRows].map((r) => r.length),
);
return {
@@ -770,7 +772,7 @@ export const buildOnlyDefaultElements = () => {
)}
</table>
);
}
},
);
// resolver
@@ -797,7 +799,7 @@ export const buildOnlyDefaultElements = () => {
if (t.content.startsWith("Error"))
return <span className="red-500">{t.content}</span>;
return <Resolver resolver={t.content} />;
}
},
);
// on-demand resolver
@@ -839,7 +841,7 @@ export const buildOnlyDefaultElements = () => {
title={t.metadata.title}
/>
);
}
},
);
return TokenIdentifiers;
@@ -848,7 +850,7 @@ export const buildOnlyDefaultElements = () => {
function findMatchingClosedParenthesis(
str: string,
openRegex: RegExp,
closedRegex: RegExp
closedRegex: RegExp,
): number | null {
let openings = 0;
let closings = 0;
@@ -904,7 +906,7 @@ function search(
start: number,
end: number,
openRx: RegExp,
closeRx: RegExp
closeRx: RegExp,
): SearchResult {
const oldEnd = end;
@@ -912,7 +914,7 @@ function search(
s,
// s.substring(0, end - start),
openRx,
closeRx
closeRx,
);
if (newEnd === null)