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