From 4fb03692cefc548dadeffbc4c06c98e0e823c00c Mon Sep 17 00:00:00 2001 From: Nikolaj Frey Date: Sun, 2 Jul 2023 01:05:55 +1000 Subject: [PATCH] feat: main Made editableValue respect new lines --- remix/app/Providers/ThingtimeProvider.tsx | 14 ++++---- remix/app/components/Thingtime/Thingtime.tsx | 35 ++++++++++++++++---- remix/app/routes/index.tsx | 7 +++- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/remix/app/Providers/ThingtimeProvider.tsx b/remix/app/Providers/ThingtimeProvider.tsx index d8c1d04..f26ee43 100644 --- a/remix/app/Providers/ThingtimeProvider.tsx +++ b/remix/app/Providers/ThingtimeProvider.tsx @@ -19,18 +19,18 @@ try { const forceable = { Content: { - Content: { - hidden1: "Edit this to your heart's desire.", - 'How?': - 'Just search for Content.Content and edit the value to whatever you want.' - } + hidden1: "Edit this to your heart's desire.", + 'How?': 'Just search for Content and edit the value to whatever you want.', + 'Example:': `Content = New Content! + Content.Nested Content = New Nested Content! + ` } } const initialThingtime = { nav: {}, - version: 12 - // ...forceable + version: 22, + ...forceable } const userData = { diff --git a/remix/app/components/Thingtime/Thingtime.tsx b/remix/app/components/Thingtime/Thingtime.tsx index 6a9e4c7..97f62c6 100644 --- a/remix/app/components/Thingtime/Thingtime.tsx +++ b/remix/app/components/Thingtime/Thingtime.tsx @@ -50,6 +50,13 @@ export const Thingtime = props => { return typeof thing }, [thing]) + const valuePl = React.useMemo(() => { + if (typeof props?.valuePl === 'number') { + return props?.valuePl + } + return props?.path ? [4, 6] : [0, 0] + }, [props?.valuePl, props?.path]) + const renderableValue = React.useMemo(() => { if (type === 'string') { if (!thing) { @@ -141,7 +148,7 @@ export const Thingtime = props => { // w={['200px', '500px']} maxW='100%' py={props?.path ? 3 : 0} - pl={props?.valuePl} + pl={valuePl} > {keysToUse?.length && keysToUse.map((key, idx) => { @@ -178,6 +185,8 @@ export const Thingtime = props => { py={2} pl={pl} fontSize={'20px'} + whiteSpace={'pre-line'} + // dangerouslySetInnerHTML={{ __html: renderableValue }} > {renderableValue} @@ -193,20 +202,32 @@ export const Thingtime = props => { const [showContextMenu, setShowContextMenu] = React.useState(false) + const humanPath = React.useMemo(() => { + if (typeof props?.path === 'string') { + return props?.path + } + return props?.path?.human || '' + }, [props?.path]) + const path = React.useMemo(() => { - if (props?.path?.human?.includes?.('hidden')) { + if (humanPath?.includes?.('hidden')) { return null } - if (props?.path?.human?.includes?.('unique')) { + if (humanPath?.includes?.('unique')) { // take only path from before the string unique - return props?.path?.human?.split?.('unique')?.[0] + return humanPath.split?.('unique')?.[0] } return ( - - {props?.path?.human} + + {humanPath} ) - }, [props?.path]) + }, [humanPath, pl, props?.pathPl]) const handleMouseEvent = React.useCallback( e => { diff --git a/remix/app/routes/index.tsx b/remix/app/routes/index.tsx index 95e84dc..0b1bcbf 100644 --- a/remix/app/routes/index.tsx +++ b/remix/app/routes/index.tsx @@ -16,7 +16,12 @@ export default function Index () { justifyContent='center' > - +