ability to prefer length on VPDisplay
This commit is contained in:
parent
21647b05b8
commit
eb55b43371
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@lingdocs/pashto-inflector",
|
"name": "@lingdocs/pashto-inflector",
|
||||||
"version": "3.1.9",
|
"version": "3.2.0",
|
||||||
"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,8 +1,8 @@
|
||||||
import { getShort } from "../lib/p-text-helpers";
|
import { getLength, getShort } from "../lib/p-text-helpers";
|
||||||
import * as T from "../types";
|
import * as T from "../types";
|
||||||
import Examples from "./Examples";
|
import Examples from "./Examples";
|
||||||
|
|
||||||
function CompiledPTextDisplay({ compiled, opts, justify, onlyOne }: {
|
function CompiledPTextDisplay({ compiled, opts, justify, onlyOne, length }: {
|
||||||
compiled: {
|
compiled: {
|
||||||
ps: T.SingleOrLengthOpts<T.PsString[]>;
|
ps: T.SingleOrLengthOpts<T.PsString[]>;
|
||||||
e?: string[] | undefined;
|
e?: string[] | undefined;
|
||||||
|
@ -10,22 +10,26 @@ function CompiledPTextDisplay({ compiled, opts, justify, onlyOne }: {
|
||||||
opts: T.TextOptions,
|
opts: T.TextOptions,
|
||||||
justify?: "left" | "right" | "center",
|
justify?: "left" | "right" | "center",
|
||||||
onlyOne?: boolean,
|
onlyOne?: boolean,
|
||||||
|
length?: "long" | "short",
|
||||||
}) {
|
}) {
|
||||||
function VariationLayer({ vs }: { vs: T.PsString[] }) {
|
function VariationLayer({ vs }: { vs: T.PsString[] }) {
|
||||||
return <div className="mb-2">
|
return <div className="mb-2">
|
||||||
<Examples opts={opts} lineHeight={0}>{vs}</Examples>
|
<Examples opts={opts} lineHeight={0}>{vs}</Examples>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
const ps = length
|
||||||
|
? getLength(compiled.ps, length)
|
||||||
|
: compiled.ps;
|
||||||
return <div className={justify === "left" ? "text-left" : justify === "right" ? "text-right" : "text-center"}>
|
return <div className={justify === "left" ? "text-left" : justify === "right" ? "text-right" : "text-center"}>
|
||||||
{onlyOne
|
{onlyOne
|
||||||
? <VariationLayer vs={[getShort(compiled.ps)[0]]} />
|
? <VariationLayer vs={[getShort(ps)[0]]} />
|
||||||
: "long" in compiled.ps ?
|
: "long" in ps ?
|
||||||
<div>
|
<div>
|
||||||
<VariationLayer vs={compiled.ps.long} />
|
<VariationLayer vs={ps.long} />
|
||||||
<VariationLayer vs={compiled.ps.short} />
|
<VariationLayer vs={ps.short} />
|
||||||
{compiled.ps.mini && <VariationLayer vs={compiled.ps.mini} />}
|
{ps.mini && <VariationLayer vs={ps.mini} />}
|
||||||
</div>
|
</div>
|
||||||
: <VariationLayer vs={compiled.ps} />
|
: <VariationLayer vs={ps} />
|
||||||
}
|
}
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,13 @@ import CompiledPTextDisplay from "../CompiledPTextDisplay";
|
||||||
import RenderedBlocksDisplay from "../RenderedBlocksDisplay";
|
import RenderedBlocksDisplay from "../RenderedBlocksDisplay";
|
||||||
import useStickyState from "../../lib/useStickyState";
|
import useStickyState from "../../lib/useStickyState";
|
||||||
|
|
||||||
function VPDisplay({ VPS, opts, setForm, justify, onlyOne }: {
|
function VPDisplay({ VPS, opts, setForm, justify, onlyOne, length }: {
|
||||||
VPS: T.VPSelectionState,
|
VPS: T.VPSelectionState,
|
||||||
opts: T.TextOptions,
|
opts: T.TextOptions,
|
||||||
setForm: "disable" | ((form: T.FormVersion) => void),
|
setForm: "disable" | ((form: T.FormVersion) => void),
|
||||||
justify?: "left" | "right" | "center",
|
justify?: "left" | "right" | "center",
|
||||||
onlyOne?: boolean | "concat",
|
onlyOne?: boolean | "concat",
|
||||||
|
length?: "long" | "short",
|
||||||
}) {
|
}) {
|
||||||
const [mode, setMode] = useState<Mode>("text");
|
const [mode, setMode] = useState<Mode>("text");
|
||||||
const [script, setScript] = useStickyState<"p" | "f">("f", "blockScriptChoice");
|
const [script, setScript] = useStickyState<"p" | "f">("f", "blockScriptChoice");
|
||||||
|
@ -45,7 +46,7 @@ function VPDisplay({ VPS, opts, setForm, justify, onlyOne }: {
|
||||||
{mode === "blocks" && <ScriptSelect value={script} onChange={setScript} />}
|
{mode === "blocks" && <ScriptSelect value={script} onChange={setScript} />}
|
||||||
</div>
|
</div>
|
||||||
{mode === "text"
|
{mode === "text"
|
||||||
? <CompiledPTextDisplay opts={opts} compiled={result} justify={justify} onlyOne={!!onlyOne} />
|
? <CompiledPTextDisplay opts={opts} compiled={result} justify={justify} onlyOne={!!onlyOne} length={length} />
|
||||||
: <RenderedBlocksDisplay opts={opts} rendered={rendered} justify={justify} script={script} />}
|
: <RenderedBlocksDisplay opts={opts} rendered={rendered} justify={justify} script={script} />}
|
||||||
{result.e && <div className={`text-muted mt-2 text-${justify === "left" ? "left" : justify === "right" ? "right" : "center"}`}>
|
{result.e && <div className={`text-muted mt-2 text-${justify === "left" ? "left" : justify === "right" ? "right" : "center"}`}>
|
||||||
{onlyOne === "concat"
|
{onlyOne === "concat"
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue