forgot to get the tense-picker going again

This commit is contained in:
adueck 2022-10-10 12:39:51 +05:00
parent 345a03edb9
commit e05d6f1111
5 changed files with 187 additions and 188 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.0.11", "version": "5.0.12",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.0.11", "version": "5.0.12",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "5.0.11", "version": "5.0.12",
"author": "lingdocs.com", "author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations", "description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com", "homepage": "https://verbs.lingdocs.com",

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "5.0.11", "version": "5.0.12",
"description": "Pashto inflector library module with React components", "description": "Pashto inflector library module with React components",
"main": "dist/components/library.js", "main": "dist/components/library.js",
"module": "dist/components/library.js", "module": "dist/components/library.js",

View File

@ -1,9 +1,9 @@
// import Select from "react-select"; import Select from "react-select";
import * as T from "../../../types"; import * as T from "../../../types";
// import ButtonSelect from "../ButtonSelect"; import ButtonSelect from "../ButtonSelect";
import { isImperativeTense, isModalTense, isPerfectTense, isVerbTense } from "../../../lib/src/type-predicates"; import { isImperativeTense, isModalTense, isPerfectTense, isVerbTense } from "../../../lib/src/type-predicates";
// import useStickyState from "../../lib/useStickyState"; import useStickyState from "../useStickyState";
// import { customStyles } from "../EntrySelect"; import { customStyles } from "../EntrySelect";
import { import {
VpsReducerAction VpsReducerAction
} from "../../../lib/src/phrase-building/vps-reducer"; } from "../../../lib/src/phrase-building/vps-reducer";
@ -42,15 +42,15 @@ const verbTenseOptions: { label: string | JSX.Element, value: T.VerbTense, formu
formula: "ba + simple past", formula: "ba + simple past",
}]; }];
// function composeFormula(formula: string, prefix: "passive" | "ability"): string { function composeFormula(formula: string, prefix: "passive" | "ability"): string {
// return formula.replace(/^perfective/, `${prefix} perfective`) return formula.replace(/^perfective/, `${prefix} perfective`)
// .replace(/^imperfective/, `${prefix} imperfective`) .replace(/^imperfective/, `${prefix} imperfective`)
// .replace("continuous", `${prefix} continuous`) .replace("continuous", `${prefix} continuous`)
// .replace("simple", `${prefix} simple`) .replace("simple", `${prefix} simple`)
// .replace(/present$/, `${prefix} present`) .replace(/present$/, `${prefix} present`)
// .replace(/subjunctive$/, `${prefix} subjunctive`) .replace(/subjunctive$/, `${prefix} subjunctive`)
// .replace("past participle", `${prefix} past participle`); .replace("past participle", `${prefix} past participle`);
// } }
const perfectTenseOptions: { label: string | JSX.Element, value: T.PerfectTense, formula: string }[] = [{ const perfectTenseOptions: { label: string | JSX.Element, value: T.PerfectTense, formula: string }[] = [{
label: "Present Perfect", label: "Present Perfect",
@ -124,176 +124,175 @@ function TensePicker(props: ({
onChange: (p: VpsReducerAction) => void, onChange: (p: VpsReducerAction) => void,
mode: "charts" | "phrases" | "quiz", mode: "charts" | "phrases" | "quiz",
}) { }) {
return <div>not here</div> const [showFormula, setShowFormula] = useStickyState<boolean>(false, "showFormula");
// const [showFormula, setShowFormula] = useStickyState<boolean>(false, "showFormula"); function onTenseSelect(o: { value: T.VerbTense | T.PerfectTense | T.ImperativeTense } | null) {
// function onTenseSelect(o: { value: T.VerbTense | T.PerfectTense | T.ImperativeTense } | null) { if ("vpsComplete" in props) return;
// if ("vpsComplete" in props) return; const tense = o?.value ? o.value : undefined;
// const tense = o?.value ? o.value : undefined; props.onChange({
// props.onChange({ type: "set tense",
// type: "set tense", payload: tense,
// payload: tense, });
// }); }
// } function moveTense(dir: "forward" | "back") {
// function moveTense(dir: "forward" | "back") { if ("vpsComplete" in props) return;
// if ("vpsComplete" in props) return; if (!props.vps.verb) return;
// if (!props.vps.verb) return; return () => {
// return () => { // TODO: ABSTRACT THIS - SAFER
// // TODO: ABSTRACT THIS - SAFER const tenses = props.vps.verb.tenseCategory === "perfect"
// const tenses = props.vps.verb.tenseCategory === "perfect" ? perfectTenseOptions
// ? perfectTenseOptions : props.vps.verb.tenseCategory === "imperative"
// : props.vps.verb.tenseCategory === "imperative" ? imperativeTenseOptions
// ? imperativeTenseOptions : verbTenseOptions;
// : verbTenseOptions; const currIndex = tenses.findIndex(tn => tn.value === props.vps.verb[
// const currIndex = tenses.findIndex(tn => tn.value === props.vps.verb[ // TODO: ABSTRACT THIS? - SAFER
// // TODO: ABSTRACT THIS? - SAFER props.vps.verb.tenseCategory === "perfect"
// props.vps.verb.tenseCategory === "perfect" ? "perfectTense"
// ? "perfectTense" : props.vps.verb.tenseCategory === "imperative"
// : props.vps.verb.tenseCategory === "imperative" ? "imperativeTense"
// ? "imperativeTense" : "verbTense"
// : "verbTense" ]);
// ]); if (currIndex === -1) {
// if (currIndex === -1) { console.error("error moving tense", dir);
// console.error("error moving tense", dir); return;
// return; }
// } const newIndex = dir === "forward"
// const newIndex = dir === "forward" ? ((currIndex + 1) % tenses.length)
// ? ((currIndex + 1) % tenses.length) : (currIndex === 0 ? (tenses.length - 1) : (currIndex - 1))
// : (currIndex === 0 ? (tenses.length - 1) : (currIndex - 1)) const newTense = tenses[newIndex];
// const newTense = tenses[newIndex]; onTenseSelect(newTense);
// onTenseSelect(newTense); };
// }; }
// } function onPosNegSelect(payload: "true" | "false") {
// function onPosNegSelect(payload: "true" | "false") { if ("vpsComplete" in props) return;
// if ("vpsComplete" in props) return; props.onChange({
// props.onChange({ type: "set negativity",
// type: "set negativity", payload,
// payload, });
// }); }
// } function onTenseCategorySelect(payload: "basic" | "modal" | "perfect" | "imperative") {
// function onTenseCategorySelect(payload: "basic" | "modal" | "perfect" | "imperative") { if ("vpsComplete" in props) return;
// if ("vpsComplete" in props) return; props.onChange({
// props.onChange({ type: "set tense category",
// type: "set tense category", payload,
// payload, });
// }); }
// } const tOptions = ("vps" in props && (props.vps.verb?.tenseCategory === "perfect"))
// const tOptions = ("vps" in props && (props.vps.verb?.tenseCategory === "perfect")) ? perfectTenseOptions
// ? perfectTenseOptions : ("vps" in props && (props.vps.verb?.tenseCategory === "imperative"))
// : ("vps" in props && (props.vps.verb?.tenseCategory === "imperative")) ? imperativeTenseOptions
// ? imperativeTenseOptions : verbTenseOptions;
// : verbTenseOptions; const showImperativeOption = ("vps" in props && props.vps.verb.voice === "active")
// const showImperativeOption = ("vps" in props && props.vps.verb.voice === "active") || ("vpsComplete" in props && props.vpsComplete.verb.voice !== "active");
// || ("vpsComplete" in props && props.vpsComplete.verb.voice !== "active"); const inPassiveVoice = ("vps" in props && props.vps.verb.voice === "passive") || ("vpsComplete" in props && props.vpsComplete.verb.voice === "passive");;
// const inPassiveVoice = ("vps" in props && props.vps.verb.voice === "passive") || ("vpsComplete" in props && props.vpsComplete.verb.voice === "passive");; const canHaveFormula = "vps" in props && props.mode !== "quiz";
// const canHaveFormula = "vps" in props && props.mode !== "quiz"; return <div>
// return <div> <div style={{ maxWidth: "300px", minWidth: "250px", margin: "0 auto" }}>
// <div style={{ maxWidth: "300px", minWidth: "250px", margin: "0 auto" }}> <div className="d-flex flex-row justify-content-between align-items-center">
// <div className="d-flex flex-row justify-content-between align-items-center"> <div className="h5">Verb Tense:</div>
// <div className="h5">Verb Tense:</div> {canHaveFormula && <div className="clickable mb-2 small" onClick={() => setShowFormula(x => !x)}>
// {canHaveFormula && <div className="clickable mb-2 small" onClick={() => setShowFormula(x => !x)}> 🧪 {!showFormula ? "Show" : "Hide"} Formula
// 🧪 {!showFormula ? "Show" : "Hide"} Formula </div>}
// </div>} </div>
// </div> {("vpsComplete" in props || props.vps.verb) && <div className="mb-2">
// {("vpsComplete" in props || props.vps.verb) && <div className="mb-2"> <ButtonSelect
// <ButtonSelect small
// small value={"vpsComplete" in props
// value={"vpsComplete" in props ? getTenseCategory(props.vpsComplete.verb.tense)
// ? getTenseCategory(props.vpsComplete.verb.tense) : props.vps.verb.tenseCategory}
// : props.vps.verb.tenseCategory} // @ts-ignore
// // @ts-ignore options={showImperativeOption ? [{
// options={showImperativeOption ? [{ label: "Basic",
// label: "Basic", value: "basic",
// value: "basic", }, {
// }, { label: "Perfect",
// label: "Perfect", value: "perfect",
// value: "perfect", }, {
// }, { label: "Ability",
// label: "Ability", value: "modal",
// value: "modal", }, {
// }, { label: "Imperative",
// label: "Imperative", value: "imperative",
// value: "imperative", }] : [{
// }] : [{ label: "Basic",
// label: "Basic", value: "basic",
// value: "basic", }, {
// }, { label: "Perfect",
// label: "Perfect", value: "perfect",
// value: "perfect", }, {
// }, { label: "Ability",
// label: "Ability", value: "modal",
// value: "modal", }].filter(x => !(inPassiveVoice && x.value === "modal"))}
// }].filter(x => !(inPassiveVoice && x.value === "modal"))} handleChange={props.mode !== "quiz" ? onTenseCategorySelect : () => null}
// handleChange={props.mode !== "quiz" ? onTenseCategorySelect : () => null} />
// /> </div>}
// </div>} {"vpsComplete" in props
// {"vpsComplete" in props ? <div style={{ fontSize: "larger" }} className="mb-3">
// ? <div style={{ fontSize: "larger" }} className="mb-3"> {[...verbTenseOptions, ...perfectTenseOptions, ...imperativeTenseOptions].find(o => o.value === props.vpsComplete.verb.tense)?.label}
// {[...verbTenseOptions, ...perfectTenseOptions, ...imperativeTenseOptions].find(o => o.value === props.vpsComplete.verb.tense)?.label} </div>
// </div> : <>
// : <> <Select
// <Select isSearchable={false}
// isSearchable={false} // for some reason can't use tOptions with find here;
// // for some reason can't use tOptions with find here; value={props.vps.verb && ([...verbTenseOptions, ...perfectTenseOptions, ...imperativeTenseOptions].find(o => o.value === props.vps.verb[
// value={props.vps.verb && ([...verbTenseOptions, ...perfectTenseOptions, ...imperativeTenseOptions].find(o => o.value === props.vps.verb[ props.vps.verb.tenseCategory === "perfect"
// props.vps.verb.tenseCategory === "perfect" ? "perfectTense"
// ? "perfectTense" : props.vps.verb.tenseCategory === "imperative"
// : props.vps.verb.tenseCategory === "imperative" ? "imperativeTense"
// ? "imperativeTense" : "verbTense"
// : "verbTense" ]))}
// ]))} // @ts-ignore - gets messed up when using customStyles
// // @ts-ignore - gets messed up when using customStyles onChange={onTenseSelect}
// onChange={onTenseSelect} className="mb-2"
// className="mb-2" options={tOptions}
// options={tOptions} styles={customStyles}
// styles={customStyles} />
// /> </>}
// </>} {"vps" in props && props.vps.verb && (props.mode !== "quiz") && <div className="d-flex flex-row justify-content-between align-items-center mt-2 mb-1" style={{ width: "100%" }}>
// {"vps" in props && props.vps.verb && (props.mode !== "quiz") && <div className="d-flex flex-row justify-content-between align-items-center mt-2 mb-1" style={{ width: "100%" }}> <div className="btn btn-light clickable" onClick={moveTense("back")}>
// <div className="btn btn-light clickable" onClick={moveTense("back")}> <i className="fas fa-chevron-left" />
// <i className="fas fa-chevron-left" /> </div>
// </div> {props.mode === "phrases" && <ButtonSelect
// {props.mode === "phrases" && <ButtonSelect small
// small value={props.vps.verb.negative.toString() as "true" | "false"}
// value={props.vps.verb.negative.toString() as "true" | "false"} options={[{
// options={[{ label: "Pos.",
// label: "Pos.", value: "false",
// value: "false", }, {
// }, { label: "Neg.",
// label: "Neg.", value: "true",
// value: "true", }]}
// }]} handleChange={onPosNegSelect}
// handleChange={onPosNegSelect} />}
// />} <div onClick={moveTense("forward")} className="btn btn-light clickable">
// <div onClick={moveTense("forward")} className="btn btn-light clickable"> <i className="fas fa-chevron-right" />
// <i className="fas fa-chevron-right" /> </div>
// </div> </div>}
// </div>} {(canHaveFormula && showFormula) && (() => {
// {(canHaveFormula && showFormula) && (() => { // TODO: Be able to show modal formulas too
// // TODO: Be able to show modal formulas too const curr = (props.vps.verb.tenseCategory === "imperative" && props.vps.verb.negative)
// const curr = (props.vps.verb.tenseCategory === "imperative" && props.vps.verb.negative) ? imperativeTenseOptions.find(x => x.value === "imperfectiveImperative")
// ? imperativeTenseOptions.find(x => x.value === "imperfectiveImperative") : [...verbTenseOptions, ...perfectTenseOptions, ...imperativeTenseOptions].find(o => o.value === props.vps.verb[
// : [...verbTenseOptions, ...perfectTenseOptions, ...imperativeTenseOptions].find(o => o.value === props.vps.verb[ props.vps.verb.tenseCategory === "perfect"
// props.vps.verb.tenseCategory === "perfect" ? "perfectTense"
// ? "perfectTense" : props.vps.verb.tenseCategory === "imperative"
// : props.vps.verb.tenseCategory === "imperative" ? "imperativeTense"
// ? "imperativeTense" : "verbTense"
// : "verbTense" ]);
// ]); const formula = !curr
// const formula = !curr ? ""
// ? "" : (props.vps.verb.tenseCategory === "modal")
// : (props.vps.verb.tenseCategory === "modal") ? composeFormula(curr.formula, "ability")
// ? composeFormula(curr.formula, "ability") : (props.vps.verb.voice === "passive")
// : (props.vps.verb.voice === "passive") ? composeFormula(curr.formula, "passive")
// ? composeFormula(curr.formula, "passive") : curr.formula;
// : curr.formula; if (curr && "formula" in curr) {
// if (curr && "formula" in curr) { return <div className="mb-2" style={{ width: "250px", overflowY: "auto" }}>
// return <div className="mb-2" style={{ width: "250px", overflowY: "auto" }}> <samp>{formula}</samp>
// <samp>{formula}</samp> </div>
// </div> }
// } })()}
// })()} </div>
// </div> </div>;
// </div>;
} }
export default TensePicker; export default TensePicker;

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/inflect", "name": "@lingdocs/inflect",
"version": "5.0.11", "version": "5.0.12",
"description": "Pashto inflector library", "description": "Pashto inflector library",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/lib/library.d.ts", "types": "dist/lib/library.d.ts",