From e8ec806ecb687c01310e9d89efa12daf4eb834f1 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Fri, 20 May 2022 18:17:03 -0500 Subject: [PATCH] rough sandwich working --- package.json | 7 +- src/components/EntrySelect.tsx | 65 +++++++++++++ .../eq-comp-picker/EqCompPicker.tsx | 20 +++- src/components/np-picker/NPPronounPicker.tsx | 2 +- src/components/np-picker/SandwichPicker.tsx | 62 ++++++++++++ src/components/vp-explorer/VPDisplay.tsx | 2 +- src/components/vp-explorer/VPExplorer.tsx | 15 ++- src/components/vp-explorer/VPExplorerQuiz.tsx | 56 ++++++----- src/components/vp-explorer/verb-selection.ts | 32 +++--- src/components/vp-explorer/vps-reducer.ts | 53 +++++----- src/lib/phrase-building/np-tools.ts | 60 ++++++++++-- src/lib/phrase-building/render-ep.ts | 4 + src/lib/phrase-building/render-np.ts | 4 +- src/lib/phrase-building/render-sandwich.ts | 26 +++++ src/lib/phrase-building/render-vp.ts | 12 +-- src/lib/phrase-building/vp-tools.ts | 95 ++++++++++++------ src/lib/sandwiches.ts | 97 +++++++++++++++++++ src/lib/type-predicates.ts | 7 +- src/types.ts | 87 +++++++++++++---- 19 files changed, 552 insertions(+), 154 deletions(-) create mode 100644 src/components/np-picker/SandwichPicker.tsx create mode 100644 src/lib/phrase-building/render-sandwich.ts create mode 100644 src/lib/sandwiches.ts diff --git a/package.json b/package.json index 3b894d2..1f5d7ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lingdocs/pashto-inflector", - "version": "2.5.5", + "version": "2.5.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", @@ -76,7 +76,10 @@ "extends": [ "react-app", "react-app/jest" - ] + ], + "rules": { + "no-warning-comments": [1, {"terms": ["fixme", "xxx"], "location": "anywhere"}] + } }, "browserslist": { "production": [ diff --git a/src/components/EntrySelect.tsx b/src/components/EntrySelect.tsx index 6a4f044..5717923 100644 --- a/src/components/EntrySelect.tsx +++ b/src/components/EntrySelect.tsx @@ -111,4 +111,69 @@ function EntrySelect(props: { } +export function SandwichSelect(props: { + sandwiches: E[], + value: E | undefined, + onChange: (value: E | undefined) => void, + name: string | undefined, + opts: T.TextOptions, + style?: StyleHTMLAttributes, +}) { + const divStyle = props.style || { width: "13rem" }; + const placeholder = "Select Sandwich…"; + const value = props.value ? makeSandwichOption(props.value) : undefined; + const options = props.sandwiches + // .sort((a, b) => { + // if ("entry" in a) { + // return a.before.p.localeCompare("p" in b ? b.p : b.entry.p, "af-PS") + // } + // return a.p.localeCompare("p" in b ? b.p : b.entry.p, "af-PS"); + // }) + .map(makeSandwichOption); + const onChange = (v: { label: string | JSX.Element, value: string } | null) => { + if (!v) { + props.onChange(undefined); + return; + } + const s = props.sandwiches.find(e => { + const sValue = JSON.parse(v.value) as T.Sandwich; + if (sValue.type !== "sandwich") throw new Error("error converting selected sandwich value to a sandwich"); + return sandwichSideEq(e.before, sValue.before) + && sandwichSideEq(e.after, sValue.after) + && (e.e === sValue.e); + }); + if (!s) return; + props.onChange(s); + } + return
+