From d24c6d8aba7f9c21b18fdb048729e506d300347f Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Thu, 7 Jul 2022 13:58:39 -0500 Subject: [PATCH] better --- package.json | 2 +- src/components/blocks/Block.tsx | 9 +- src/components/np-picker/NPPicker.tsx | 149 +++++++++++----------- src/components/vp-explorer/VPPicker.tsx | 29 ++++- src/components/vp-explorer/vps-reducer.ts | 11 ++ src/lib/misc-helpers.ts | 9 ++ 6 files changed, 128 insertions(+), 81 deletions(-) diff --git a/package.json b/package.json index 509f20e..a31d94c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "3.2.8", + "version": "3.2.9", "author": "lingdocs.com", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "homepage": "https://verbs.lingdocs.com", diff --git a/src/components/blocks/Block.tsx b/src/components/blocks/Block.tsx index fbed879..6cec961 100644 --- a/src/components/blocks/Block.tsx +++ b/src/components/blocks/Block.tsx @@ -3,7 +3,7 @@ import classNames from "classnames"; import { getEnglishFromRendered, } from "../../lib/phrase-building/np-tools"; -import { getEnglishPersonInfo } from "../../library"; +import { getEnglishPersonInfo, getEnglishParticipleInflection } from "../../lib/misc-helpers"; import { useState } from "react"; import { getLength } from "../../lib/p-text-helpers"; import { roleIcon } from "../vp-explorer/VPExplorerExplanationModal"; @@ -101,8 +101,11 @@ function VerbSBlock({ opts, v, script }: { {getLength(v.ps, length)[0][script]} -
{v.type === "perfectParticipleBlock" ? "Past Partic." : "Verb"}
- {getEnglishPersonInfo(v.person, "short")} +
{v.type === "perfectParticipleBlock" ? "Past Partic." : "Verb"} aa
+ {((v.type === "perfectParticipleBlock" ? "Past Partic." : "Verb") + ? getEnglishParticipleInflection + : getEnglishPersonInfo + )(v.person, "short")} } diff --git a/src/components/np-picker/NPPicker.tsx b/src/components/np-picker/NPPicker.tsx index 89bb7f5..b4b9444 100644 --- a/src/components/np-picker/NPPicker.tsx +++ b/src/components/np-picker/NPPicker.tsx @@ -24,6 +24,7 @@ function NPPicker(props: { entryFeeder: T.EntryFeeder, phraseIsComplete: boolean, isShrunk?: boolean, + isRemoved?: boolean, }) { if (props.is2ndPersonPicker && ((props.np?.selection.type !== "pronoun") || !isSecondPerson(props.np.selection.person))) { throw new Error("can't use 2ndPerson NPPicker without a pronoun"); @@ -106,7 +107,9 @@ function NPPicker(props: { ? :
; const possesiveLabel = props.np?.selection.type === "participle" ? "Subj/Obj" : "Possesor"; - return <> + return
@@ -119,79 +122,79 @@ function NPPicker(props: {
- {!npType &&
-
- Choose NP + {!npType &&
+
+ Choose NP +
+ {npTypes.map((npt) =>
+ +
)} +
} + {(props.np && props.np.selection.type !== "pronoun" && (props.np.selection.possesor || addingPoss)) &&
+
+
{possesiveLabel}:
+ {(props.np.selection.possesor && !props.isShrunk && props.phraseIsComplete) &&
+ {!props.np.selection.possesor.shrunken ? "🪄" : "👶"} +
} +
{ + setAddingPoss(false); + handlePossesiveChange(undefined); + }}> + +
- {npTypes.map((npt) =>
- -
)} -
} - {(props.np && props.np.selection.type !== "pronoun" && (props.np.selection.possesor || addingPoss)) &&
-
-
{possesiveLabel}:
- {(props.np.selection.possesor && !props.isShrunk && props.phraseIsComplete) &&
- {!props.np.selection.possesor.shrunken ? "🪄" : "👶"} -
} -
{ - setAddingPoss(false); - handlePossesiveChange(undefined); - }}> - -
-
- -
} - {(npType === "noun" || npType === "participle") && props.np && !addingPoss &&
- setAddingPoss(true)}>+ {possesiveLabel} -
} - {(npType === "pronoun" && props.np?.selection.type === "pronoun") - ? onChange({ type: "NP", selection: p })} - is2ndPersonPicker={props.is2ndPersonPicker} - opts={props.opts} - /> - : npType === "noun" - ? onChange(s ? { type: "NP", selection: s } : undefined)} - opts={props.opts} - /> - : npType === "participle" - ? onChange(s ? { type: "NP", selection: s } : undefined)} - opts={props.opts} - /> - : null - } -
- ; + +
} + {(npType === "noun" || npType === "participle") && props.np && !addingPoss &&
+ setAddingPoss(true)}>+ {possesiveLabel} +
} + {(npType === "pronoun" && props.np?.selection.type === "pronoun") + ? onChange({ type: "NP", selection: p })} + is2ndPersonPicker={props.is2ndPersonPicker} + opts={props.opts} + /> + : npType === "noun" + ? onChange(s ? { type: "NP", selection: s } : undefined)} + opts={props.opts} + /> + : npType === "participle" + ? onChange(s ? { type: "NP", selection: s } : undefined)} + opts={props.opts} + /> + : null + } +
+
; } function ensureSingleShrink(old: T.NPSelection | undefined, s: T.NPSelection | undefined): T.NPSelection | undefined { diff --git a/src/components/vp-explorer/VPPicker.tsx b/src/components/vp-explorer/VPPicker.tsx index 7ab1005..329590e 100644 --- a/src/components/vp-explorer/VPPicker.tsx +++ b/src/components/vp-explorer/VPPicker.tsx @@ -95,9 +95,16 @@ function VPPicker({ opts, vps, onChange, entryFeeder }: { ? setShowingExplanation({ role: "king", item: "subject" })}>Subject {roleIcon.king} + ?
+ Subj. setShowingExplanation({ role: "king", item: "subject" })}>{roleIcon.king} + {(rendered && rendered.whatsAdjustable !== "servant") && + adjustVps({ type: "toggle king remove" })} className="mx-2 clickable"> + {!VPS?.form.removeKing ? "🚫" : "🙈"} + + } +
:
- Subject + Subj. {` `} setShowingExplanation({ role: "servant", item: "subject" })}>{roleIcon.servant} {` `} @@ -117,6 +124,7 @@ function VPPicker({ opts, vps, onChange, entryFeeder }: { onChange={handleSubjectChange} opts={opts} isShrunk={(servantIsShrunk && roles.servant === "subject")} + isRemoved={roles.king === "subject" && VPS?.form.removeKing} /> : (vps.verb && block?.type === "objectSelection" && block.selection !== "none") ?
@@ -130,9 +138,16 @@ function VPPicker({ opts, vps, onChange, entryFeeder }: { : setShowingExplanation({ role: "king", item: "object" })}>Object {roleIcon.king}
+ ?
+ Obj. setShowingExplanation({ role: "king", item: "object" })}>{roleIcon.king} + {(rendered && rendered.whatsAdjustable !== "servant") && + adjustVps({ type: "toggle king remove" })} className="mx-2 clickable"> + {!VPS?.form.removeKing ? "🚫" : "🙈"} + + } +
:
- Object + Obj. {` `} setShowingExplanation({ role: "servant", item: "object" })}>{roleIcon.servant} {` `} @@ -141,6 +156,11 @@ function VPPicker({ opts, vps, onChange, entryFeeder }: { {!servantIsShrunk ? "🪄" : "👶"} } + {(rendered && rendered.whatsAdjustable !== "servant") && + adjustVps({ type: "toggle king remove" })} className="mx-2 clickable"> + {!VPS?.form.removeKing ? "🚫" : "🙈"} + + }
} entryFeeder={entryFeeder} role="object" @@ -149,6 +169,7 @@ function VPPicker({ opts, vps, onChange, entryFeeder }: { onChange={handleObjectChange} opts={opts} isShrunk={(servantIsShrunk && roles.servant === "object")} + isRemoved={roles.king === "object" && VPS?.form.removeKing} />}
: null} diff --git a/src/components/vp-explorer/vps-reducer.ts b/src/components/vp-explorer/vps-reducer.ts index 26347e0..8c38759 100644 --- a/src/components/vp-explorer/vps-reducer.ts +++ b/src/components/vp-explorer/vps-reducer.ts @@ -53,6 +53,8 @@ export type VpsReducerAction = { } | { type: "toggle servant shrink", } | { + type: "toggle king remove", +} |{ type: "set verb", payload: T.VerbEntry, } | { @@ -251,6 +253,15 @@ export function vpsReducer(vps: T.VPSelectionState, action: VpsReducerAction, se }, }; } + if (action.type === "toggle king remove") { + return { + ...vps, + form: { + ...vps.form, + removeKing: !vps.form.removeKing, + }, + }; + } if (action.type === "set verb") { return makeVPSelectionState(action.payload, vps); } diff --git a/src/lib/misc-helpers.ts b/src/lib/misc-helpers.ts index 0d62e6d..b7f3177 100644 --- a/src/lib/misc-helpers.ts +++ b/src/lib/misc-helpers.ts @@ -163,6 +163,15 @@ export function getEnglishPersonInfo(person: T.Person, version?: "short" | "long return `${p} ${n}. ${g}.`; } +export function getEnglishParticipleInflection(person: T.Person, version?: "short" | "long"): string { + const number = personIsPlural(person) ? "plural" : "singular"; + const n = version === "short" + ? (number === "plural" ? "plur." : "sing.") : number; + const gender = personGender(person); + const g = gender; + return `${g}. ${n}`; +} + export function randomNumber(minInclusive: number, maxExclusive: number): number { return Math.floor(Math.random() * (maxExclusive - minInclusive) + minInclusive); }