-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): layer style node system (#1143)
Co-authored-by: airslice <[email protected]>
- Loading branch information
1 parent
67cad92
commit 16722ac
Showing
37 changed files
with
1,753 additions
and
280 deletions.
There are no files selected for viewing
33 changes: 0 additions & 33 deletions
33
web/src/beta/features/Editor/Map/LayerStylePanel/Editor/CodeTab.tsx
This file was deleted.
Oops, something went wrong.
85 changes: 0 additions & 85 deletions
85
web/src/beta/features/Editor/Map/LayerStylePanel/Editor/InterfaceTab.tsx
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
web/src/beta/features/Editor/Map/LayerStylePanel/Editor/StyleCode/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { CodeInput } from "@reearth/beta/lib/reearth-ui"; | ||
import { LayerStyle } from "@reearth/services/api/layerStyleApi/utils"; | ||
import { styled } from "@reearth/services/theme"; | ||
import { SetStateAction } from "jotai"; | ||
import { Dispatch, FC, useCallback, useEffect, useState } from "react"; | ||
|
||
import NoStyleMessage from "../NoStyleMessage"; | ||
|
||
type CodeProps = { | ||
layerStyle: LayerStyle | undefined; | ||
setLayerStyle: Dispatch<SetStateAction<LayerStyle | undefined>>; | ||
}; | ||
|
||
const StyleCode: FC<CodeProps> = ({ layerStyle, setLayerStyle }) => { | ||
const [styleCode, setStyleCode] = useState<string | undefined>(""); | ||
|
||
useEffect(() => { | ||
setStyleCode(JSON.stringify(layerStyle?.value, null, 2)); | ||
}, [layerStyle]); | ||
|
||
const handleStyleCodeChange = useCallback( | ||
(newStyleCode?: string) => { | ||
try { | ||
const parsedStyle = JSON.parse(newStyleCode || ""); | ||
setLayerStyle((prev) => { | ||
if (!prev?.id) return prev; | ||
return { | ||
...prev, | ||
value: parsedStyle | ||
}; | ||
}); | ||
} catch (_error) { | ||
// Do nothing | ||
} | ||
|
||
setStyleCode(newStyleCode); | ||
}, | ||
[setLayerStyle] | ||
); | ||
|
||
return layerStyle?.id ? ( | ||
<CodeWrapper> | ||
<CodeInput | ||
value={styleCode} | ||
onChange={handleStyleCodeChange} | ||
language="json" | ||
showLines={false} | ||
/> | ||
</CodeWrapper> | ||
) : ( | ||
<NoStyleMessage /> | ||
); | ||
}; | ||
|
||
export default StyleCode; | ||
|
||
const CodeWrapper = styled("div")(({ theme }) => ({ | ||
padding: theme.spacing.small, | ||
height: "100%" | ||
})); |
Oops, something went wrong.