fixing make saveable vps data
This commit is contained in:
parent
e2a90e6315
commit
693e8dd9ab
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@lingdocs/pashto-inflector",
|
||||
"version": "2.3.5",
|
||||
"version": "2.3.6",
|
||||
"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",
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
import PronounPicker from "./NPPronounPicker";
|
||||
import NounPicker from "./NPNounPicker";
|
||||
import ParticiplePicker from "./NPParticiplePicker";
|
||||
// import { getEnglishPronoun } from "../../lib/english-pronoun-tools";
|
||||
// import { ButtonSelect } from "@lingdocs/pashto-inflector";
|
||||
import {
|
||||
randomPerson,
|
||||
} from "../../lib/np-tools";
|
||||
import { useState, useEffect } from "react";
|
||||
import * as T from "../../types";
|
||||
import { isSecondPerson } from "../../lib/phrase-building/vp-tools";
|
||||
// import { capitalizeFirstLetter } from "../../lib/text-tools";
|
||||
|
||||
const npTypes: T.NPType[] = ["pronoun", "noun", "participle"];
|
||||
|
||||
|
@ -33,6 +30,7 @@ function NPPicker(props: {
|
|||
const [npType, setNpType] = useState<T.NPType | undefined>(props.np ? props.np.type : undefined);
|
||||
useEffect(() => {
|
||||
setNpType(props.np ? props.np.type : undefined);
|
||||
setAddingPoss(false);
|
||||
}, [props.np]);
|
||||
function handleClear() {
|
||||
if (props.np && props.np.type === "noun" && props.np.dynamicComplement) return;
|
||||
|
@ -186,9 +184,8 @@ function checkForNewPossesor(n: T.NPSelection | undefined, old: T.PossesorSelect
|
|||
return false;
|
||||
}
|
||||
|
||||
// TODO: BETTER UID
|
||||
function makeUID() {
|
||||
return Math.floor(Math.random() * 50000);
|
||||
return Math.floor(Math.random() * 10000000);
|
||||
}
|
||||
|
||||
export default NPPicker;
|
|
@ -45,7 +45,7 @@ export function VPExplorer(props: {
|
|||
}) {
|
||||
const [vps, setVps] = useStickyState<T.VPSelectionState>(
|
||||
savedVps => makeVPSelectionState(props.verb, savedVps),
|
||||
"vpsState6",
|
||||
"vpsState7",
|
||||
);
|
||||
const [mode, setMode] = useStickyState<"charts" | "phrases" | "quiz">(
|
||||
savedMode => {
|
||||
|
|
|
@ -5,6 +5,7 @@ import { getVerbInfo } from "../../lib/verb-info";
|
|||
import Hider from "../Hider";
|
||||
import useStickyState from "../../lib/useStickyState";
|
||||
import CompoundDisplay from "./CompoundDisplay";
|
||||
import { changeStatDyn, changeTransitivity, changeVoice } from "./verb-selection";
|
||||
|
||||
// TODO: dark on past tense selecitons
|
||||
|
||||
|
@ -27,7 +28,7 @@ function VerbPicker(props: {
|
|||
return <div>ERROR: Verb version should be select first</div>;
|
||||
}
|
||||
function onVoiceSelect(value: "active" | "passive") {
|
||||
if (props.vps.verb && props.vps.verb.changeVoice) {
|
||||
if (props.vps.verb && props.vps.verb.canChangeVoice) {
|
||||
if (value === "passive" && props.vps.verb.tenseCategory === "imperative") {
|
||||
return;
|
||||
}
|
||||
|
@ -35,12 +36,12 @@ function VerbPicker(props: {
|
|||
props.onChange({
|
||||
...props.vps,
|
||||
subject: props.vps.verb.object,
|
||||
verb: props.vps.verb.changeVoice(value, props.vps.verb.object),
|
||||
verb: changeVoice(props.vps.verb, value, props.vps.verb.object),
|
||||
});
|
||||
} else {
|
||||
props.onChange({
|
||||
...props.vps,
|
||||
verb: props.vps.verb.changeVoice(value, value === "active" ? props.vps.subject : undefined),
|
||||
verb: changeVoice(props.vps.verb, value, value === "active" ? props.vps.subject : undefined),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -49,18 +50,18 @@ function VerbPicker(props: {
|
|||
return t === "intransitive" ? "transitive" : t;
|
||||
}
|
||||
function handleChangeTransitivity(t: "transitive" | "grammatically transitive") {
|
||||
if (props.vps.verb && props.vps.verb.changeTransitivity) {
|
||||
if (props.vps.verb && props.vps.verb.canChangeTransitivity) {
|
||||
props.onChange({
|
||||
...props.vps,
|
||||
verb: props.vps.verb.changeTransitivity(t),
|
||||
verb: changeTransitivity(props.vps.verb, t),
|
||||
});
|
||||
}
|
||||
}
|
||||
function handleChangeStatDyn(c: "stative" | "dynamic") {
|
||||
if (props.vps.verb && props.vps.verb.changeStatDyn) {
|
||||
if (props.vps.verb && props.vps.verb.canChangeStatDyn) {
|
||||
props.onChange({
|
||||
...props.vps,
|
||||
verb: props.vps.verb.changeStatDyn(c),
|
||||
verb: changeStatDyn(props.vps.verb, c),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +85,7 @@ function VerbPicker(props: {
|
|||
</Hider>
|
||||
</div>}
|
||||
<div className="d-flex flex-row justify-content-around flex-wrap" style={{ maxWidth: "400px", margin: "0 auto" }}>
|
||||
{props.vps.verb && props.vps.verb.changeTransitivity && <div className="text-center my-2">
|
||||
{props.vps.verb && props.vps.verb.canChangeTransitivity && <div className="text-center my-2">
|
||||
<ButtonSelect
|
||||
small
|
||||
options={[{
|
||||
|
@ -98,7 +99,7 @@ function VerbPicker(props: {
|
|||
handleChange={handleChangeTransitivity}
|
||||
/>
|
||||
</div>}
|
||||
{props.vps.verb && props.vps.verb.changeVoice && <div className="text-center my-2">
|
||||
{props.vps.verb && props.vps.verb.canChangeVoice && <div className="text-center my-2">
|
||||
<ButtonSelect
|
||||
small
|
||||
value={props.vps.verb.voice}
|
||||
|
@ -117,7 +118,7 @@ function VerbPicker(props: {
|
|||
handleChange={onVoiceSelect}
|
||||
/>
|
||||
</div>}
|
||||
{props.vps.verb && props.vps.verb.changeStatDyn && <div className="text-center my-2">
|
||||
{props.vps.verb && props.vps.verb.canChangeStatDyn && <div className="text-center my-2">
|
||||
<ButtonSelect
|
||||
small
|
||||
options={[{
|
||||
|
|
|
@ -62,39 +62,43 @@ export function makeVPSelectionState(
|
|||
? (os?.verb.voice || "active")
|
||||
: "active",
|
||||
negative: os ? os.verb.negative : false,
|
||||
...("grammaticallyTransitive" in info) ? {
|
||||
changeTransitivity: function(t) {
|
||||
return {
|
||||
...this,
|
||||
transitivity: t,
|
||||
object: t === "grammatically transitive" ? T.Person.ThirdPlurMale : undefined,
|
||||
};
|
||||
},
|
||||
} : {},
|
||||
...("stative" in info) ? {
|
||||
changeStatDyn: function(c) {
|
||||
return {
|
||||
...this,
|
||||
isCompound: c,
|
||||
object: c === "dynamic"
|
||||
? makeNounSelection(info.dynamic.objComplement.entry as T.NounEntry, true)
|
||||
: undefined,
|
||||
dynAuxVerb: c === "dynamic"
|
||||
? { entry: info.dynamic.auxVerb } as T.VerbEntry
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
} : {},
|
||||
...(transitivity === "transitive") ? {
|
||||
changeVoice: function(v, s) {
|
||||
return {
|
||||
...this,
|
||||
voice: v,
|
||||
object: v === "active" ? s : "none",
|
||||
};
|
||||
},
|
||||
} : {},
|
||||
canChangeTransitivity: "grammaticallyTransitive" in info,
|
||||
canChangeVoice: transitivity === "transitive",
|
||||
canChangeStatDyn: "stative" in info,
|
||||
},
|
||||
shrunkenPossesive: os ? os.shrunkenPossesive : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export function changeVoice(v: T.VerbSelection, voice: "active" | "passive", s: T.NPSelection | undefined): T.VerbSelection {
|
||||
return {
|
||||
...v,
|
||||
voice,
|
||||
object: voice === "active" ? s : "none",
|
||||
};
|
||||
}
|
||||
|
||||
export function changeStatDyn(v: T.VerbSelection, s: "dynamic" | "stative"): T.VerbSelection {
|
||||
const info = getVerbInfo(v.verb.entry, v.verb.complement);
|
||||
if (!("stative" in info)) {
|
||||
return v;
|
||||
}
|
||||
return {
|
||||
...v,
|
||||
isCompound: s,
|
||||
object: s === "dynamic"
|
||||
? makeNounSelection(info.dynamic.objComplement.entry as T.NounEntry, true)
|
||||
: undefined,
|
||||
dynAuxVerb: s === "dynamic"
|
||||
? { entry: info.dynamic.auxVerb } as T.VerbEntry
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export function changeTransitivity(v: T.VerbSelection, transitivity: "transitive" | "grammatically transitive"): T.VerbSelection {
|
||||
return {
|
||||
...v,
|
||||
transitivity,
|
||||
object: transitivity === "grammatically transitive" ? T.Person.ThirdPlurMale : undefined,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -550,13 +550,11 @@ export type VerbSelection = {
|
|||
dynAuxVerb?: VerbEntry,
|
||||
object: VerbObject, // TODO: should have a locked in (but number changeable noun) here for dynamic compounds
|
||||
transitivity: Transitivity,
|
||||
canChangeTransitivity: boolean,
|
||||
canChangeStatDyn: boolean,
|
||||
isCompound: "stative" | "dynamic" | false,
|
||||
voice: "active" | "passive",
|
||||
changeTransitivity?: (t: "transitive" | "grammatically transitive") => VerbSelection,
|
||||
changeStatDyn?: (t: "stative" | "dynamic") => VerbSelection,
|
||||
changeVoice?: (v: "active" | "passive", subj?: NPSelection) => VerbSelection,
|
||||
// TODO: changeStativeDynamic
|
||||
// TODO: add in aspect element here??
|
||||
canChangeVoice: boolean,
|
||||
negative: boolean,
|
||||
verbTense: VerbTense,
|
||||
perfectTense: PerfectTense,
|
||||
|
|
Loading…
Reference in New Issue