From 17e8d0e3b18892185bd93f0ab2d5d5b6f3428ac1 Mon Sep 17 00:00:00 2001 From: Nikolaj Frey Date: Wed, 16 Aug 2023 09:10:13 +1000 Subject: [PATCH] feat: feature/mvp-sprint-1 Added render mode and chakra type detecting in render mode --- remix/app/components/Icon/Icon.tsx | 3 + remix/app/components/Nav/Nav.tsx | 45 +++- remix/app/components/Thingtime/Thingtime.tsx | 196 +++++++++++++----- .../app/components/Thingtime/ThingtimeURL.tsx | 49 ++++- remix/app/routes/{things => }/*.tsx | 0 remix/app/routes/code/*.tsx | 7 - remix/app/routes/code/edit/*.tsx | 7 - remix/app/routes/edit/*.tsx | 7 - remix/app/routes/edit/code/*.tsx | 7 - remix/app/routes/things/code/*.tsx | 7 - remix/app/routes/things/code/edit/*.tsx | 7 - remix/app/routes/things/edit/*.tsx | 7 - remix/app/routes/things/edit/code/*.tsx | 7 - 13 files changed, 234 insertions(+), 115 deletions(-) rename remix/app/routes/{things => }/*.tsx (100%) delete mode 100644 remix/app/routes/code/*.tsx delete mode 100644 remix/app/routes/code/edit/*.tsx delete mode 100644 remix/app/routes/edit/*.tsx delete mode 100644 remix/app/routes/edit/code/*.tsx delete mode 100644 remix/app/routes/things/code/*.tsx delete mode 100644 remix/app/routes/things/code/edit/*.tsx delete mode 100644 remix/app/routes/things/edit/*.tsx delete mode 100644 remix/app/routes/things/edit/code/*.tsx diff --git a/remix/app/components/Icon/Icon.tsx b/remix/app/components/Icon/Icon.tsx index 25d6c1c..e06d04e 100644 --- a/remix/app/components/Icon/Icon.tsx +++ b/remix/app/components/Icon/Icon.tsx @@ -21,6 +21,9 @@ export const Icon = (props) => { if (["wizard", "gandalf"]?.includes(name)) { return "🧙‍♂️" } + if (["two eyes"]?.includes(name)) { + return "👀" + } if (["box", "thing", "object"]?.includes(name)) { return "📦" } diff --git a/remix/app/components/Nav/Nav.tsx b/remix/app/components/Nav/Nav.tsx index 0bfd357..ae825c4 100644 --- a/remix/app/components/Nav/Nav.tsx +++ b/remix/app/components/Nav/Nav.tsx @@ -19,6 +19,13 @@ export const Nav = (props) => { setProfileDrawerOpen(!profileDrawerOpen) }, [profileDrawerOpen]) + const inEditorMode = React.useMemo(() => { + if (pathname.slice(0, 7) === "/editor") { + return true + } + return false + }, [pathname]) + const inEditMode = React.useMemo(() => { if (pathname.slice(0, 5) === "/edit") { return true @@ -35,7 +42,7 @@ export const Nav = (props) => { return false }, [pathname]) - const toggleEditor = React.useCallback( + const toggleEdit = React.useCallback( (e) => { // if first characters of pathname are /things replace with /edit // or if first characters of pathname are /edit replace with /things @@ -50,6 +57,21 @@ export const Nav = (props) => { [pathname, navigate] ) + const toggleEditor = React.useCallback( + (e) => { + // if first characters of pathname are /things replace with /edit + // or if first characters of pathname are /edit replace with /things + if (pathname.slice(0, 7) === "/editor") { + const newPathname = pathname.replace("/editor", "/edit") + navigate(newPathname) + } else if (pathname.slice(0, 5) === "/edit") { + const newPathname = pathname.replace("/edit", "/editor") + navigate(newPathname) + } + }, + [pathname, navigate] + ) + return ( <> { > {editorToggleable && (
+ + {/* */} +
+ )} + {editorToggleable && ( +
{ const editValueRef = React.useRef({}) const depth = React.useMemo(() => { - return props?.depth || 1 + return typeof props?.depth === "number" ? props?.depth : 0 }, [props?.depth]) + const render = React.useMemo(() => { + return props?.render || false + }, [props?.render]) + + const width = React.useMemo(() => { + if (props?.width) { + return props?.width + } + if (props?.w) { + return props?.w + } + if (render) { + return "auto" + } + return "100%" + }, [props?.width, props?.w, render]) + + const chakras = React.useMemo(() => { + if (!props?.edit && props?.chakra) { + return true + } + return false + }, [props?.edit, props?.chakra]) + const pl = React.useMemo(() => { + if (!props.edit && chakras) { + return [0] + } + return props?.pl || [4, 6] - }, [props?.pl]) + }, [props?.pl, props?.edit, chakras]) const pr = React.useMemo(() => { - return props?.pr || (depth === 1 ? [4, 6] : 0) + return props?.pr || (depth === 0 ? [4, 6] : 0) }, [props?.pr, depth]) const multiplyPl = React.useCallback( @@ -109,6 +138,10 @@ export const Thingtime = (props) => { return props.thing }, [props.thing, childrenRef.current]) + const chakra = React.useMemo(() => { + return !props?.edit && typeof thing?.chakra === "string" && thing?.chakra + }, [thing?.chakra, props?.edit]) + const path = React.useMemo(() => { return props?.path?.key || props?.path || "" }, [props?.path]) @@ -215,6 +248,10 @@ export const Thingtime = (props) => { }, [props?.valuePl, props?.path]) const renderableValue = React.useMemo(() => { + if (chakras) { + return null + } + if (type === "string") { return } else if (type === "number") { @@ -248,11 +285,15 @@ export const Thingtime = (props) => { } else { return "Something.." } - }, [thing, thingDep, type, keys]) + }, [thing, thingDep, type, chakras, keys]) const keysToUse = React.useMemo(() => { + if (!props?.edit && chakra) { + return ["children"] + } + return keys - }, [keys]) + }, [chakra, keys, props?.edit]) // const keysToUse = flattenedKeys const template1Modes = React.useMemo(() => { @@ -262,19 +303,20 @@ export const Thingtime = (props) => { const AtomicWrapper = React.useCallback((args) => { return ( {args?.children} @@ -308,12 +350,14 @@ export const Thingtime = (props) => { key={idx} seen={nextSeen} edit={props?.edit} + render={render} circular={seen?.includes?.(nextThing)} depth={depth + 1} parent={thing} notRoot fullPath={fullPath + "." + key?.key} path={key} + chakra={chakra} thing={nextThing} // thing={{ infinite: { yes: true } }} valuePl={pl} @@ -324,6 +368,35 @@ export const Thingtime = (props) => { ) } if (type === "object" && !circular) { + if (chakra) { + console.log("nik Chakras", Chakras) + const ChakraComponent = Chakras[chakra] + + console.log("Thingtime is chakra", fullPath, chakra) + + try { + if (ChakraComponent) { + console.log( + "Thingtime found ChakraComponent", + fullPath, + ChakraComponent + ) + console.log("Thingtime found thing?.props", fullPath, thing?.props) + + const ret = ( + + + {inner} + + + ) + return ret + } + } catch { + // chakra error + } + } + return ( { circular, seen, type, + chakra, fullPath, + render, depth, thing, thingDep, @@ -563,6 +638,10 @@ export const Thingtime = (props) => { }, [humanPath, props?.edit]) const pathDom = React.useMemo(() => { + if (chakras) { + return <> + } + if (renderedPath) { return ( <> @@ -579,7 +658,7 @@ export const Thingtime = (props) => { ) } - }, [renderedPath, pl, props?.edit, props?.pathPl]) + }, [renderedPath, pl, chakras, props?.edit, props?.pathPl]) const handleMouseEvent = React.useCallback( (e) => { @@ -619,6 +698,10 @@ export const Thingtime = (props) => { const [showContextIcon, setShowContextIcon] = React.useState(false) + // if (render && depth >= 1) { + // return thingtimeChildren + // } + return ( { flexDirection="column" // width="500px" rowGap={2} - width={props?.width || props?.w || "100%"} + width={width} maxWidth="100%" // marginTop={3} paddingRight={pr} @@ -634,58 +717,67 @@ export const Thingtime = (props) => { onMouseEnter={handleMouseEvent} onMouseLeave={handleMouseEvent} {...(props.chakras || {})} - className={`thing uuid-${uuid}`} + className={`thing uuid-${uuid} edit-${props?.edit ? "true" : "false"}`} data-path={props?.path} > {/* {uuid?.current} */} - - setShowContextIcon(true)} - onMouseLeave={() => setShowContextIcon(false)} - > - {pathDom} - {props?.edit && ( - - {typeIcon} - - )} - {pathDom && ( - - - - )} + {!chakras && ( + + setShowContextIcon(true)} + onMouseLeave={() => setShowContextIcon(false)} + > + {pathDom} + {props?.edit && ( + + {typeIcon} + + )} + {pathDom && ( + + + + )} + - + )} {/* {showContextMenu && contextMenu} */} {!loading && !thingtimeChildren && atomicValue && ( - {atomicValue} + + {atomicValue} + )} {!loading && thingtimeChildren && ( - + {thingtimeChildren} - {type === "object" && ( + {!render && type === "object" && ( { const { getThingtime } = useThingtime() + const { pathname } = useLocation() + const matches = useMatches() const location = React.useMemo(() => { return matches[matches.length - 1] }, [matches]) const path = React.useMemo(() => { - const pathPartOne = location?.params?.["*"] + console.log("nik location", location) + + // const sanitisation = ["/things", "/edit", "/editor", "/code", "/coder"] + + // // strip the leading /path1/path2 path1 section from the path + // let pathPartOne = location?.pathname?.split("/")[2] + + // // remove all sanitsation strings from path + // sanitisation.forEach((sanitisationString) => { + // pathPartOne = pathPartOne?.replace(sanitisationString, "") + // }) + + // strip the leading /path1/path2 path1 section from the path + const pathPartOne = location?.pathname?.split("/")[2] const path = pathPartOne?.replace(/\//g, ".") @@ -29,15 +44,39 @@ export const ThingtimeURL = (props) => { return ret }, [path, getThingtime]) + const inEditorMode = React.useMemo(() => { + if (pathname.slice(0, 7) === "/editor") { + return true + } + return false + }, [pathname]) + + const inEditMode = React.useMemo(() => { + if (pathname.slice(0, 5) === "/edit") { + return true + } + return false + }, [pathname]) + return ( + {inEditorMode && ( + + )} -} diff --git a/remix/app/routes/code/edit/*.tsx b/remix/app/routes/code/edit/*.tsx deleted file mode 100644 index ec65898..0000000 --- a/remix/app/routes/code/edit/*.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react" - -import { ThingtimeURL } from "~/components/Thingtime/ThingtimeURL" - -export default function Index() { - return -} diff --git a/remix/app/routes/edit/*.tsx b/remix/app/routes/edit/*.tsx deleted file mode 100644 index 83490fa..0000000 --- a/remix/app/routes/edit/*.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react" - -import { ThingtimeURL } from "~/components/Thingtime/ThingtimeURL" - -export default function Index() { - return -} diff --git a/remix/app/routes/edit/code/*.tsx b/remix/app/routes/edit/code/*.tsx deleted file mode 100644 index 558e900..0000000 --- a/remix/app/routes/edit/code/*.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react" - -import { ThingtimeURL } from "~/components/Thingtime/ThingtimeURL" - -export default function Index() { - return -} diff --git a/remix/app/routes/things/code/*.tsx b/remix/app/routes/things/code/*.tsx deleted file mode 100644 index 59fe8fa..0000000 --- a/remix/app/routes/things/code/*.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react" - -import { ThingtimeURL } from "~/components/Thingtime/ThingtimeURL" - -export default function Index() { - return -} diff --git a/remix/app/routes/things/code/edit/*.tsx b/remix/app/routes/things/code/edit/*.tsx deleted file mode 100644 index ec65898..0000000 --- a/remix/app/routes/things/code/edit/*.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react" - -import { ThingtimeURL } from "~/components/Thingtime/ThingtimeURL" - -export default function Index() { - return -} diff --git a/remix/app/routes/things/edit/*.tsx b/remix/app/routes/things/edit/*.tsx deleted file mode 100644 index 83490fa..0000000 --- a/remix/app/routes/things/edit/*.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react" - -import { ThingtimeURL } from "~/components/Thingtime/ThingtimeURL" - -export default function Index() { - return -} diff --git a/remix/app/routes/things/edit/code/*.tsx b/remix/app/routes/things/edit/code/*.tsx deleted file mode 100644 index 558e900..0000000 --- a/remix/app/routes/things/edit/code/*.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react" - -import { ThingtimeURL } from "~/components/Thingtime/ThingtimeURL" - -export default function Index() { - return -}