-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26f560a
commit 1cae642
Showing
9 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { Lang } from "@carefree0910/core"; | ||
|
||
export enum NodeEditor_Words { | ||
"basic-editor-plugin-header" = "basic-editor-plugin-header", | ||
"text-editor-plugin-header" = "text-editor-plugin-header", | ||
} | ||
|
||
export const nodeEditorLangRecords: Record<Lang, Record<NodeEditor_Words, string>> = { | ||
zh: { | ||
[NodeEditor_Words["basic-editor-plugin-header"]]: "基础属性", | ||
[NodeEditor_Words["text-editor-plugin-header"]]: "编辑文本", | ||
}, | ||
en: { | ||
[NodeEditor_Words["basic-editor-plugin-header"]]: "Basic Fields", | ||
[NodeEditor_Words["text-editor-plugin-header"]]: "Edit Text", | ||
}, | ||
}; |
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
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
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,121 @@ | ||
import { useUnmount } from "ahooks"; | ||
import { ReactElement, useEffect, useState } from "react"; | ||
import { observer } from "mobx-react-lite"; | ||
import { Center, Flex } from "@chakra-ui/react"; | ||
|
||
import { | ||
langStore, | ||
translate, | ||
useCornerRadius, | ||
useIsReady, | ||
useSelecting, | ||
} from "@carefree0910/business"; | ||
|
||
import { ReactComponent as RotateIcon } from "@/assets/icons/rotate.svg"; | ||
import { ReactComponent as CornerRadiusIcon } from "@/assets/icons/corner-radius.svg"; | ||
|
||
import type { IPlugin } from "@/schema/plugins"; | ||
import { NodeEditor_Words } from "@/lang/nodeEditor"; | ||
import { usePluginIds } from "@/stores/pluginsInfo"; | ||
import CFIcon from "@/components/CFIcon"; | ||
import CFDivider from "@/components/CFDivider"; | ||
import CFHeading from "@/components/CFHeading"; | ||
import CFInput, { ICFInput } from "@/components/CFInput"; | ||
import { CFCaption } from "@/components/CFText"; | ||
import { drawboardPluginFactory } from "../utils/factory"; | ||
import Render from "../components/Render"; | ||
import { mean } from "@carefree0910/core"; | ||
|
||
const FieldInput = ({ | ||
caption, | ||
value, | ||
setValue, | ||
...props | ||
}: ICFInput & { | ||
caption?: string | ReactElement; | ||
value: number; | ||
setValue: (value: number) => void; | ||
}) => { | ||
const [iv, setIv] = useState(value); | ||
|
||
useEffect(() => setIv(value), [value]); | ||
useUnmount(() => setValue(iv)); | ||
|
||
return ( | ||
<Flex align="center"> | ||
<CFCaption w="24px" mr="12px" as="div"> | ||
<Center>{caption}</Center> | ||
</CFCaption> | ||
<CFInput | ||
w="72px" | ||
h="36px" | ||
p="12px" | ||
onKeyDown={(e) => { | ||
if (e.key === "Enter") { | ||
(e.target as any)?.blur(); | ||
} | ||
}} | ||
useNumberInputProps={{ | ||
value: iv, | ||
onChange: (value) => setIv(+value), | ||
onBlur: () => setValue(iv), | ||
}} | ||
{...props} | ||
/> | ||
</Flex> | ||
); | ||
}; | ||
|
||
const BasicEditorPlugin = ({ pluginInfo, ...props }: IPlugin) => { | ||
const id = usePluginIds("basicEditor").id; | ||
const lang = langStore.tgt; | ||
let x: number, y: number, w: number, h: number, rotation: number; | ||
let Fields: ReactElement | null = null; | ||
const { cornerRadius, setCornerRadius } = useCornerRadius(); | ||
if (!useIsReady()) { | ||
props.renderInfo.isInvisible = true; | ||
} else { | ||
const info = useSelecting("basic")({ fixed: 1 }); | ||
if (!info) { | ||
props.renderInfo.isInvisible = true; | ||
} else { | ||
({ x, y, w, h, rotation } = info); | ||
const { type, displayNode, setX, setY, setW, setH, setRotation } = info; | ||
if (type === "none" || type === "multiple") { | ||
props.renderInfo.isInvisible = true; | ||
} else { | ||
Fields = ( | ||
<Flex w="100%" px="12px" gap="12px" wrap="wrap" justify="flex-start"> | ||
<FieldInput caption="X" value={x} setValue={setX({ trace: true })} /> | ||
<FieldInput caption="Y" value={y} setValue={setY({ trace: true })} /> | ||
<FieldInput caption="W" value={w} setValue={setW({ trace: true })} /> | ||
<FieldInput caption="H" value={h} setValue={setH({ trace: true })} /> | ||
<FieldInput | ||
caption={<CFIcon svg={RotateIcon} fillbyCurrentColor />} | ||
value={rotation} | ||
setValue={setRotation({ trace: true })} | ||
/> | ||
{displayNode.type === "image" ? ( | ||
<FieldInput | ||
caption={<CFIcon svg={CornerRadiusIcon} fillbyCurrentColor />} | ||
value={ | ||
cornerRadius ? parseFloat(mean(Object.values(cornerRadius)).toFixed(1)) : 0.0 | ||
} | ||
setValue={(v) => setCornerRadius({ trace: true })({ lt: v, rt: v, rb: v, lb: v })} | ||
/> | ||
) : null} | ||
</Flex> | ||
); | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<Render id={id} {...props}> | ||
<CFHeading>{translate(NodeEditor_Words["basic-editor-plugin-header"], lang)}</CFHeading> | ||
<CFDivider /> | ||
{Fields} | ||
</Render> | ||
); | ||
}; | ||
drawboardPluginFactory.register("basicEditor", true)(observer(BasicEditorPlugin)); |
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
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