From 7e3d64438005be4360e429ef73bbf1d6d330b20f Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Thu, 26 May 2022 15:44:05 -0500 Subject: [PATCH] better --- package.json | 3 +- src/components/NPPlayground.tsx | 32 --------- .../phrase-diagram/EditablePhraseDiagram.tsx | 70 ++++++++++++++++--- .../phrase-diagram/PhraseDiagram.tsx | 45 +++++++++++- src/content/index.ts | 6 ++ src/content/phrase-structure/ap.mdx | 46 +++++++++++- src/content/phrase-structure/np.mdx | 6 +- src/types/gramm-types.d.ts | 8 ++- yarn.lock | 14 ++-- 9 files changed, 170 insertions(+), 60 deletions(-) delete mode 100644 src/components/NPPlayground.tsx diff --git a/package.json b/package.json index b9121bb..443c430 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,10 @@ "version": "0.1.0", "private": true, "dependencies": { + "@formkit/auto-animate": "^1.0.0-beta.1", "@fortawesome/fontawesome-free": "^5.15.4", "@lingdocs/lingdocs-main": "^0.3.1", - "@lingdocs/pashto-inflector": "^2.6.2", + "@lingdocs/pashto-inflector": "^2.6.4", "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", diff --git a/src/components/NPPlayground.tsx b/src/components/NPPlayground.tsx deleted file mode 100644 index 3020628..0000000 --- a/src/components/NPPlayground.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import { - Types as T, - NPPicker, -} from "@lingdocs/pashto-inflector"; -import { useState } from "react"; -import PhraseDiagram from "./phrase-diagram/PhraseDiagram"; -import entryFeeder from "../lib/entry-feeder"; - -function NPPlayground({ opts, npIn }: { - opts: T.TextOptions, - npIn: T.NPSelection | undefined, -}) { - const [np, setNp] = useState(npIn); - return
-
- -
- {np && {[ - { type: "NP", block: np }, - ]}} -
-} - -export default NPPlayground; \ No newline at end of file diff --git a/src/components/phrase-diagram/EditablePhraseDiagram.tsx b/src/components/phrase-diagram/EditablePhraseDiagram.tsx index 57a7caf..f066543 100644 --- a/src/components/phrase-diagram/EditablePhraseDiagram.tsx +++ b/src/components/phrase-diagram/EditablePhraseDiagram.tsx @@ -1,9 +1,16 @@ import { Types as T, + NPPicker, + APPicker, } from "@lingdocs/pashto-inflector"; +import { + useEffect, + useRef, +} from "react"; import { useState } from "react"; import PhraseDiagram from "./PhraseDiagram"; -import NPPlayground from "../NPPlayground"; +import entryFeeder from "../../lib/entry-feeder"; +import autoAnimate from "@formkit/auto-animate"; export function EditIcon() { return ; @@ -13,19 +20,64 @@ function EditablePhraseDiagram({ opts, children }: { opts: T.TextOptions, children: BlockInput[], }) { - const np = children[0].block; + const block = children[0]; + const parent = useRef(null); + useEffect(() => { + parent.current && autoAnimate(parent.current) + }, [parent]); const [editing, setEditing] = useState(false); + const [edited, setEdited] = useState<{ + type: "NP", + block: T.NPSelection | undefined, + } | { + type: "AP", + block: T.APSelection | undefined, + }>(block); if (children.length === 0) return null; + function handleNPChange(np: T.NPSelection | undefined) { + setEdited({ type: "NP", block: np }); + } + function handleAPChange(ap: T.APSelection | undefined) { + setEdited({ type: "AP", block: ap }); + } + function handleReset() { + setEdited(block); + setEditing(false); + } return
-
setEditing(e => !e)}> +
setEditing(true)} + > {!editing ? : }
-
- {editing - ? - : {[ - { type: "NP", block: np }, - ]}} +
+ {editing &&
+ {edited.type === "NP" + ? + : null} + /> + } +
} + {edited.block + && + {[edited] as BlockInput[]} + }
; } diff --git a/src/components/phrase-diagram/PhraseDiagram.tsx b/src/components/phrase-diagram/PhraseDiagram.tsx index f3b7d1c..2cecf52 100644 --- a/src/components/phrase-diagram/PhraseDiagram.tsx +++ b/src/components/phrase-diagram/PhraseDiagram.tsx @@ -2,6 +2,7 @@ import { renderNPSelection, Types as T, getEnglishFromRendered, + renderAPSelection, } from "@lingdocs/pashto-inflector"; import classNames from "classnames"; @@ -22,11 +23,49 @@ function Block({ opts, children }: { opts: T.TextOptions, children: BlockInput, }) { - // const possesor = children.block.possesor; - const rendered = renderNPSelection(children.block, false, false, "subject", "none"); + if (children.type === "NP") { + const rendered = renderNPSelection(children.block, false, false, "subject", "none"); + const english = getEnglishFromRendered(rendered) + return
+ {rendered} +
; + } + const rendered = renderAPSelection(children.block); const english = getEnglishFromRendered(rendered) return
- {rendered} + {rendered} +
; +} + +function AP({ opts, children, english }: { + opts: T.TextOptions, + children: T.Rendered, + english?: string, +}) { + const ap = children; + if (ap.type === "adverb") { + return
+
+ {ap.ps[0].f} +
+
AP
+ {english &&
{english}
} +
; + } + return
+ Will implement sandwich
; } diff --git a/src/content/index.ts b/src/content/index.ts index a322a91..aa1bd01 100644 --- a/src/content/index.ts +++ b/src/content/index.ts @@ -21,6 +21,8 @@ import * as equativeExplorer from "!babel-loader!@lingdocs/mdx-loader!./equative // @ts-ignore import * as NPIntro from "!babel-loader!@lingdocs/mdx-loader!./phrase-structure/np.mdx"; +// @ts-ignore +import * as APIntro from "!babel-loader!@lingdocs/mdx-loader!./phrase-structure/ap.mdx"; // @ts-ignore import * as nounsGender from "!babel-loader!@lingdocs/mdx-loader!./nouns/nouns-gender.mdx"; @@ -105,6 +107,10 @@ const contentTree = [ import: NPIntro, slug: "np", }, + { + import: APIntro, + slug: "ap", + }, ], }, { diff --git a/src/content/phrase-structure/ap.mdx b/src/content/phrase-structure/ap.mdx index 7b71eff..e171ee6 100644 --- a/src/content/phrase-structure/ap.mdx +++ b/src/content/phrase-structure/ap.mdx @@ -2,4 +2,48 @@ title: APs --- -AP page here \ No newline at end of file +import { + defaultTextOptions as opts, + InlinePs, + Examples, +} from "@lingdocs/pashto-inflector"; +import psmd from "../../lib/psmd"; +import Link from "../../components/Link"; +import EditablePhraseDiagram, { + EditIcon, +} from "../../components/phrase-diagram/EditablePhraseDiagram"; + +Another building block we have in Pashto phrases in the **AP (Adverb Phrase)**. Adverb Phrases are used to give more information about the phrase in terms of time, manner, place, degree, etc. + +An AP is either: + +- an adverb, or +- a sandwich + +### Adverb + +An adverb is a word or expression that modifies the time, manner, place, etc. of a phrase. + +{[ + { + type: "AP", + block: { + type: "adverb", + entry: {"ts":1527815160,"i":2394,"p":"پرون","f":"paroon","g":"paroon","e":"yesterday","c":"adv."}, + }, + }, +]} + +{[ + { + type: "AP", + block: { + type: "adverb", + entry: {"ts":1527819967,"i":5428,"p":"خامخا","f":"khaamakhaa","g":"khaamakhaa","e":"definitely, for sure, whether someone wants or not, willy-nilly (this last use more in Urdu)","c":"adv."}, + }, + }, +]} + +### Sandwich + +Coming soon... \ No newline at end of file diff --git a/src/content/phrase-structure/np.mdx b/src/content/phrase-structure/np.mdx index fd479e5..6231419 100644 --- a/src/content/phrase-structure/np.mdx +++ b/src/content/phrase-structure/np.mdx @@ -12,7 +12,7 @@ import Link from "../../components/Link"; import EditablePhraseDiagram, { EditIcon, } from "../../components/phrase-diagram/EditablePhraseDiagram"; -import NPPlayground from "../../components/NPPlayground"; +// import NPPlayground from "../../components/NPPlayground"; Pashto phrases are built with a basic **building blocks** 🧱 like NPs, APs, verbs, and equatives. We can think of phrases in Pashto as a line of blocks like this: @@ -409,8 +409,8 @@ An **NP** is one of the following: Notice how NPs can contain other NPs, and therefore go on foreeeever. So you could have like 50 words packed together and it would all be **one single NP**, **one building block** in a sentence. -## NP Playground + diff --git a/src/types/gramm-types.d.ts b/src/types/gramm-types.d.ts index 6623489..36ee08d 100644 --- a/src/types/gramm-types.d.ts +++ b/src/types/gramm-types.d.ts @@ -4,4 +4,10 @@ type Pronoun = { person: import("@lingdocs/pashto-inflector").Types.Person, }; -type BlockInput = { type: "NP", block: T.NPSelection }; +type BlockInput = { + type: "NP", + block: import("@lingdocs/pashto-inflector").Types.NPSelection, +} | { + type: "AP", + block: import("@lingdocs/pashto-inflector").Types.APSelection, +}; diff --git a/yarn.lock b/yarn.lock index 59af69d..963c743 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1695,13 +1695,12 @@ rambda "^6.7.0" react-select "^5.2.2" -"@lingdocs/pashto-inflector@^2.6.2": - version "2.6.2" - resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-2.6.2.tgz#41c6a18a67aa9dff8ade2fd49ad8b27d04ecb4f8" - integrity sha512-GSiJ7FFoDEDIfDcPv10SienHYQr/8lRmBP6fbwDV2vFVf9vJ4+nywuhFmU0JuBL2HILG/e6CQ3tvQZvoquopCg== +"@lingdocs/pashto-inflector@^2.6.4": + version "2.6.5" + resolved "https://npm.lingdocs.com/@lingdocs%2fpashto-inflector/-/pashto-inflector-2.6.5.tgz#9cd8efd14d48d0a9aa9ff8439b2bdc135a855f57" + integrity sha512-y1prO4ASg1P2v5960twoYD2NOfN4P6vc9cM2/QqMIHQX7TkXwzFnjKKu9MD3dCOH0FPOv1V6NAEgbBMJGJa1Pw== dependencies: "@formkit/auto-animate" "^1.0.0-beta.1" - assert-never "^1.2.1" classnames "^2.2.6" jsurl2 "^2.1.0" lz-string "^1.4.4" @@ -2930,11 +2929,6 @@ asn1@~0.2.3: dependencies: safer-buffer "~2.1.0" -assert-never@^1.2.1: - version "1.2.1" - resolved "https://registry.yarnpkg.com/assert-never/-/assert-never-1.2.1.tgz#11f0e363bf146205fb08193b5c7b90f4d1cf44fe" - integrity sha512-TaTivMB6pYI1kXwrFlEhLeGfOqoDNdTxjCdwRfFFkEA30Eu+k48W34nlok2EYWJfFFzqaEmichdNM7th6M5HNw== - assert-plus@1.0.0, assert-plus@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525"