diff --git a/src/components/equative-explorer/EquativeDisplay.tsx b/src/components/equative-explorer/EquativeDisplay.tsx index fec3a4f..e76a7b5 100644 --- a/src/components/equative-explorer/EquativeDisplay.tsx +++ b/src/components/equative-explorer/EquativeDisplay.tsx @@ -11,9 +11,9 @@ import { import { equativeMachine, assembleEquativeOutput, - NounInput, + SubjectInput, } from "../../lib/equative-machine"; -import { isPluralEntry, isSingularEntry } from "../../lib/type-predicates"; +import { isNoun, isPluralEntry } from "../../lib/type-predicates"; function EquativeDisplay({ state }: { state: ExplorerState }) { if (state.subjectType === "pronouns") { @@ -23,18 +23,14 @@ function EquativeDisplay({ state }: { state: ExplorerState }) { /> } const entry = state.subjectsSelected[state.subjectType]; - const nounInput: NounInput = isSingularEntry(entry) ? { + // @ts-ignore - TODO: safer and for use with unisex nouns + const subjInput: SubjectInput = isNoun(entry) ? { entry, - plural: state.subjectsSelected.info.plural, - } : isPluralEntry(entry) ? { - entry, - plural: true, - } : { - entry: entry as SingularEntry, - plural: state.subjectsSelected.info.plural, - }; + plural: isPluralEntry(entry) ? true : state.subjectsSelected.info.plural, + } : entry; + const eq = assembleEquativeOutput( - equativeMachine(nounInput, state.predicatesSelected[state.predicateType]) + equativeMachine(subjInput, state.predicatesSelected[state.predicateType]) ); if ("short" in eq) return
length options not supported yet
; return
diff --git a/src/components/equative-explorer/EquativeExplorer.tsx b/src/components/equative-explorer/EquativeExplorer.tsx index 53b881f..4b8bfcf 100644 --- a/src/components/equative-explorer/EquativeExplorer.tsx +++ b/src/components/equative-explorer/EquativeExplorer.tsx @@ -14,6 +14,7 @@ import { defaultUnisexNoun, defaultAdjective, defaultNoun, + defaultParticiple, } from "./explorer-inputs"; import EquativeDisplay from "./EquativeDisplay"; @@ -26,6 +27,7 @@ const defaultState: ExplorerState = { }, subjectsSelected: { noun: defaultNoun, + participle: defaultParticiple, info: { plural: false, gender: "masc", diff --git a/src/components/equative-explorer/explorer-helpers.ts b/src/components/equative-explorer/explorer-helpers.ts index 5ab7022..efd7dfc 100644 --- a/src/components/equative-explorer/explorer-helpers.ts +++ b/src/components/equative-explorer/explorer-helpers.ts @@ -6,10 +6,13 @@ import { import { equativeMachine, assembleEquativeOutput, + ParticipleInput, + isParticipleInput, + getEnglishParticiple, } from "../../lib/equative-machine"; -export function sort(arr: T[]): T[] { - return arr.sort((a, b) => a.p.localeCompare(b.p)); +export function sort(arr: Readonly): T[] { + return [...arr].sort((a, b) => a.p.localeCompare(b.p)); } export function makeBlockWPronouns(e: Adjective | UnisexNoun): T.VerbBlock { @@ -28,7 +31,7 @@ export function makeBlockWPronouns(e: Adjective | UnisexNoun): T.VerbBlock { } export function makeOptionLabel(e: T.DictionaryEntry): string { - const eng = getEnglishWord(e); + const eng = (isParticipleInput(e)) ? getEnglishParticiple(e) : getEnglishWord(e); const english = typeof eng === "string" ? eng : !eng diff --git a/src/components/equative-explorer/explorer-inputs.ts b/src/components/equative-explorer/explorer-inputs.ts index 232f881..256cdb8 100644 --- a/src/components/equative-explorer/explorer-inputs.ts +++ b/src/components/equative-explorer/explorer-inputs.ts @@ -1,20 +1,27 @@ -import { nouns, adjectives } from "../../words/words"; +import { nouns, adjectives, verbs } from "../../words/words"; import { isUnisexNoun, } from "../../lib/type-predicates"; import { sort } from "./explorer-helpers"; +import { + ParticipleInput, +} from "../../lib/equative-machine"; const unisexNouns = nouns.filter(x => isUnisexNoun(x)) as UnisexNoun[]; const nonUnisexNouns = nouns.filter(x => !isUnisexNoun(x)) as (MascNoun | FemNoun)[]; + const inputs = { adjective: sort(adjectives), unisexNoun: sort(unisexNouns), noun: sort(nonUnisexNouns), + // @ts-ignore + participle: sort(verbs.map(e => e.entry) as ParticipleInput[]), }; -export const defaultAdjective = inputs.adjective.find(ps => ps.p === "ستړی") || inputs.adjective[0]; +export const defaultAdjective = inputs.adjective.find(ps => ps.p === "زوړ") || inputs.adjective[0]; export const defaultUnisexNoun = inputs.unisexNoun.find(ps => ps.p === "پښتون") || inputs.unisexNoun[0]; export const defaultNoun = inputs.noun.find(ps => ps.p === "کتاب") || inputs.noun[0]; +export const defaultParticiple = inputs.participle.find(ps => ps.p === "لیکل") || inputs.participle[0]; export default inputs; \ No newline at end of file diff --git a/src/components/equative-explorer/explorer-reducer.ts b/src/components/equative-explorer/explorer-reducer.ts index c6a8229..f7b26b9 100644 --- a/src/components/equative-explorer/explorer-reducer.ts +++ b/src/components/equative-explorer/explorer-reducer.ts @@ -31,6 +31,7 @@ export function reducer(state: ExplorerState, action: ExplorerReducerAction): Ex if (action.type === "setSubject") { if (state.subjectType === "pronouns") return state; const pile = inputs[state.subjectType]; + // @ts-ignore const subject = (pile.find(p => p.ts === action.payload) || pile[0]); return { ...state, diff --git a/src/components/equative-explorer/explorer-selectors.tsx b/src/components/equative-explorer/explorer-selectors.tsx index 8396ab8..93fd5ac 100644 --- a/src/components/equative-explorer/explorer-selectors.tsx +++ b/src/components/equative-explorer/explorer-selectors.tsx @@ -12,6 +12,98 @@ import { import { isPluralEntry } from "../../lib/type-predicates"; import Select from "react-select"; +export function SubjectSelector({ state, dispatch }: { + state: ExplorerState, + dispatch: (action: ExplorerReducerAction) => void, +}) { + function onTypeSelect(e: React.ChangeEvent) { + const t = e.target.value as SubjectType; + dispatch({ type: "setSubjectType", payload: t }); + } + function onSubjectSelect({ value }: any) { + dispatch({ type: "setSubject", payload: parseInt(value) }); + } + const pluralNounSelected = ( + state.subjectType === "noun" && isPluralEntry(state.subjectsSelected.noun) + ); + const options = state.subjectType === "pronouns" + ? [] + : inputs[state.subjectType].map(e => ({ + value: e.ts.toString(), + label: makeOptionLabel(e), + })); + const subject = state.subjectType === "pronouns" + ? undefined + : state.subjectsSelected[state.subjectType]; + return
+ +
+ + +
+
+ + +
+
+ + +
+ {state.subjectType !== "pronouns" && + <> + - -
-
- - -
- {state.subjectType !== "pronouns" && - <> -