From e9ef40f8a15a523f16906368b96d3151008af394 Mon Sep 17 00:00:00 2001 From: adueck Date: Fri, 23 Sep 2022 12:33:14 +0400 Subject: [PATCH] fixed issue with the leftover form choice potentially not being compatible with a dynamic compound when selected --- src/App.tsx | 1 + src/components/vp-explorer/verb-selection.ts | 4 ++- src/lib/jsx-map.tsx | 33 +++++++++++++------- src/lib/type-predicates.ts | 3 +- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 9efae8f..c957139 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -28,6 +28,7 @@ import defualtTextOptions from "./lib/default-text-options"; import PhraseBuilder from "./components/vp-explorer/VPExplorer"; import useStickyState from "./lib/useStickyState"; import { EPExplorer } from "./library"; + type VerbType = "simple" | "stative compound" | "dynamic compound"; const verbTypes: VerbType[] = [ "simple", diff --git a/src/components/vp-explorer/verb-selection.ts b/src/components/vp-explorer/verb-selection.ts index 8dfc398..7fcb4ae 100644 --- a/src/components/vp-explorer/verb-selection.ts +++ b/src/components/vp-explorer/verb-selection.ts @@ -74,7 +74,9 @@ export function makeVPSelectionState( externalComplement: takesExternalComplement(verb) ? { type: "complement", selection: { type: "unselected" }} : undefined, - form: os ? os.form : { removeKing: false, shrinkServant: false }, + form: (os && info.type !== "dynamic compound") + ? os.form + : { removeKing: false, shrinkServant: false }, }; } diff --git a/src/lib/jsx-map.tsx b/src/lib/jsx-map.tsx index 2716be9..ab6609f 100644 --- a/src/lib/jsx-map.tsx +++ b/src/lib/jsx-map.tsx @@ -55,21 +55,30 @@ export function psJSXMap(ps: T.PsJSX, target: "p" | "f", dealWithString: (ps: T. /** * Allows a text transform function to be run over all the text in a JSX element - * + * * @param e a JSX Element * @param f a function to transform the text * @returns the JSX Element with all the text transformed */ -export function JSXMap(e: JSX.Element, f: (s: string) => string): JSX.Element { + export function JSXTextTransform( + e: JSX.Element | string, + f: (s: string) => string + ): JSX.Element | string { + if (typeof e === "string") { + return f(e); + } return { - ...e, - props: { - ...e.props, - children: typeof e.props.children === "string" - ? f(e.props.children) - : e.props.children.map((x: string | JSX.Element) => ( - (typeof x === "string") ? f(x) : JSXMap(x, f) - )), - }, + ...e, + props: { + ...e.props, + children: + typeof e.props.children === "string" + ? f(e.props.children) + : Array.isArray(e.props.children) + ? e.props.children.map((x: string | JSX.Element) => ( + JSXTextTransform(x, f) + )) + : JSXTextTransform(e.props.children, f) + } }; -} \ No newline at end of file + } \ No newline at end of file diff --git a/src/lib/type-predicates.ts b/src/lib/type-predicates.ts index bb39f19..c2e1a79 100644 --- a/src/lib/type-predicates.ts +++ b/src/lib/type-predicates.ts @@ -24,7 +24,8 @@ export function isAdverbEntry(e: T.Entry | T.DictionaryEntry): e is T.AdverbEntr } export function isLocativeAdverbEntry(e: T.Entry | T.DictionaryEntry): e is T.LocativeAdverbEntry { - return isAdverbEntry(e) && e.c.includes("loc. adv."); + if ("entry" in e) return false; + return !!e.c?.includes("loc. adv."); } export function isNounOrAdjEntry(e: T.Entry): e is (T.NounEntry | T.AdjectiveEntry) {