ability to show demonstratives without nouns

This commit is contained in:
adueck 2024-07-31 14:36:06 -04:00
parent 1a6cc6723c
commit 49f6bd7ed2
10 changed files with 199 additions and 137 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "7.3.1", "version": "7.3.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "7.3.1", "version": "7.3.2",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "pashto-inflector", "name": "pashto-inflector",
"version": "7.3.1", "version": "7.3.2",
"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",

View File

@ -1,12 +1,12 @@
{ {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "7.3.1", "version": "7.3.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "7.3.1", "version": "7.3.2",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@formkit/auto-animate": "^1.0.0-beta.3", "@formkit/auto-animate": "^1.0.0-beta.3",

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/ps-react", "name": "@lingdocs/ps-react",
"version": "7.3.1", "version": "7.3.2",
"description": "Pashto inflector library module with React components", "description": "Pashto inflector library module with React components",
"main": "dist/components/library.js", "main": "dist/components/library.js",
"module": "dist/components/library.js", "module": "dist/components/library.js",

View File

@ -663,6 +663,8 @@ export function NPBlock({
np.selection.possesor && np.selection.possesor &&
!np.selection.possesor.shrunken !np.selection.possesor.shrunken
); );
const demWithoutNoun =
np.selection.demonstrative && !np.selection.demonstrative.withNoun;
const elements = [ const elements = [
...(!inside ...(!inside
? [ ? [
@ -676,10 +678,21 @@ export function NPBlock({
<Demonstrative opts={opts} script={script}> <Demonstrative opts={opts} script={script}>
{np.selection.demonstrative ? np.selection.demonstrative : undefined} {np.selection.demonstrative ? np.selection.demonstrative : undefined}
</Demonstrative>, </Demonstrative>,
<div
style={{
opacity: demWithoutNoun ? 0.5 : 1,
}}
>
<Adjectives opts={opts} script={script}> <Adjectives opts={opts} script={script}>
{np.selection.adjectives} {np.selection.adjectives}
</Adjectives>, </Adjectives>
<div className={np.selection.adjectives?.length ? "mx-1" : ""}> </div>,
<div
style={{
opacity: demWithoutNoun ? 0.5 : 1,
}}
className={np.selection.adjectives?.length ? "mx-1" : ""}
>
{" "} {" "}
{flattenLengths(np.selection.ps)[0][script]} {flattenLengths(np.selection.ps)[0][script]}
</div>, </div>,

View File

@ -13,7 +13,7 @@ export default function DemonstrativePicker({
onChange({ onChange({
type: "demonstrative", type: "demonstrative",
demonstrative: d, demonstrative: d,
hideNoun: false, withNoun: true,
}); });
} else { } else {
onChange({ onChange({
@ -22,7 +22,16 @@ export default function DemonstrativePicker({
}); });
} }
} }
function handleWithNounChange(e: React.ChangeEvent<HTMLInputElement>) {
if (demonstrative) {
onChange({
...demonstrative,
withNoun: e.target.checked,
});
}
}
return ( return (
<div>
<div className="d-flex flex-row justify-content-around py-1"> <div className="d-flex flex-row justify-content-around py-1">
<div> <div>
<button <button
@ -55,5 +64,24 @@ export default function DemonstrativePicker({
</button> </button>
</div> </div>
</div> </div>
<div
className="form-check"
style={{
opacity: demonstrative ? 1 : 0.5,
}}
>
<input
className="form-check-input"
type="checkbox"
checked={demonstrative?.withNoun}
onChange={handleWithNounChange}
id="withNoun"
disabled={!demonstrative}
/>
<label className="form-check-label text-muted" htmlFor="withNoun">
with noun
</label>
</div>
</div>
); );
} }

View File

@ -99,7 +99,12 @@ function NPNounPicker(props: {
} }
} }
return ( return (
<div style={{ maxWidth: "225px", minWidth: "125px" }}> <div
style={{
maxWidth: "225px",
minWidth: "125px",
}}
>
{!addingDemonstrative && !props.noun?.demonstrative ? ( {!addingDemonstrative && !props.noun?.demonstrative ? (
<div> <div>
<span <span
@ -143,6 +148,14 @@ function NPNounPicker(props: {
handleChange={setPatternFilter} handleChange={setPatternFilter}
/> />
</div>} */} </div>} */}
<div
style={{
opacity:
props.noun?.demonstrative && !props.noun.demonstrative.withNoun
? 0.5
: 1,
}}
>
{props.noun && ( {props.noun && (
<AdjectiveManager <AdjectiveManager
phraseIsComplete={props.phraseIsComplete} phraseIsComplete={props.phraseIsComplete}
@ -236,6 +249,7 @@ function NPNounPicker(props: {
</div> </div>
)} )}
</div> </div>
</div>
); );
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@lingdocs/inflect", "name": "@lingdocs/inflect",
"version": "7.3.1", "version": "7.3.2",
"description": "Pashto inflector library", "description": "Pashto inflector library",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/lib/library.d.ts", "types": "dist/lib/library.d.ts",

View File

@ -12,16 +12,22 @@ function getBaseAndAdjectives({
return getSandwichPsBaseAndAdjectives(selection); return getSandwichPsBaseAndAdjectives(selection);
} }
const adjs = "adjectives" in selection && selection.adjectives; const adjs = "adjectives" in selection && selection.adjectives;
const demons = ("demonstrative" in selection && const demonstrativePs = ("demonstrative" in selection &&
selection.demonstrative?.ps) || { p: "", f: "" }; selection.demonstrative?.ps) || { p: "", f: "" };
if (!adjs) { if (!adjs) {
// TODO: does this ever get used?? // TODO: does this ever get used??
return flattenLengths(selection.ps).map((x) => concatPsString(demons, x)); return flattenLengths(selection.ps).map((x) =>
concatPsString(demonstrativePs, x)
);
}
if (selection.demonstrative && !selection.demonstrative.withNoun) {
return [demonstrativePs];
} }
return flattenLengths(selection.ps).map((p) => return flattenLengths(selection.ps).map((p) =>
concatPsString( concatPsString(
demons, demonstrativePs,
// demons ? " " : "", // demons ? " " : "",
adjs.reduce( adjs.reduce(
(accum, curr) => { (accum, curr) => {
@ -207,9 +213,10 @@ function addArticlesAndAdjs(
: " (m.)" : " (m.)"
: ""; : "";
const demonstrative = np.demonstrative ? ` ${np.demonstrative.e}` : ""; const demonstrative = np.demonstrative ? ` ${np.demonstrative.e}` : "";
return `${ const demWithoutNoun = np.demonstrative && !np.demonstrative.withNoun;
np.demonstrative ? "" : articles return `${np.demonstrative ? "" : articles}${demonstrative}${
}${demonstrative}${adjs}${word}${genderTag}`; demWithoutNoun ? ` (${(adjs + word).trim()})` : adjs + word
}${genderTag}`;
} catch (e) { } catch (e) {
return undefined; return undefined;
} }

View File

@ -905,7 +905,7 @@ export type NounSelection = {
export type DemonstrativeSelection = { export type DemonstrativeSelection = {
type: "demonstrative"; type: "demonstrative";
demonstrative: "daa" | "hagha" | "dagha"; demonstrative: "daa" | "hagha" | "dagha";
hideNoun: boolean; withNoun: boolean;
}; };
export type AdverbSelection = { export type AdverbSelection = {
@ -1024,7 +1024,7 @@ export type Rendered<
? { ? {
type: "demonstrative"; type: "demonstrative";
demonstrative: DemonstrativeSelection["demonstrative"]; demonstrative: DemonstrativeSelection["demonstrative"];
hideNoun: boolean; withNoun: boolean;
ps: PsString; ps: PsString;
e: string; e: string;
} }