This commit is contained in:
lingdocs 2022-03-24 16:05:07 +05:00
parent 5e4639df84
commit 825b37e9fb
5 changed files with 35 additions and 29 deletions

View File

@ -98,7 +98,10 @@ export function PhraseBuilder() {
<div>{servantEmoji} = <abbr title="can be shrunken into a mini-pronoun">servant</abbr> of phrase</div> <div>{servantEmoji} = <abbr title="can be shrunken into a mini-pronoun">servant</abbr> of phrase</div>
</div> </div>
{verb && (typeof verb.object === "object") && <div className="d-flex flex-row justify-content-around flex-wrap mb-2"> {verb && (typeof verb.object === "object") && <div className="d-flex flex-row justify-content-around flex-wrap mb-2">
<button onClick={handleSubjObjSwap} className="btn btn-sm btn-light">swap subj/obj</button> <button onClick={handleSubjObjSwap} className="btn btn-sm btn-light">
<i className="fas fa-exchange-alt mr-2" /> subj/obj
</button>
<div>{` `}</div>
</div>} </div>}
<div className="d-flex flex-row justify-content-around flex-wrap"> <div className="d-flex flex-row justify-content-around flex-wrap">
<div className="mb-2"> <div className="mb-2">

View File

@ -3,40 +3,44 @@ import { renderVP, compileVP } from "../../lib/phrase-building";
import { import {
InlinePs, InlinePs,
defaultTextOptions as opts, defaultTextOptions as opts,
ButtonSelect,
Types as T, Types as T,
} from "@lingdocs/pashto-inflector"; } from "@lingdocs/pashto-inflector";
import classNames from "classnames";
function adjustForm(form: FormVersion, servantShrinkable: boolean): FormVersion { function buttonClass(active: boolean, side: "l" | "r") {
if (!servantShrinkable) { return classNames(
return form === "shortest" "btn btn-sm btn-outline-secondary",
? "no king" { active },
: form === "mini servant" { "mr-1": side === "l" },
? "full" { "ml-1": side === "r" },
: form; );
}
return form;
} }
function VPDisplay({ VP }: { VP: VPSelection }) { function VPDisplay({ VP }: { VP: VPSelection }) {
const [form, setForm] = useState<FormVersion>("full"); const [form, setForm] = useState<FormVersion>({ removeKing: false, shrinkServant: false });
// TODO: Possibly put the servant shrinking in here after the render // TODO: Possibly put the servant shrinking in here after the render
const result = compileVP(renderVP(VP), form); const result = compileVP(renderVP(VP), form);
const servantShrinkable = VP.object && VP.object !== "none"; const servantShrinkable = VP.object && VP.object !== "none";
const toggleForm = (f: "removeKing" | "shrinkServant") => () => {
setForm(oForm => ({
...oForm,
[f]: !oForm[f],
}));
}
return <div className="text-center mt-2"> return <div className="text-center mt-2">
<div className="my-3"> <div className="my-3">
<ButtonSelect <button
small onClick={toggleForm("removeKing")}
options={[ className={buttonClass(form.removeKing, "l")}
{ value: "full", label: "Full" }, >
{ value: "no king", label: "No King" }, 🚫 King
...servantShrinkable ? [{ value: "mini servant", label: "Mini Servant" }] : [], </button>
...servantShrinkable ? [{ value: "shortest", label: "Shortest" }] : [], {servantShrinkable && <button
]} onClick={toggleForm("shrinkServant")}
value={adjustForm(form, servantShrinkable)} className={buttonClass(form.shrinkServant, "r")}
// @ts-ignore >
handleChange={setForm} 👶 Servant
/> </button>}
</div> </div>
{"long" in result.ps ? {"long" in result.ps ?
<div> <div>

View File

@ -67,9 +67,8 @@ function shrinkEntitiesAndGatherKids(VP: VPRendered, form: FormVersion): { kids:
subject: VP.subject.ps, subject: VP.subject.ps,
object: typeof VP.object === "object" ? VP.object.ps : undefined, object: typeof VP.object === "object" ? VP.object.ps : undefined,
} }
const removeKing = form === "no king" || form === "shortest"; const { removeKing, shrinkServant } = form;
const shrinkServant = form === "mini servant" || form === "shortest"; const shrinkCanditate = (shrinkServant && VP.servant)
const shrinkCanditate = ((form === "mini servant" || form === "shortest") && VP.servant)
? VP[VP.servant] ? VP[VP.servant]
: undefined; : undefined;
const toShrink = (!shrinkCanditate || typeof shrinkCanditate !== "object") const toShrink = (!shrinkCanditate || typeof shrinkCanditate !== "object")

View File

@ -97,7 +97,7 @@ type ParticipleSelection = {
// If T has key K ("user"), replace it // If T has key K ("user"), replace it
type ReplaceKey<T, K extends string, R> = T extends Record<K, unknown> ? (Omit<T, K> & Record<K, R>) : T; type ReplaceKey<T, K extends string, R> = T extends Record<K, unknown> ? (Omit<T, K> & Record<K, R>) : T;
type FormVersion = "full" | "no king" | "mini servant" | "shortest"; // TODO: "all"; type FormVersion = { removeKing: boolean, shrinkServant: boolean };
type Rendered<T extends NPSelection> = ReplaceKey< type Rendered<T extends NPSelection> = ReplaceKey<
Omit<T, "changeGender" | "changeNumber" | "changeDistance">, Omit<T, "changeGender" | "changeNumber" | "changeDistance">,

File diff suppressed because one or more lines are too long