Skip to content

Commit

Permalink
added demonstrative pronouns
Browse files Browse the repository at this point in the history
  • Loading branch information
adueck committed Jul 28, 2024
1 parent 46fd6e6 commit 453216e
Show file tree
Hide file tree
Showing 18 changed files with 982 additions and 750 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pashto-inflector",
"version": "7.2.2",
"version": "7.3.0",
"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",
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Hider from "./components/src/Hider";
import InflectionDemo from "./demo-components/InflectionDemo";
import SpellingDemo from "./demo-components/SpellingDemo";
import ParserDemo from "./demo-components/ParserDemo";
import InflectionTable from "./components/src/InflectionsTable";
// import InflectionTable from "./components/src/InflectionsTable";

function App() {
const [showingTextOptions, setShowingTextOptions] = useStickyState<boolean>(
Expand Down
4 changes: 2 additions & 2 deletions src/components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lingdocs/ps-react",
"version": "7.2.2",
"version": "7.3.0",
"description": "Pashto inflector library module with React components",
"main": "dist/components/library.js",
"module": "dist/components/library.js",
Expand Down
36 changes: 33 additions & 3 deletions src/components/src/blocks/Block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,27 @@ function Sandwich({
);
}

function Demonstrative({
opts,
script,
children,
}: {
opts: T.TextOptions;
script: "p" | "f";
children: T.Rendered<T.DemonstrativeSelection> | undefined;
}) {
if (!children) {
return null;
}
return (
<div className="text-center">
<Border padding={"1rem"}>{children.ps[script]}</Border>
<div>DEM</div>
<SubText>{children.e}</SubText>
</div>
);
}

function CompNounBlock({
opts,
noun,
Expand All @@ -612,7 +633,7 @@ function CompNounBlock({
return (
<div className="text-center">
<Border
extraClassName={`!inside && hasPossesor ? "pt-2" : ""`}
// extraClassName={`${!inside && hasPossesor} ? "pt-2" : ""`}
padding={"1rem"}
>
{flattenLengths(noun.ps)[0][script]}
Expand Down Expand Up @@ -652,19 +673,25 @@ export function NPBlock({
</Possesors>,
]
: []),
<Demonstrative opts={opts} script={script}>
{np.selection.demonstrative ? np.selection.demonstrative : undefined}
</Demonstrative>,
<Adjectives opts={opts} script={script}>
{np.selection.adjectives}
</Adjectives>,
<div className={np.selection.adjectives?.length ? "mx-1" : ""}>
{" "}
{flattenLengths(np.selection.ps)[0][script]}
</div>,
];
].filter((x) => {
// @ts-ignore
return x !== " ";
});
const el = script === "p" ? elements.reverse() : elements;
return (
<div className="text-center">
<Border
extraClassName={`!inside && hasPossesor ? "pt-2" : ""`}
// extraClassName={`!inside && hasPossesor ? "pt-2" : ""`}
padding={
inside
? "0.3rem"
Expand Down Expand Up @@ -759,6 +786,9 @@ function Adjectives({
return null;
}
const c = script === "p" ? children.reverse() : children;
if (c.length === 0) {
return null;
}
return (
<em className="mr-1">
{c.map((a) => a.ps[0][script]).join(" ")}
Expand Down
219 changes: 82 additions & 137 deletions src/components/src/np-picker/AdjectiveManager.tsx
Original file line number Diff line number Diff line change
@@ -1,153 +1,98 @@
import * as T from "../../../types";
import { useState } from "react";
import AdjectivePicker from "./AdjectivePicker";
import classNames from "classnames";

function AdjectiveManager(props: {
adjectives: T.AdjectiveSelection[],
entryFeeder: T.EntryFeeder,
opts: T.TextOptions,
demonstrative: T.NounSelection["demonstrative"],
onChange: (adjs: T.AdjectiveSelection[]) => void,
onDemonstrativeChange: (dem: T.NounSelection["demonstrative"]) => void,
phraseIsComplete: boolean,
adjectives: T.AdjectiveSelection[];
entryFeeder: T.EntryFeeder;
opts: T.TextOptions;
onChange: (adjs: T.AdjectiveSelection[]) => void;
phraseIsComplete: boolean;
}) {
const [adding, setAdding] = useState<boolean>(false);
const [addingDemonstrative, setAddingDemonstrative] = useState<boolean>(false);
function handleChange(i: number) {
return (a: T.AdjectiveSelection | undefined) => {
if (a === undefined) return;
const updated = [...props.adjectives];
updated[i] = a;
props.onChange(
updated.filter((x): x is T.AdjectiveSelection => !!x)
);
};
}
function deleteAdj(i: number) {
return () => {
props.onChange(remove(props.adjectives, i));
};
}
function handleAddNew(a: T.AdjectiveSelection | undefined) {
if (a === undefined) return;
setAdding(false);
props.onChange([
a,
...props.adjectives,
]);
}
// const flippedList = [...props.adjectives];
// flippedList.reverse();
// console.log(props.adjectives);
return <div className="mb-1">
{adding && <div>
<div className="d-flex flex-row justify-content-between mb-1">
<div>Add Adjective</div>
<div className="clickable" onClick={() => setAdding(false)}>
<i className="fas fa-trash" />
</div>
</div>
<AdjectivePicker
phraseIsComplete={props.phraseIsComplete}
noTitle
adjective={undefined}
entryFeeder={props.entryFeeder}
opts={props.opts}
onChange={handleAddNew}
/>
</div>}
{addingDemonstrative && <div>
<div className="d-flex flex-row justify-content-between mb-1">
<div>Add Demonstrative</div>
<div className="clickable" onClick={() => {
setAddingDemonstrative(false);
props.onDemonstrativeChange(undefined);
}}>
<i className="fas fa-trash" />
</div>
const [adding, setAdding] = useState<boolean>(false);
function handleChange(i: number) {
return (a: T.AdjectiveSelection | undefined) => {
if (a === undefined) return;
const updated = [...props.adjectives];
updated[i] = a;
props.onChange(updated.filter((x): x is T.AdjectiveSelection => !!x));
};
}
function deleteAdj(i: number) {
return () => {
props.onChange(remove(props.adjectives, i));
};
}
function handleAddNew(a: T.AdjectiveSelection | undefined) {
if (a === undefined) return;
setAdding(false);
props.onChange([a, ...props.adjectives]);
}
// const flippedList = [...props.adjectives];
// flippedList.reverse();
// console.log(props.adjectives);
return (
<div className="mb-1">
{adding && (
<div>
<div className="d-flex flex-row justify-content-between mb-1">
<div>Add Adjective</div>
<div className="clickable" onClick={() => setAdding(false)}>
<i className="fas fa-trash" />
</div>
<DemonstrativePicker
demonstrative={props.demonstrative}
onChange={props.onDemonstrativeChange}
/>
</div>}
{props.adjectives.map((adj, i) => <div key={i}>
<div className="d-flex flex-row justify-content-between">
<div>Adjective</div>
<div className="d-flex flex-row align-items-baseline">
{!!props.adjectives.length && !adding && <div>
<div className="clickable h6" onClick={() => setAdding(true)}>+ Adj.</div>
</div>}
<div onClick={deleteAdj(i)} className="ml-4">
<div className="fas fa-trash" />
</div>
</div>
<AdjectivePicker
phraseIsComplete={props.phraseIsComplete}
noTitle
adjective={undefined}
entryFeeder={props.entryFeeder}
opts={props.opts}
onChange={handleAddNew}
/>
</div>
)}

{props.adjectives.map((adj, i) => (
<div key={i}>
<div className="d-flex flex-row justify-content-between">
<div>Adjective</div>
<div className="d-flex flex-row align-items-baseline">
{!!props.adjectives.length && !adding && (
<div>
<div className="clickable h6" onClick={() => setAdding(true)}>
+ Adj.
</div>
</div>
)}
<div onClick={deleteAdj(i)} className="ml-4">
<div className="fas fa-trash" />
</div>
</div>
<AdjectivePicker
phraseIsComplete={props.phraseIsComplete}
noTitle
key={`adj${i}`}
adjective={adj}
entryFeeder={props.entryFeeder}
opts={props.opts}
onChange={handleChange(i)}
/>
</div>)}
{!adding && !props.adjectives.length && <div className="h6 clickable" style={{ float: "right" }}>
<div className="clickable" onClick={() => setAdding(true)}>+ Adj.</div>
</div>}
{/* {!addingDemonstrative && !props.demonstrative && <h6 className="clickable mr-2" style={{ float: "right" }}>
<div className="clickable" onClick={() => setAddingDemonstrative(true)}>+ Demons.</div>
</h6>} */}
</div>;
}

function DemonstrativePicker({ demonstrative, onChange }: {
demonstrative: T.NounSelection["demonstrative"],
onChange: (dem: T.NounSelection["demonstrative"]) => void,
}) {
function handleDChange(d: "daa" | "hagha" | "dagha") {
if (!demonstrative) {
onChange({
type: "demonstrative",
demonstrative: d,
hideNoun: false,
});
} else {
onChange({
...demonstrative,
demonstrative: d,
});
}
}
return <div className="d-flex flex-row justify-content-around py-1">
<div>
<button
className={classNames("btn", "btn-outline-secondary", { active: demonstrative?.demonstrative === "daa" })}
onClick={() => handleDChange("daa")}
>دا</button>
</div>
<AdjectivePicker
phraseIsComplete={props.phraseIsComplete}
noTitle
key={`adj${i}`}
adjective={adj}
entryFeeder={props.entryFeeder}
opts={props.opts}
onChange={handleChange(i)}
/>
</div>
<div>
<button
className={classNames("btn", "btn-outline-secondary", { active: demonstrative?.demonstrative === "hagha" })}
onClick={() => handleDChange("hagha")}
>هغه</button>
</div>
<div>
<button
className={classNames("btn", "btn-outline-secondary", { active: demonstrative?.demonstrative === "dagha" })}
onClick={() => handleDChange("dagha")}
>دغه</button>
))}
{!adding && !props.adjectives.length && (
<div className="h6 clickable" style={{ float: "right" }}>
<div className="clickable" onClick={() => setAdding(true)}>
+ Adj.
</div>
</div>
</div>;
)}
</div>
);
}

function remove<X>(arr: X[], i: number): X[] {
return [
...arr.slice(0, i),
...arr.slice(i + 1),
];
return [...arr.slice(0, i), ...arr.slice(i + 1)];
}

export default AdjectiveManager;
export default AdjectiveManager;
Loading

0 comments on commit 453216e

Please sign in to comment.