diff --git a/client/packages/lowcoder/package.json b/client/packages/lowcoder/package.json index 542327bee7..634deed0e0 100644 --- a/client/packages/lowcoder/package.json +++ b/client/packages/lowcoder/package.json @@ -101,7 +101,7 @@ "react-quill-new": "^3.4.6", "react-redux": "^7.2.6", "react-resizable": "^3.0.4", - "react-resize-detector": "^12.0.2", + "react-resize-detector": "^12.3.0", "react-router": "^5.2.1", "react-router-dom": "^5.3.0", "react-signature-canvas": "^1.0.6", @@ -132,7 +132,8 @@ "y-protocols": "^1.0.6", "y-websocket": "^3.0.0", "yjs": "^13.6.27", - "zod": "^3.25.76" + "zod": "^3.25.76", + "zustand": "^5.0.14" }, "scripts": { "supportedBrowsers": "yarn dlx browserslist-useragent-regexp --allowHigherVersions '>0.2%,not dead,not op_mini all,chrome >=69'", diff --git a/client/packages/lowcoder/src/components/CompName.tsx b/client/packages/lowcoder/src/components/CompName.tsx index 69fd8c781e..66bd47643a 100644 --- a/client/packages/lowcoder/src/components/CompName.tsx +++ b/client/packages/lowcoder/src/components/CompName.tsx @@ -15,6 +15,7 @@ import { trans } from "i18n"; import { getComponentDocUrl } from "comps/utils/compDocUtil"; import { getComponentPlaygroundUrl } from "comps/utils/compDocUtil"; import { parseCompType } from "comps/utils/remote"; +import { useEditorStore } from "comps/editorStore"; const CompDiv = styled.div<{ $width?: number; $hasSearch?: boolean; $showSearch?: boolean }>` width: ${(props) => (props.$width ? props.$width : 312)}px; @@ -79,7 +80,11 @@ export const CompName = React.memo((props: Iprops) => { const [showSearch, setShowSearch] = useState(false); const editorState = useContext(EditorContext); - const selectedComp = useMemo(() => values(editorState.selectedComps())[0], [editorState]); + const selectedCompNames = useEditorStore((state) => state.selectedCompNames); + const selectedComp = useMemo( + () => values(editorState.selectedComps(selectedCompNames))[0], + [editorState, selectedCompNames] + ); const compType = useMemo(() => selectedComp.children.compType.getView() as UICompType, [selectedComp]); const compInfo = useMemo(() => parseCompType(compType), [compType]); const docUrl = useMemo(() => getComponentDocUrl(compType), [compType]); diff --git a/client/packages/lowcoder/src/components/PermissionDialog/AppPermissionDialog.tsx b/client/packages/lowcoder/src/components/PermissionDialog/AppPermissionDialog.tsx index be9abcc463..57d8da8d2f 100644 --- a/client/packages/lowcoder/src/components/PermissionDialog/AppPermissionDialog.tsx +++ b/client/packages/lowcoder/src/components/PermissionDialog/AppPermissionDialog.tsx @@ -127,7 +127,7 @@ export const AppPermissionDialog = React.memo( return ( { setActiveStepKey("permission"); props.onVisibleChange(false); diff --git a/client/packages/lowcoder/src/components/resultPanel/BottomResultPanel.tsx b/client/packages/lowcoder/src/components/resultPanel/BottomResultPanel.tsx index 7f4f82c23b..8886b6a5c9 100644 --- a/client/packages/lowcoder/src/components/resultPanel/BottomResultPanel.tsx +++ b/client/packages/lowcoder/src/components/resultPanel/BottomResultPanel.tsx @@ -3,6 +3,7 @@ import Draggable from "react-draggable"; import * as React from "react"; import { useContext, useRef, useState } from "react"; import { EditorContext } from "../../comps/editorState"; +import { useEditorStore } from "../../comps/editorStore"; import { Layers } from "constants/Layers"; import { HeaderWrapper, useResultPanel } from "./index"; @@ -31,7 +32,8 @@ interface BottomResultPanelProps { export const BottomResultPanel = (props: BottomResultPanelProps) => { const { bottom } = props; const editorState = useContext(EditorContext); - const showResultComp = editorState.showResultComp(); + const showResultCompName = useEditorStore((state) => state.showResultCompName); + const showResultComp = editorState.showResultComp(showResultCompName); const result = showResultComp?.result(); const draggableRef = useRef(null); diff --git a/client/packages/lowcoder/src/comps/comps/avatarGroup.tsx b/client/packages/lowcoder/src/comps/comps/avatarGroup.tsx index f370a4ef99..6818db70db 100644 --- a/client/packages/lowcoder/src/comps/comps/avatarGroup.tsx +++ b/client/packages/lowcoder/src/comps/comps/avatarGroup.tsx @@ -10,9 +10,9 @@ import { NumberControl, StringControl } from "comps/controls/codeControl"; import { Avatar, Tooltip } from "antd"; import { clickEvent, doubleClickEvent, eventHandlerControl, refreshEvent } from "../controls/eventHandlerControl"; import styled from "styled-components"; -import { useContext, ReactElement, useEffect } from "react"; +import { ReactElement, useEffect } from "react"; import { MultiCompBuilder, stateComp, withDefault } from "../generators"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { IconControl } from "../controls/iconControl"; import { ColorControl } from "../controls/colorControl"; import { optionsControl } from "../controls/optionsControl"; @@ -148,9 +148,11 @@ let AvatarGroupBasicComp = (function () { return new UICompBuilder(childrenMap, (props, dispatch) => { return( )}) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <> - {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && ( <>
{children.avatars.propertyView({})} @@ -175,7 +177,7 @@ let AvatarGroupBasicComp = (function () { )} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.avatar.getPropertyView()} @@ -186,7 +188,8 @@ let AvatarGroupBasicComp = (function () { )} - )) + ); + }) .build(); })(); diff --git a/client/packages/lowcoder/src/comps/comps/buttonComp/buttonComp.tsx b/client/packages/lowcoder/src/comps/comps/buttonComp/buttonComp.tsx index bd019ab66c..c4b577a18b 100644 --- a/client/packages/lowcoder/src/comps/comps/buttonComp/buttonComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/buttonComp/buttonComp.tsx @@ -3,6 +3,7 @@ import { dropdownControl } from "comps/controls/dropdownControl"; import { ButtonEventHandlerControl } from "comps/controls/eventHandlerControl"; import { IconControl } from "comps/controls/iconControl"; import { CompNameContext, EditorContext, EditorState } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { withDefault } from "comps/generators"; import { NewChildren, UICompBuilder } from "comps/generators/uiCompBuilder"; import { @@ -146,7 +147,7 @@ type ChildrenType = NewChildren>; const ButtonPropertyView = React.memo((props: { children: ChildrenType }) => { - const { editorModeStatus } = useContext(EditorContext); + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
diff --git a/client/packages/lowcoder/src/comps/comps/buttonComp/dropdownComp.tsx b/client/packages/lowcoder/src/comps/comps/buttonComp/dropdownComp.tsx index ec2fa482e0..8880f4735e 100644 --- a/client/packages/lowcoder/src/comps/comps/buttonComp/dropdownComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/buttonComp/dropdownComp.tsx @@ -9,8 +9,8 @@ import { UICompBuilder } from "comps/generators/uiCompBuilder"; import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUtils"; import { Section, sectionNames } from "lowcoder-design"; import { trans } from "i18n"; -import React, { ReactElement, useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import React, { ReactElement } from "react"; +import { useEditorStore } from "comps/editorStore"; import styled from "styled-components"; import EllipsisOutlined from "@ant-design/icons/EllipsisOutlined"; import { IconControl } from "comps/controls/iconControl"; @@ -250,13 +250,15 @@ const DropdownTmpComp = (function () { ); }) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.options.propertyView({})}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{!children.onlyMenu.getView() && !children.onlyIcon.getView() ? children.onEvent.getPropertyView() @@ -267,7 +269,7 @@ const DropdownTmpComp = (function () { )} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.text.propertyView({ label: trans("label") })} @@ -290,7 +292,8 @@ const DropdownTmpComp = (function () { )} - )) + ); + }) .build(); })(); diff --git a/client/packages/lowcoder/src/comps/comps/buttonComp/linkComp.tsx b/client/packages/lowcoder/src/comps/comps/buttonComp/linkComp.tsx index b96fe77ea2..318e5dad26 100644 --- a/client/packages/lowcoder/src/comps/comps/buttonComp/linkComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/buttonComp/linkComp.tsx @@ -21,8 +21,8 @@ import { IconControl } from "comps/controls/iconControl"; import { hasIcon } from "comps/utils"; import { RefControl } from "comps/controls/refControl"; -import { EditorContext } from "comps/editorState"; -import React, { useContext, useEffect } from "react"; +import { useEditorStore } from "comps/editorStore"; +import React, { useEffect } from "react"; const Link = styled(Button)<{ $style: LinkStyleType; @@ -120,13 +120,14 @@ const LinkTmpComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
{children.text.propertyView({ label: trans("text") })}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{children.onEvent.getPropertyView()} {disabledPropertyView(children)} @@ -141,7 +142,7 @@ const LinkTmpComp = (function () {
)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.style.getPropertyView()}
{children.animationStyle.getPropertyView()}
diff --git a/client/packages/lowcoder/src/comps/comps/buttonComp/scannerComp.tsx b/client/packages/lowcoder/src/comps/comps/buttonComp/scannerComp.tsx index 8900ea914c..1d39d09ba4 100644 --- a/client/packages/lowcoder/src/comps/comps/buttonComp/scannerComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/buttonComp/scannerComp.tsx @@ -28,12 +28,11 @@ import React, { useEffect, useRef, useState, - useContext, } from "react"; import { arrayStringExposingStateControl, stringExposingStateControl } from "comps/controls/codeStateControl"; import { BoolControl } from "comps/controls/boolControl"; import { RefControl } from "comps/controls/refControl"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; const Error = styled.div` color: #f5222d; @@ -284,14 +283,16 @@ const ScannerTmpComp = (function () { ); }) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.text.propertyView({ label: trans("text") })}
- {(useContext(EditorContext).editorModeStatus === "logic" || - useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || + editorModeStatus === "both") && ( <>
{children.onEvent.getPropertyView()} @@ -315,14 +316,15 @@ const ScannerTmpComp = (function () { )} - {(useContext(EditorContext).editorModeStatus === "layout" || - useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || + editorModeStatus === "both") && (
{children.style.getPropertyView()}
)} - )) + ); + }) .setExposeMethodConfigs(buttonRefMethods) .build(); })(); diff --git a/client/packages/lowcoder/src/comps/comps/buttonComp/toggleButtonComp.tsx b/client/packages/lowcoder/src/comps/comps/buttonComp/toggleButtonComp.tsx index ce82c9ff51..7e093f4299 100644 --- a/client/packages/lowcoder/src/comps/comps/buttonComp/toggleButtonComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/buttonComp/toggleButtonComp.tsx @@ -24,8 +24,8 @@ import { import { styleControl } from "comps/controls/styleControl"; import { BoolControl } from "comps/controls/boolControl"; import { RefControl } from "comps/controls/refControl"; -import React, { useContext, useEffect } from "react"; -import { EditorContext } from "comps/editorState"; +import React, { useEffect } from "react"; +import { useEditorStore } from "comps/editorStore"; import { Tooltip } from "antd"; const IconWrapper = styled.div` @@ -103,7 +103,9 @@ const ToggleTmpComp = (function () { ); }) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.value.propertyView({ @@ -112,7 +114,7 @@ const ToggleTmpComp = (function () { })}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{children.onEvent.getPropertyView()} {disabledPropertyView(children)} @@ -143,8 +145,8 @@ const ToggleTmpComp = (function () { )} - {(useContext(EditorContext).editorModeStatus === "layout" || - useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || + editorModeStatus === "both") && ( <>
{children.showBorder.propertyView({ @@ -160,7 +162,8 @@ const ToggleTmpComp = (function () {
{children.disabledStyle.getPropertyView()}
- )) + ); + }) .setExposeMethodConfigs(buttonRefMethods) .build(); })(); diff --git a/client/packages/lowcoder/src/comps/comps/carouselComp.tsx b/client/packages/lowcoder/src/comps/comps/carouselComp.tsx index 5d3f6d77bb..46964c72a1 100644 --- a/client/packages/lowcoder/src/comps/comps/carouselComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/carouselComp.tsx @@ -15,8 +15,7 @@ import { ArrayStringControl } from "comps/controls/codeControl"; import { styleControl } from "comps/controls/styleControl"; import { AnimationStyle, AnimationStyleType, CarouselStyle } from "comps/controls/styleControlConstants"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; // TODO: dots at top position needs proper margin (should be the same as bottom position) @@ -84,13 +83,14 @@ let CarouselBasicComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
{children.data.propertyView({ label: trans("data") })}
- {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && ( <>
{children.onEvent.getPropertyView()} @@ -98,7 +98,7 @@ let CarouselBasicComp = (function () { {children.autoPlay.propertyView({ label: trans("carousel.autoPlay") })}
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.showDots.propertyView({ label: trans("carousel.showDots") })} {children.dotPosition.propertyView({ diff --git a/client/packages/lowcoder/src/comps/comps/chatBoxComponent/chatBoxComp.tsx b/client/packages/lowcoder/src/comps/comps/chatBoxComponent/chatBoxComp.tsx index d8a874cb3b..9c293f1e37 100644 --- a/client/packages/lowcoder/src/comps/comps/chatBoxComponent/chatBoxComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/chatBoxComponent/chatBoxComp.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useState } from "react"; +import React, { useState } from "react"; import { Section, sectionNames, controlItem } from "lowcoder-design"; import { default as Segmented } from "antd/es/segmented"; import { UICompBuilder, withDefault, stateComp } from "../../generators"; @@ -41,7 +41,7 @@ import { } from "comps/controls/styleControlConstants"; import { RefControl } from "comps/controls/refControl"; import { hiddenPropertyView } from "comps/utils/propertyUtils"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { trans } from "i18n"; import { ChatBoxView } from "./components/ChatBoxView"; @@ -187,7 +187,7 @@ const avatarStyleOptions = [ const ChatBoxPropertyView = React.memo((props: { children: any }) => { const { children } = props; - const editorMode = useContext(EditorContext).editorModeStatus; + const editorMode = useEditorStore((state) => state.editorModeStatus); const [messageStyleSegment, setMessageStyleSegment] = useState("own"); const [avatarStyleSegment, setAvatarStyleSegment] = useState("own"); diff --git a/client/packages/lowcoder/src/comps/comps/columnLayout/columnLayout.tsx b/client/packages/lowcoder/src/comps/comps/columnLayout/columnLayout.tsx index 2fc3fbdd62..4bde0299c9 100644 --- a/client/packages/lowcoder/src/comps/comps/columnLayout/columnLayout.tsx +++ b/client/packages/lowcoder/src/comps/comps/columnLayout/columnLayout.tsx @@ -35,8 +35,8 @@ import { messageInstance } from "lowcoder-design/src/components/GlobalInstances" import { BoolControl } from "comps/controls/boolControl"; import { BoolCodeControl, NumberControl, StringControl } from "comps/controls/codeControl"; -import { useContext, useEffect } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEffect } from "react"; +import { useEditorStore } from "comps/editorStore"; import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUtils"; import { DisabledContext } from "comps/generators/uiCompBuilder"; @@ -250,6 +250,7 @@ export const ResponsiveLayoutBaseComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -259,14 +260,14 @@ export const ResponsiveLayoutBaseComp = (function () { })}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{disabledPropertyView(children)} {hiddenPropertyView(children)}
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.autoHeight.getPropertyView()} @@ -291,7 +292,7 @@ export const ResponsiveLayoutBaseComp = (function () { )} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.style.getPropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/commentComp/commentComp.tsx b/client/packages/lowcoder/src/comps/comps/commentComp/commentComp.tsx index f3b14959c9..4001728b17 100644 --- a/client/packages/lowcoder/src/comps/comps/commentComp/commentComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/commentComp/commentComp.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState, useRef, useContext } from "react"; +import React, { useEffect, useState, useRef } from "react"; // Render the component to the editor import { changeChildAction, @@ -27,7 +27,7 @@ import { mentionEvent, doubleClickEvent, } from "comps/controls/eventHandlerControl"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; // Introducing styles @@ -379,7 +379,9 @@ let CommentBasicComp = (function () { return ( )}) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.title.propertyView({ @@ -387,7 +389,7 @@ let CommentBasicComp = (function () { })}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{children.value.propertyView({ @@ -418,7 +420,7 @@ let CommentBasicComp = (function () { )} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.sendCommentAble.getView() && children.buttonText.propertyView({ @@ -437,7 +439,8 @@ let CommentBasicComp = (function () { )} - )) + ); + }) .build(); })(); diff --git a/client/packages/lowcoder/src/comps/comps/containerComp/cardComp.tsx b/client/packages/lowcoder/src/comps/comps/containerComp/cardComp.tsx index c8661fa969..5a8cb9eca5 100644 --- a/client/packages/lowcoder/src/comps/comps/containerComp/cardComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/containerComp/cardComp.tsx @@ -9,8 +9,8 @@ import { disabledPropertyView, hiddenPropertyView, showDataLoadingIndicatorsProp import { trans } from "i18n"; import { BoolCodeControl, StringControl } from "comps/controls/codeControl"; import { BoolControl } from "comps/controls/boolControl"; -import { useContext, useEffect, useRef, useState } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEffect, useRef, useState } from "react"; +import { useEditorStore } from "comps/editorStore"; import { Card } from "antd"; import styled from "styled-components"; import { AnimationStyle, AnimationStyleType, CardHeaderStyle, CardHeaderStyleType, CardStyle, CardStyleType } from "comps/controls/styleControlConstants"; @@ -276,9 +276,10 @@ export const ContainerBaseComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <> - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{children.size.propertyView({ @@ -337,7 +338,7 @@ export const ContainerBaseComp = (function () { )} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.cardType.propertyView({ @@ -366,4 +367,3 @@ export const ContainerBaseComp = (function () { })(); export const CardComp = withExposingConfigs(ContainerBaseComp, [NameConfigHidden]); - diff --git a/client/packages/lowcoder/src/comps/comps/containerComp/containerComp.tsx b/client/packages/lowcoder/src/comps/comps/containerComp/containerComp.tsx index 1fa38cdc5c..adfbcebc67 100644 --- a/client/packages/lowcoder/src/comps/comps/containerComp/containerComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/containerComp/containerComp.tsx @@ -14,8 +14,7 @@ import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUt import { trans } from "i18n"; import { BoolCodeControl } from "comps/controls/codeControl"; import { DisabledContext } from "comps/generators/uiCompBuilder"; -import React, { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { AnimationStyle } from "@lowcoder-ee/comps/controls/styleControlConstants"; import { styleControl } from "@lowcoder-ee/comps/controls/styleControl"; @@ -32,16 +31,17 @@ export const ContainerBaseComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <> - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{disabledPropertyView(children)} {hiddenPropertyView(children)}
)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.container.getPropertyView()}
diff --git a/client/packages/lowcoder/src/comps/comps/containerComp/containerView.tsx b/client/packages/lowcoder/src/comps/comps/containerComp/containerView.tsx index dbf4d5d8f5..39404ad63f 100644 --- a/client/packages/lowcoder/src/comps/comps/containerComp/containerView.tsx +++ b/client/packages/lowcoder/src/comps/comps/containerComp/containerView.tsx @@ -2,6 +2,7 @@ import { EditorContext, EditorState } from "comps/editorState"; import { sameTypeMap, stateComp, valueComp } from "comps/generators"; import { addMapChildAction, addMapCompChildAction } from "comps/generators/sameTypeMap"; import { hookCompCategory, HookCompType } from "comps/hooks/hookCompTypes"; +import { shouldOpenOverlayOnCreate } from "comps/hooks/hookSelection"; import { UICompLayoutInfo, uiCompRegistry, UICompType } from "comps/uiCompRegistry"; import { genRandomKey } from "comps/utils/idGenerator"; import { parseCompType } from "comps/utils/remote"; @@ -54,6 +55,7 @@ import React, { useRef, useState, } from "react"; +import { useEditorStore } from "comps/editorStore"; import { ResizePayload, useResizeDetector } from "react-resize-detector"; import styled from "styled-components"; import { checkIsMobile } from "util/commonUtils"; @@ -215,13 +217,16 @@ const onDrop = async ( // log.debug("layout: onDrop start. layout: ", layout, " items: ", items, " compType: ", compType); if (hookCompCategory(compType) === "ui") { const compName = editorState.getNameGenerator().genItemName(compType); + const hookValue = { + name: compName, + compType: compType as HookCompType, + ...(shouldOpenOverlayOnCreate(compType) && { comp: { visible: true } }), + }; editorState .getHooksComp() .dispatch( wrapActionExtraInfo( - editorState - .getHooksComp() - .pushAction({ name: compName, compType: compType as HookCompType }), + editorState.getHooksComp().pushAction(hookValue), { compInfos: [{ compName: compName, compType: compType, type: "add" }] } ) ); @@ -328,10 +333,10 @@ const GridItemWrapper = React.memo(React.forwardRef( props: React.PropsWithChildren>, ref: React.ForwardedRef ) => { - const editorState = useContext(EditorContext); + const disableInteract = useEditorStore((state) => state.disableInteract); const { children, ...divProps } = props; return ( - + {props.children} ); @@ -354,6 +359,9 @@ export const InnerGrid = React.memo((props: ViewPropsWithSelect) => { const [currentRowCount, setRowCount] = useState(rowCount || Infinity); const [currentRowHeight, setRowHeight] = useState(positionParams.rowHeight || DEFAULT_ROW_HEIGHT); const editorState = useContext(EditorContext); + const selectedCompNames = useEditorStore((state) => state.selectedCompNames); + const isDragging = useEditorStore((state) => state.isDragging); + const showGridLines = useEditorStore((state) => state.isDragging || state.forceShowGrid); const { readOnly } = useContext(ExternalEditorContext); const appSettingsComp = editorState?.getAppSettingsComp().getView(); @@ -377,10 +385,10 @@ export const InnerGrid = React.memo((props: ViewPropsWithSelect) => { getExtraLayout( props.items, props.layout, - editorState?.selectedCompNames, + selectedCompNames, props.dragSelectedComps ), - [props.items, props.layout, editorState?.selectedCompNames, props.dragSelectedComps] + [props.items, props.layout, selectedCompNames, props.dragSelectedComps] ); const [containerSelectNames, setContainerSelectNames] = useState>(new Set([])); @@ -397,8 +405,8 @@ export const InnerGrid = React.memo((props: ViewPropsWithSelect) => { }, [extraLayout, containerSelectNames]); const canAddSelect = useMemo( - () => _.size(containerSelectNames) === _.size(editorState?.selectedCompNames), - [containerSelectNames, editorState?.selectedCompNames] + () => _.size(containerSelectNames) === _.size(selectedCompNames), + [containerSelectNames, selectedCompNames] ); const dispatchPositionParamsTimerRef = useRef(0); @@ -532,7 +540,7 @@ export const InnerGrid = React.memo((props: ViewPropsWithSelect) => { style={props.style} scrollContainerRef={props.scrollContainerRef} width={width ?? 0} - showGridLines={editorState?.showGridLines() && (isDroppable || enableGridLines)} + showGridLines={showGridLines && (isDroppable || enableGridLines)} isRowCountLocked={isRowCountLocked} isDraggable={isDraggable} isResizable={isResizable} @@ -590,12 +598,12 @@ export const InnerGrid = React.memo((props: ViewPropsWithSelect) => { minHeight={props.minHeight} bgColor={props.bgColor} radius={props.radius} - hintPlaceholder={!editorState?.isDragging && !readOnly && props.hintPlaceholder} + hintPlaceholder={!isDragging && !readOnly && props.hintPlaceholder} selectedSize={_.size(containerSelectNames)} clickItem={clickItem} isCanvas={props.isCanvas} showName={props.showName} - disableDirectionKey={editorState?.isDragging || readOnly} + disableDirectionKey={isDragging || readOnly} > {itemViews} diff --git a/client/packages/lowcoder/src/comps/comps/containerComp/flowContainerView.tsx b/client/packages/lowcoder/src/comps/comps/containerComp/flowContainerView.tsx index 71bb7b83d8..f84c61d967 100644 --- a/client/packages/lowcoder/src/comps/comps/containerComp/flowContainerView.tsx +++ b/client/packages/lowcoder/src/comps/comps/containerComp/flowContainerView.tsx @@ -8,6 +8,7 @@ import { EditorContext } from "comps/editorState"; import { ThemeContext } from "comps/utils/themeContext"; import styled from "styled-components"; import { defaultTheme } from "@lowcoder-ee/constants/themeConstants"; +import { useEditorStore } from "comps/editorStore"; const FlowContainerWrapper = styled.div<{ $bgColor: string; $maxWidth?: number; $minHeight: string }>` background-color: ${(props) => props.$bgColor}; @@ -37,6 +38,7 @@ export function FlowContainerView( const layouts = props.layout; const { selectable, minHeight, maxWidth } = props; const editorState = useContext(EditorContext); + const selectedCompNames = useEditorStore((state) => state.selectedCompNames); const bgColor = (useContext(ThemeContext)?.theme || defaultTheme).canvas; return ( @@ -63,7 +65,7 @@ export function FlowContainerView( }} autoHeight={false} resizeHandles={[]} - isSelected={editorState.selectedCompNames.has(comp.name)} + isSelected={selectedCompNames.has(comp.name)} onClick={() => { editorState.setSelectedCompNames(new Set([comp.name])); }} diff --git a/client/packages/lowcoder/src/comps/comps/containerComp/pageLayoutComp.tsx b/client/packages/lowcoder/src/comps/comps/containerComp/pageLayoutComp.tsx index efa3dc6b3d..706c049c6f 100644 --- a/client/packages/lowcoder/src/comps/comps/containerComp/pageLayoutComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/containerComp/pageLayoutComp.tsx @@ -10,8 +10,8 @@ import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUt import { trans } from "i18n"; import { BoolCodeControl } from "comps/controls/codeControl"; import { DisabledContext } from "comps/generators/uiCompBuilder"; -import React, { useContext, useEffect, useState } from "react"; -import { EditorContext } from "comps/editorState"; +import { useState } from "react"; +import { useEditorStore } from "comps/editorStore"; import { ContainerChildren, @@ -38,9 +38,10 @@ export const ContainerBaseComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <> - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{disabledPropertyView(children)} {hiddenPropertyView(children)} @@ -48,7 +49,7 @@ export const ContainerBaseComp = (function () {
)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.container.getPropertyView()}
diff --git a/client/packages/lowcoder/src/comps/comps/containerComp/textContainerComp.tsx b/client/packages/lowcoder/src/comps/comps/containerComp/textContainerComp.tsx index 653363f017..f22d3acbb4 100644 --- a/client/packages/lowcoder/src/comps/comps/containerComp/textContainerComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/containerComp/textContainerComp.tsx @@ -21,8 +21,7 @@ import { dropdownControl } from "comps/controls/dropdownControl"; import { withDefault } from "comps/generators/simpleGenerators"; import { styleControl } from "comps/controls/styleControl"; import { AnimationStyle, TextContainerStyle } from "comps/controls/styleControlConstants"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { alignWithJustifyControl } from "comps/controls/alignControl"; const typeOptions = [ @@ -69,6 +68,7 @@ export const ContainerBaseComp = (function () { return ; }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -76,12 +76,12 @@ export const ContainerBaseComp = (function () { {children.text.propertyView({})}
- {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{hiddenPropertyView(children)}
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.container.getPropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/customComp/customComp.tsx b/client/packages/lowcoder/src/comps/comps/customComp/customComp.tsx index dd9d6489f5..83c217b1a4 100644 --- a/client/packages/lowcoder/src/comps/comps/customComp/customComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/customComp/customComp.tsx @@ -5,13 +5,13 @@ import { jsonObjectStateControl } from "comps/controls/codeStateControl"; import { UICompBuilder, withDefault } from "comps/generators"; import { NameConfig, NameConfigHidden, withExposingConfigs } from "comps/generators/withExposing"; import { Section, sectionNames } from "lowcoder-design"; -import { useEffect, useRef, useContext } from "react"; +import { useEffect, useRef } from "react"; import styled from "styled-components"; import { getPromiseAfterDispatch } from "util/promiseUtils"; import { EventData, EventTypeEnum } from "./types"; import { hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps/utils/propertyUtils"; import { trans } from "i18n"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { AnimationStyle, AnimationStyleType, CustomStyle, CustomStyleType } from "@lowcoder-ee/comps/controls/styleControlConstants"; import { styleControl } from "@lowcoder-ee/comps/controls/styleControl"; // TODO: eventually to embedd in container so we have styling? @@ -241,9 +241,10 @@ const CustomCompBase = new UICompBuilder(childrenMap, (props, dispatch) => { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <> - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{children.model.propertyView({ label: trans("customComp.data") })} {children.code.propertyView({ label: trans("customComp.code"), language: "html" })} diff --git a/client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx b/client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx index e26bf4ab69..643d6ea98b 100644 --- a/client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/dateComp/dateComp.tsx @@ -16,7 +16,7 @@ import { focusEvent, } from "../../controls/eventHandlerControl"; import { LabelControl } from "../../controls/labelControl"; -import { stringExposingStateControl } from "../../controls/codeStateControl"; +import { stringExposingStateControl, withLinkedDefaultValue } from "../../controls/codeStateControl"; import { UICompBuilder, withDefault } from "../../generators"; import { CommonNameConfig, depsConfig, withExposingConfigs } from "../../generators/withExposing"; import { formDataChildren, FormDataPropertyView } from "../formComp/formDataConstants"; @@ -39,7 +39,7 @@ import { } from "comps/utils/propertyUtils"; import { trans } from "i18n"; import { DATE_FORMAT, DATE_TIME_FORMAT, DateParser, PickerMode } from "util/dateTimeUtils"; -import React, { ReactNode, useContext, useEffect, useState } from "react"; +import React, { ReactNode, useEffect, useState } from "react"; import { IconControl } from "comps/controls/iconControl"; import { hasIcon } from "comps/utils"; import { Section, sectionNames } from "components/Section"; @@ -49,7 +49,7 @@ import { useIsMobile } from "util/hooks"; import { RefControl } from "comps/controls/refControl"; // import { CommonPickerMethods } from "antd/es/date-picker/generatePicker/interface"; import { DateRangeUIView } from "comps/comps/dateComp/dateRangeUIView"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { dropdownControl } from "comps/controls/dropdownControl"; import { timeZoneOptions } from "./timeZone"; import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators"; @@ -228,19 +228,14 @@ const getFormattedDate = ( } const DatePickerTmpCmp = new UICompBuilder(childrenMap, (props) => { - const defaultValue = { ...props.defaultValue }.value; const value = { ...props.value }.value; - + let time: dayjs.Dayjs | null = null; if (value !== '') { time = dayjs(value, DateParser); } - - const [tempValue, setTempValue] = useState(time); - useEffect(() => { - props.value.onChange(defaultValue); - }, [defaultValue]); + const [tempValue, setTempValue] = useState(time); useEffect(() => { const newValue = value ? dayjs(value, DateParser) : null; @@ -293,6 +288,7 @@ const DatePickerTmpCmp = new UICompBuilder(childrenMap, (props) => { }); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); const isMobile = useIsMobile(); return ( <> @@ -312,7 +308,7 @@ const DatePickerTmpCmp = new UICompBuilder(childrenMap, (props) => { - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{requiredPropertyView(children)} {children.showValidationWhenEmpty.propertyView({ @@ -333,24 +329,24 @@ const DatePickerTmpCmp = new UICompBuilder(childrenMap, (props) => { )} {/*{commonAdvanceSection(children, children.dateType.value === "date")}*/} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && children.label.getPropertyView()} + {(editorModeStatus === "layout" || editorModeStatus === "both") && children.label.getPropertyView()} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && (
{formatPropertyView({ children, placeholder: DATE_FORMAT })} {children.placeholder.propertyView({ label: trans("date.placeholderText") })}
)} - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{timeFields(children, isMobile)} {children.suffixIcon.propertyView({ label: trans("button.suffixIcon") })}
)} - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && !isMobile && commonAdvanceSection(children)} + {(editorModeStatus === "logic" || editorModeStatus === "both") && !isMobile && commonAdvanceSection(children)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.style.getPropertyView()} @@ -378,7 +374,10 @@ const DatePickerTmpCmp = new UICompBuilder(childrenMap, (props) => { .setExposeMethodConfigs(dateRefMethods) .build(); -export const datePickerControl = migrateOldData(DatePickerTmpCmp, fixOldInputCompData); +export const datePickerControl = migrateOldData( + withLinkedDefaultValue(DatePickerTmpCmp, "defaultValue", "value"), + fixOldInputCompData +); export function fixOldDateOrTimeRangeData(oldData: any) { if (!oldData) return oldData; @@ -412,17 +411,14 @@ let DateRangeTmpCmp = (function () { }; return new UICompBuilder(childrenMap, (props) => { - const defaultStart = { ...props.defaultStart }.value; const startValue = { ...props.start }.value; - - const defaultEnd = { ...props.defaultEnd }.value; const endValue = { ...props.end }.value; let start: dayjs.Dayjs | null = null; if (startValue !== '') { start = dayjs(startValue, DateParser); } - + let end: dayjs.Dayjs | null = null; if (endValue !== '') { end = dayjs(endValue, DateParser); @@ -431,14 +427,6 @@ let DateRangeTmpCmp = (function () { const [tempStartValue, setTempStartValue] = useState(start); const [tempEndValue, setTempEndValue] = useState(end); - useEffect(() => { - props.start.onChange(defaultStart); - }, [defaultStart]); - - useEffect(() => { - props.end.onChange(defaultEnd); - }, [defaultEnd]); - useEffect(() => { const value = startValue ? dayjs(startValue, DateParser) : null; setTempStartValue(value); @@ -510,6 +498,7 @@ let DateRangeTmpCmp = (function () { }); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); const isMobile = useIsMobile(); return ( <> @@ -534,7 +523,7 @@ let DateRangeTmpCmp = (function () { - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{requiredPropertyView(children)} {children.showValidationWhenEmpty.propertyView({ @@ -554,24 +543,24 @@ let DateRangeTmpCmp = (function () { )} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && children.label.getPropertyView()} + {(editorModeStatus === "layout" || editorModeStatus === "both") && children.label.getPropertyView()} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && (
{formatPropertyView({ children })} {children.placeholder.propertyView({ label: trans("date.placeholderText") })}
)} - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{timeFields(children, isMobile)} {children.suffixIcon.propertyView({ label: trans("button.suffixIcon") })}
)} - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && commonAdvanceSection(children)} + {(editorModeStatus === "logic" || editorModeStatus === "both") && commonAdvanceSection(children)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.style.getPropertyView()} @@ -597,7 +586,14 @@ let DateRangeTmpCmp = (function () { .build(); })(); -export const dateRangeControl = migrateOldData(DateRangeTmpCmp, fixOldDateOrTimeRangeData); +export const dateRangeControl = migrateOldData( + withLinkedDefaultValue( + withLinkedDefaultValue(DateRangeTmpCmp, "defaultStart", "start"), + "defaultEnd", + "end" + ), + fixOldDateOrTimeRangeData +); const getTimeZoneInfo = (timeZone: any, otherTimeZone: any) => { const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone; diff --git a/client/packages/lowcoder/src/comps/comps/dateComp/timeComp.tsx b/client/packages/lowcoder/src/comps/comps/dateComp/timeComp.tsx index c5b8ecc6b6..c3363fd611 100644 --- a/client/packages/lowcoder/src/comps/comps/dateComp/timeComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/dateComp/timeComp.tsx @@ -15,7 +15,7 @@ import { eventHandlerControl, focusEvent, } from "../../controls/eventHandlerControl"; -import { stringExposingStateControl } from "../../controls/codeStateControl"; +import { stringExposingStateControl, withLinkedDefaultValue } from "../../controls/codeStateControl"; import { LabelControl } from "../../controls/labelControl"; import { UICompBuilder, withDefault } from "../../generators"; import { @@ -42,7 +42,7 @@ import { } from "comps/utils/propertyUtils"; import { trans } from "i18n"; import { TIME_FORMAT, TimeParser } from "util/dateTimeUtils"; -import React, { ReactNode, useContext, useEffect, useState } from "react"; +import React, { ReactNode, useEffect, useState } from "react"; import { IconControl } from "comps/controls/iconControl"; import { hasIcon } from "comps/utils"; import { Section, sectionNames } from "components/Section"; @@ -53,7 +53,7 @@ import { RefControl } from "comps/controls/refControl"; // import { CommonPickerMethods } from "antd/es/date-picker/generatePicker/interface"; import { TimePickerProps } from "antd/es/time-picker"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { dropdownControl } from "comps/controls/dropdownControl"; import { timeZoneOptions } from "./timeZone"; import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators"; @@ -159,19 +159,14 @@ export type TimeCompViewProps = Pick< }; const TimePickerTmpCmp = new UICompBuilder(childrenMap, (props) => { - const defaultValue = { ...props.defaultValue }.value; const value = { ...props.value }.value; let time: dayjs.Dayjs | null = null; if(value !== '') { time = dayjs(value, TimeParser); } - - const [tempValue, setTempValue] = useState(time); - useEffect(() => { - props.value.onChange(defaultValue); - }, [defaultValue]); + const [tempValue, setTempValue] = useState(time); useEffect(() => { const newValue = value ? dayjs(value, TimeParser) : null; @@ -221,7 +216,9 @@ const TimePickerTmpCmp = new UICompBuilder(childrenMap, (props) => { ...validate(props), }); }) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.defaultValue.propertyView({ @@ -235,7 +232,7 @@ const TimePickerTmpCmp = new UICompBuilder(childrenMap, (props) => { - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{requiredPropertyView(children)} {children.showValidationWhenEmpty.propertyView({ @@ -254,15 +251,15 @@ const TimePickerTmpCmp = new UICompBuilder(childrenMap, (props) => {
)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && children.label.getPropertyView()} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && children.label.getPropertyView()} + {(editorModeStatus === "layout" || editorModeStatus === "both") && (
{formatPropertyView({ children, placeholder: TIME_FORMAT })} {children.placeholder.propertyView({ label: trans("time.placeholderText") })}
)} - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{commonAdvanceSection(children)} {children.use12Hours.propertyView({ label: trans("prop.use12Hours") })} @@ -270,7 +267,7 @@ const TimePickerTmpCmp = new UICompBuilder(childrenMap, (props) => {
)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.style.getPropertyView()} @@ -290,11 +287,15 @@ const TimePickerTmpCmp = new UICompBuilder(childrenMap, (props) => { )} - )) + ); + }) .setExposeMethodConfigs(dateRefMethods) .build(); -export const timePickerControl = migrateOldData(TimePickerTmpCmp, fixOldInputCompData); +export const timePickerControl = migrateOldData( + withLinkedDefaultValue(TimePickerTmpCmp, "defaultValue", "value"), + fixOldInputCompData +); const TimeRangeTmpCmp = (function () { const childrenMap = { @@ -308,10 +309,7 @@ const TimeRangeTmpCmp = (function () { }; return new UICompBuilder(childrenMap, (props) => { - const defaultStart = { ...props.defaultStart }.value; const startValue = { ...props.start }.value; - - const defaultEnd = { ...props.defaultEnd }.value; const endValue = { ...props.end }.value; let start: dayjs.Dayjs | null = null; @@ -326,14 +324,6 @@ const TimeRangeTmpCmp = (function () { const [tempStartValue, setTempStartValue] = useState(start); const [tempEndValue, setTempEndValue] = useState(end); - useEffect(() => { - props.start.onChange(defaultStart); - }, [defaultStart]); - - useEffect(() => { - props.end.onChange(defaultEnd); - }, [defaultEnd]); - useEffect(() => { const value = startValue ? dayjs(startValue, TimeParser) : null; setTempStartValue(value); @@ -395,7 +385,9 @@ const TimeRangeTmpCmp = (function () { : startResult), }); }) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.defaultStart.propertyView({ @@ -413,7 +405,7 @@ const TimeRangeTmpCmp = (function () { - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{requiredPropertyView(children)} {children.showValidationWhenEmpty.propertyView({ @@ -432,15 +424,15 @@ const TimeRangeTmpCmp = (function () {
)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && children.label.getPropertyView()} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && children.label.getPropertyView()} + {(editorModeStatus === "layout" || editorModeStatus === "both") && (
{formatPropertyView({ children, placeholder: TIME_FORMAT })} {children.placeholder.propertyView({ label: trans("time.placeholderText") })}
)} - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{commonAdvanceSection(children)} {children.use12Hours.propertyView({ label: trans("prop.use12Hours") })} @@ -448,7 +440,7 @@ const TimeRangeTmpCmp = (function () {
)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.style.getPropertyView()} @@ -468,11 +460,19 @@ const TimeRangeTmpCmp = (function () { )} - )) + ); + }) .build(); })(); -export const timeRangeControl = migrateOldData(TimeRangeTmpCmp, fixOldDateOrTimeRangeData); +export const timeRangeControl = migrateOldData( + withLinkedDefaultValue( + withLinkedDefaultValue(TimeRangeTmpCmp, "defaultStart", "start"), + "defaultEnd", + "end" + ), + fixOldDateOrTimeRangeData +); const getTimeZoneInfo = (timeZone: any, otherTimeZone: any) => { const tz = timeZone === 'UserChoice' ? otherTimeZone : timeZone; diff --git a/client/packages/lowcoder/src/comps/comps/dividerComp.tsx b/client/packages/lowcoder/src/comps/comps/dividerComp.tsx index 287b684091..2f0eccbc94 100644 --- a/client/packages/lowcoder/src/comps/comps/dividerComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/dividerComp.tsx @@ -15,8 +15,7 @@ import { trans } from "i18n"; import { AutoHeightControl } from "comps/controls/autoHeightControl"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; type IProps = DividerProps & { $style: DividerStyleType; @@ -124,6 +123,7 @@ const DividerTempComp = migrateOldData( ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <> {!children?.type?.getView() && @@ -131,13 +131,13 @@ const DividerTempComp = migrateOldData( {children.title.propertyView({ label: trans("divider.title") })}
} - {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{hiddenPropertyView(children)}
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{!_.isEmpty(children.title.getView()) && diff --git a/client/packages/lowcoder/src/comps/comps/fileComp/fileComp.tsx b/client/packages/lowcoder/src/comps/comps/fileComp/fileComp.tsx index b804c53410..7659056daf 100644 --- a/client/packages/lowcoder/src/comps/comps/fileComp/fileComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/fileComp/fileComp.tsx @@ -44,8 +44,7 @@ import { messageInstance } from "lowcoder-design/src/components/GlobalInstances" import { CustomModal } from "lowcoder-design"; import { DraggerUpload } from "./draggerUpload"; import { ImageCaptureModal } from "./ImageCaptureModal"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { checkIsMobile } from "@lowcoder-ee/util/commonUtils"; import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl"; @@ -515,7 +514,9 @@ let FileTmpComp = new UICompBuilder(childrenMap, (props, dispatch) => { return ; }) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.text.propertyView({ @@ -535,7 +536,7 @@ let FileTmpComp = new UICompBuilder(childrenMap, (props, dispatch) => { - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{children.uploadType.getView() !== "single" && children.maxFiles.propertyView({ label: trans("file.maxFiles") })} {commonValidationFields(children)} @@ -580,14 +581,15 @@ let FileTmpComp = new UICompBuilder(childrenMap, (props, dispatch) => { )} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.style.getPropertyView()}
{children.animationStyle.getPropertyView()}
)} - )) + ); + }) .build(); class FileImplComp extends FileTmpComp { diff --git a/client/packages/lowcoder/src/comps/comps/fileViewerComp.tsx b/client/packages/lowcoder/src/comps/comps/fileViewerComp.tsx index 159595231d..b2511f6d7a 100644 --- a/client/packages/lowcoder/src/comps/comps/fileViewerComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/fileViewerComp.tsx @@ -10,8 +10,7 @@ import { UICompBuilder, withDefault } from "../generators"; import { NameConfig, NameConfigHidden, withExposingConfigs } from "../generators/withExposing"; import { hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps/utils/propertyUtils"; import { trans } from "i18n"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { AutoHeightControl } from "../controls/autoHeightControl"; import { BoolControl } from "../controls/boolControl"; @@ -98,6 +97,7 @@ let FileViewerBasicComp = (function () { />; }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -109,7 +109,7 @@ let FileViewerBasicComp = (function () { })}
- {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{hiddenPropertyView(children)} {showDataLoadingIndicatorsPropertyView(children)} @@ -124,7 +124,7 @@ let FileViewerBasicComp = (function () { )}
- {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.style.getPropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/formComp/formComp.tsx b/client/packages/lowcoder/src/comps/comps/formComp/formComp.tsx index bece24fe23..bb5167b33a 100644 --- a/client/packages/lowcoder/src/comps/comps/formComp/formComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/formComp/formComp.tsx @@ -7,6 +7,7 @@ import { import { Section, sectionNames } from "lowcoder-design"; import { genQueryId } from "comps/utils/idGenerator"; import { CompNameContext, EditorContext, EditorState } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { withMethodExposing } from "comps/generators/withMethodExposing"; import { ContainerPlaceholder } from "lowcoder-design"; import { @@ -208,13 +209,14 @@ const FormBaseComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
{children.resetAfterSubmit.propertyView({ label: trans("formComp.resetAfterSubmit") })}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{children.onEvent.getPropertyView()} {disabledPropertyView(children)} @@ -225,7 +227,7 @@ const FormBaseComp = (function () { )} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.container.getPropertyView()} @@ -233,14 +235,14 @@ const FormBaseComp = (function () { )} - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{children.initialData.propertyView({ label: trans("formComp.initialData") })} {children.invalidFormMessage.propertyView({ label: trans("formComp.invalidFormMessage") })}
)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.container.stylePropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/iconComp.tsx b/client/packages/lowcoder/src/comps/comps/iconComp.tsx index 8cc3716e16..de467cd793 100644 --- a/client/packages/lowcoder/src/comps/comps/iconComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/iconComp.tsx @@ -29,8 +29,7 @@ import { eventHandlerControl, doubleClickEvent, } from "../controls/eventHandlerControl"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { AssetType, IconscoutControl } from "@lowcoder-ee/comps/controls/iconscoutControl"; import { dropdownControl } from "../controls/dropdownControl"; import { useCompClickEventHandler } from "../utils/useCompClickEventHandler"; @@ -150,7 +149,9 @@ const IconView = (props: RecordConstructorToView) => { let IconBasicComp = (function () { return new UICompBuilder(childrenMap, (props) => { return()}) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{ children.sourceMode.propertyView({ @@ -166,7 +167,7 @@ let IconBasicComp = (function () { })}
- {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{children.onEvent.getPropertyView()} {hiddenPropertyView(children)} @@ -174,7 +175,7 @@ let IconBasicComp = (function () {
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.autoHeight.propertyView({ label: trans("iconComp.autoSize"), @@ -193,7 +194,8 @@ let IconBasicComp = (function () { )} - )) + ); + }) .build(); })(); @@ -206,4 +208,3 @@ IconBasicComp = class extends IconBasicComp { export const IconComp = withExposingConfigs(IconBasicComp, [ NameConfigHidden, ]); - diff --git a/client/packages/lowcoder/src/comps/comps/iframeComp.tsx b/client/packages/lowcoder/src/comps/comps/iframeComp.tsx index c401653d16..9f18bd00a6 100644 --- a/client/packages/lowcoder/src/comps/comps/iframeComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/iframeComp.tsx @@ -10,8 +10,7 @@ import { hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps import { trans } from "i18n"; import log from "loglevel"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; const Wrapper = styled.div<{$style: IframeStyleType; $animationStyle:AnimationStyleType}>` width: 100%; @@ -67,13 +66,15 @@ let IFrameCompBase = new UICompBuilder( ); } ) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.url.propertyView({ label: "Source URL", placeholder: "https://example.com", tooltip: trans("iframe.URLDesc") })}
- {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{hiddenPropertyView(children)} {children.allowDownload.propertyView({ label: trans("iframe.allowDownload") })} @@ -85,7 +86,7 @@ let IFrameCompBase = new UICompBuilder(
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.style.getPropertyView()} @@ -96,7 +97,8 @@ let IFrameCompBase = new UICompBuilder( )} - )) + ); + }) .build(); IFrameCompBase = class extends IFrameCompBase { diff --git a/client/packages/lowcoder/src/comps/comps/imageComp.tsx b/client/packages/lowcoder/src/comps/comps/imageComp.tsx index 8bc246a2b1..450f356b70 100644 --- a/client/packages/lowcoder/src/comps/comps/imageComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/imageComp.tsx @@ -32,8 +32,7 @@ import { BoolControl } from "comps/controls/boolControl"; import { default as AntImage } from "antd/es/image"; import { DEFAULT_IMG_URL } from "util/stringUtils"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { StringControl } from "../controls/codeControl"; import { PositionControl } from "comps/controls/dropdownControl"; import { dropdownControl } from "../controls/dropdownControl"; @@ -246,6 +245,7 @@ let ImageBasicComp = new UICompBuilder(childrenMap, (props) => { return ; }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -259,7 +259,7 @@ let ImageBasicComp = new UICompBuilder(childrenMap, (props) => { {children.sourceMode.getView() === 'asset-library' && children.iconScoutAsset.propertyView({})}
- {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{children.onEvent.getPropertyView()} {hiddenPropertyView(children)} @@ -274,7 +274,7 @@ let ImageBasicComp = new UICompBuilder(childrenMap, (props) => {
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
diff --git a/client/packages/lowcoder/src/comps/comps/jsonComp/jsonEditorComp.tsx b/client/packages/lowcoder/src/comps/comps/jsonComp/jsonEditorComp.tsx index 8b1d4c8400..0b2fab07bb 100644 --- a/client/packages/lowcoder/src/comps/comps/jsonComp/jsonEditorComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/jsonComp/jsonEditorComp.tsx @@ -12,14 +12,14 @@ import { formDataChildren, FormDataPropertyView } from "../formComp/formDataCons import { AnimationStyle, JsonEditorStyle } from "comps/controls/styleControlConstants"; import { styleControl } from "comps/controls/styleControl"; import { migrateOldData, withDefault } from "comps/generators/simpleGenerators"; -import { useRef, useEffect, useContext, useCallback, useMemo } from "react"; +import { useRef, useEffect, useCallback, useMemo } from "react"; import { EditorState, EditorView, type EditorView as EditorViewType, } from "base/codeEditor/codeMirror"; import { useExtensions } from "base/codeEditor/extensions"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl"; import { BoolControl } from "@lowcoder-ee/comps/controls/boolControl"; @@ -177,9 +177,9 @@ let JsonEditorTmpComp = (function () { }); }) .setPropertyViewFn((children) => { - const editorContext = useContext(EditorContext); - const isLogicMode = editorContext.editorModeStatus === "logic" || editorContext.editorModeStatus === "both"; - const isLayoutMode = editorContext.editorModeStatus === "layout" || editorContext.editorModeStatus === "both"; + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + const isLogicMode = editorModeStatus === "logic" || editorModeStatus === "both"; + const isLayoutMode = editorModeStatus === "layout" || editorModeStatus === "both"; return ( <> diff --git a/client/packages/lowcoder/src/comps/comps/jsonComp/jsonExplorerComp.tsx b/client/packages/lowcoder/src/comps/comps/jsonComp/jsonExplorerComp.tsx index f929dd68ce..194c28d45f 100644 --- a/client/packages/lowcoder/src/comps/comps/jsonComp/jsonExplorerComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/jsonComp/jsonExplorerComp.tsx @@ -9,8 +9,8 @@ import { dropdownControl } from "comps/controls/dropdownControl"; import { ArrayOrJSONObjectControl, NumberControl } from "comps/controls/codeControl"; import { hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps/utils/propertyUtils"; import { trans } from "i18n"; -import { EditorContext } from "comps/editorState"; -import { useContext, useEffect } from "react"; +import { useEditorStore } from "comps/editorStore"; +import { useEffect } from "react"; import { AnimationStyle, AnimationStyleType } from "@lowcoder-ee/comps/controls/styleControlConstants"; import { styleControl } from "@lowcoder-ee/comps/controls/styleControl"; import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl"; @@ -80,6 +80,7 @@ let JsonExplorerTmpComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -96,7 +97,7 @@ let JsonExplorerTmpComp = (function () { })}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{hiddenPropertyView(children)} {children.expandToggle.propertyView({ label: trans("jsonExplorer.expandToggle") })} @@ -104,7 +105,7 @@ let JsonExplorerTmpComp = (function () {
)} - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{children.indent.propertyView({ label: trans("jsonExplorer.indent") })}
@@ -117,8 +118,8 @@ let JsonExplorerTmpComp = (function () { label: trans('prop.showVerticalScrollbar'), })}
} - {(useContext(EditorContext).editorModeStatus === 'layout' || - useContext(EditorContext).editorModeStatus === 'both') && ( + {(editorModeStatus === 'layout' || + editorModeStatus === 'both') && ( <>
{children.theme.propertyView({ diff --git a/client/packages/lowcoder/src/comps/comps/jsonComp/jsonLottieComp.tsx b/client/packages/lowcoder/src/comps/comps/jsonComp/jsonLottieComp.tsx index 92f3559368..977f30bc58 100644 --- a/client/packages/lowcoder/src/comps/comps/jsonComp/jsonLottieComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/jsonComp/jsonLottieComp.tsx @@ -10,7 +10,7 @@ import { styleControl } from "comps/controls/styleControl"; import { AnimationStyle, LottieStyle } from "comps/controls/styleControlConstants"; import { trans } from "i18n"; import { Section, sectionNames } from "lowcoder-design"; -import { useContext, lazy, useEffect, useState, useCallback } from "react"; +import { lazy, useEffect, useState, useCallback } from "react"; import { stateComp, UICompBuilder, withDefault } from "../../generators"; import { NameConfig, @@ -18,7 +18,7 @@ import { withExposingConfigs, } from "../../generators/withExposing"; import { defaultLottie } from "./jsonConstants"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { AssetType, IconscoutControl } from "@lowcoder-ee/comps/controls/iconscoutControl"; import { DotLottie } from "@lottiefiles/dotlottie-react"; import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl"; @@ -279,6 +279,7 @@ let JsonLottieTmpComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -292,7 +293,7 @@ let JsonLottieTmpComp = (function () { {children.sourceMode.getView() === 'asset-library' && children.iconScoutAsset.propertyView({})}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{children.onEvent.getPropertyView()} {children.speed.propertyView({ label: trans("jsonLottie.speed")})} @@ -305,7 +306,7 @@ let JsonLottieTmpComp = (function () { )} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && (
{children.autoHeight.getPropertyView()} {children.aspectRatio.propertyView({ @@ -316,7 +317,7 @@ let JsonLottieTmpComp = (function () {
)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.container.getPropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/jsonSchemaFormComp/jsonSchemaFormComp.tsx b/client/packages/lowcoder/src/comps/comps/jsonSchemaFormComp/jsonSchemaFormComp.tsx index d5c956b85c..74076e4ba4 100644 --- a/client/packages/lowcoder/src/comps/comps/jsonSchemaFormComp/jsonSchemaFormComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/jsonSchemaFormComp/jsonSchemaFormComp.tsx @@ -23,7 +23,7 @@ import { Theme } from "@rjsf/antd"; import { hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps/utils/propertyUtils"; import { AutoHeightControl } from "../../controls/autoHeightControl"; import { useContext, useEffect, useRef, useState, createContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import ObjectFieldTemplate from './ObjectFieldTemplate'; import ArrayFieldTemplate from './ArrayFieldTemplate'; import { Select } from 'antd'; @@ -373,6 +373,7 @@ let FormBasicComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); const formType = children.formType.getView(); const uiSchemaFieldDescription = formType === "rjsf" @@ -380,8 +381,8 @@ let FormBasicComp = (function () { : "JSONForms UI schema object for configuring controls, scopes, layouts, categories, rules, and renderer options. It should match the JSON Schema fields."; return ( <> - {(useContext(EditorContext).editorModeStatus === "logic" || - useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || + editorModeStatus === "both") && (
{children.formType.propertyView({ radioButton: true, @@ -514,7 +515,7 @@ let FormBasicComp = (function () {
)} - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{children.onEvent.getPropertyView()} {hiddenPropertyView(children)} @@ -524,7 +525,7 @@ let FormBasicComp = (function () { {showDataLoadingIndicatorsPropertyView(children)}
)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.autoHeight.getPropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/listViewComp/listView.tsx b/client/packages/lowcoder/src/comps/comps/listViewComp/listView.tsx index 4b62a66b93..5dec51164e 100644 --- a/client/packages/lowcoder/src/comps/comps/listViewComp/listView.tsx +++ b/client/packages/lowcoder/src/comps/comps/listViewComp/listView.tsx @@ -1,5 +1,6 @@ import { default as Pagination } from "antd/es/pagination"; import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { BackgroundColorContext } from "comps/utils/backgroundColorContext"; import _ from "lodash"; import { ConstructorToView } from "lowcoder-core"; @@ -319,7 +320,7 @@ export function ListView(props: Props) { const children = comp.children; const ref = useRef(null); const editorState = useContext(EditorContext); - const isDragging = editorState.isDragging; + const isDragging = useEditorStore((state) => state.isDragging); const [listHeight, setListHeight] = useDelayState(0, isDragging); const dynamicHeight = useMemo(() => children.dynamicHeight.getView(), [children.dynamicHeight]); const heightUnitOfRow = useMemo( @@ -375,7 +376,7 @@ export function ListView(props: Props) { const commonLayout = comp.realSimpleContainer()!.children.layout.getView(); const isOneItem = - pageInfo.currentPageSize > 0 && (_.isEmpty(commonLayout) || editorState.isDragging); + pageInfo.currentPageSize > 0 && (_.isEmpty(commonLayout) || isDragging); const noOfRows = isOneItem ? 1 : Math.floor((pageInfo.currentPageSize + noOfColumns - 1) / noOfColumns); diff --git a/client/packages/lowcoder/src/comps/comps/listViewComp/listViewPropertyView.tsx b/client/packages/lowcoder/src/comps/comps/listViewComp/listViewPropertyView.tsx index b3c3911ce1..05f8ea1ffa 100644 --- a/client/packages/lowcoder/src/comps/comps/listViewComp/listViewPropertyView.tsx +++ b/client/packages/lowcoder/src/comps/comps/listViewComp/listViewPropertyView.tsx @@ -2,8 +2,7 @@ import { trans, transToNode } from "i18n"; import { Section, sectionNames } from "lowcoder-design"; import { ListViewImplComp } from "./listViewComp"; import { ListCompType } from "./listViewUtils"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { disabledPropertyView, hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps/utils/propertyUtils"; type Props = { @@ -12,6 +11,7 @@ type Props = { export function listPropertyView(compType: ListCompType) { return (props: Props) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); const { comp } = props; const children = comp.children; return ( @@ -47,13 +47,13 @@ export function listPropertyView(compType: ListCompType) { })}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{comp.children.pagination.getPropertyView()}
)} - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{children.onEvent.getPropertyView()} {hiddenPropertyView(children)} @@ -64,7 +64,7 @@ export function listPropertyView(compType: ListCompType) {
)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.horizontalGridCells.propertyView({ label: trans('prop.horizontalGridCells'), diff --git a/client/packages/lowcoder/src/comps/comps/mediaComp/audioComp.tsx b/client/packages/lowcoder/src/comps/comps/mediaComp/audioComp.tsx index 9b64c1bbc2..e25f72f9f6 100644 --- a/client/packages/lowcoder/src/comps/comps/mediaComp/audioComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/mediaComp/audioComp.tsx @@ -13,8 +13,8 @@ import { withDefault } from "../../generators/simpleGenerators"; import { trans } from "i18n"; import { hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps/utils/propertyUtils"; import { mediaCommonChildren, mediaMethods } from "./mediaUtils"; -import { useContext, useEffect } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEffect } from "react"; +import { useEditorStore } from "comps/editorStore"; const Container = styled.div<{ $style: any; $animationStyle: AnimationStyleType }>` ${props => props.$style}; @@ -78,6 +78,7 @@ let AudioBasicComp = (function () { return ; }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -87,7 +88,7 @@ let AudioBasicComp = (function () { })}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{children.onEvent.getPropertyView()} {hiddenPropertyView(children)} diff --git a/client/packages/lowcoder/src/comps/comps/mediaComp/videoComp.tsx b/client/packages/lowcoder/src/comps/comps/mediaComp/videoComp.tsx index a4f5fb751e..ea7738035b 100644 --- a/client/packages/lowcoder/src/comps/comps/mediaComp/videoComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/mediaComp/videoComp.tsx @@ -21,8 +21,7 @@ import { Video } from "lowcoder-design"; import type ReactPlayer from "react-player"; import { mediaCommonChildren, mediaMethods } from "./mediaUtils"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import styled, { css } from "styled-components"; const EventOptions = [ @@ -132,6 +131,7 @@ let VideoBasicComp = (function () { return ; }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -141,7 +141,7 @@ let VideoBasicComp = (function () { })}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{children.onEvent.getPropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/meetingComp/controlButton.tsx b/client/packages/lowcoder/src/comps/comps/meetingComp/controlButton.tsx index c5e7709c97..337ef0d833 100644 --- a/client/packages/lowcoder/src/comps/comps/meetingComp/controlButton.tsx +++ b/client/packages/lowcoder/src/comps/comps/meetingComp/controlButton.tsx @@ -3,6 +3,7 @@ import { dropdownControl } from "comps/controls/dropdownControl"; import { ButtonEventHandlerControl } from "comps/controls/eventHandlerControl"; import { IconControl } from "comps/controls/iconControl"; import { CompNameContext, EditorContext, EditorState } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { withDefault } from "comps/generators"; import { UICompBuilder } from "comps/generators/uiCompBuilder"; import _ from "lodash"; @@ -38,7 +39,6 @@ import { import { useEffect, useRef, useState } from "react"; import { useResizeDetector } from "react-resize-detector"; -import { useContext } from "react"; import { Tooltip } from "antd"; import { AssetType, IconscoutControl } from "@lowcoder-ee/comps/controls/iconscoutControl"; import { useCompClickEventHandler } from "@lowcoder-ee/comps/utils/useCompClickEventHandler"; @@ -319,7 +319,9 @@ let ButtonTmpComp = (function () { ); }) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{ children.sourceMode.propertyView({ @@ -337,8 +339,8 @@ let ButtonTmpComp = (function () { })}
- {(useContext(EditorContext).editorModeStatus === "logic" || - useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || + editorModeStatus === "both") && (
{children.onEvent.getPropertyView()} {disabledPropertyView(children)} @@ -348,8 +350,8 @@ let ButtonTmpComp = (function () {
)} - {(useContext(EditorContext).editorModeStatus === "layout" || - useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || + editorModeStatus === "both") && ( <>
{children.autoHeight.getPropertyView()} @@ -369,7 +371,8 @@ let ButtonTmpComp = (function () { )} - )) + ); + }) .build(); })(); ButtonTmpComp = class extends ButtonTmpComp { diff --git a/client/packages/lowcoder/src/comps/comps/navComp/navComp.tsx b/client/packages/lowcoder/src/comps/comps/navComp/navComp.tsx index 41006481e5..7881c60668 100644 --- a/client/packages/lowcoder/src/comps/comps/navComp/navComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/navComp/navComp.tsx @@ -33,8 +33,8 @@ import { import { hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps/utils/propertyUtils"; import { trans } from "i18n"; -import { useContext, useState, useCallback } from "react"; -import { EditorContext } from "comps/editorState"; +import { useState, useCallback } from "react"; +import { useEditorStore } from "comps/editorStore"; import { createNavItemsControl } from "./components/NavItemsControl"; import { Layers } from "constants/Layers"; import { CanvasContainerID } from "constants/domLocators"; @@ -478,6 +478,23 @@ function renderStyleSections( ); } +function NavPropertyView({ childrenMap }: { childrenMap: any }) { + const mode = useEditorStore((state) => state.editorModeStatus); + const showLogic = mode === "logic" || mode === "both"; + const showLayout = mode === "layout" || mode === "both"; + const [styleSegment, setStyleSegment] = useState("normal"); + + return ( + <> + {renderBasicSection(childrenMap)} + {showLogic && renderInteractionSection(childrenMap)} + {showLayout && renderLayoutSection(childrenMap)} + {showLogic && renderAdvancedSection(childrenMap)} + {showLayout && renderStyleSections(childrenMap, styleSegment, setStyleSegment)} + + ); +} + const childrenMap = { logoUrl: StringControl, logoEvent: withDefault(eventHandlerControl(logoEventHandlers), [{ name: "click" }]), @@ -745,7 +762,7 @@ const NavCompBase = new UICompBuilder(childrenMap, (props) => { width={["left", "right"].includes(props.placement as any) ? transToPxSize(props.drawerWidth || DEFAULT_SIZE) : undefined as any} height={["top", "bottom"].includes(props.placement as any) ? transToPxSize(props.drawerHeight || DEFAULT_SIZE) : undefined as any} styles={{ body: { padding: 0 } }} - destroyOnClose + destroyOnHidden > { ); }) - .setPropertyViewFn((children) => { - const mode = useContext(EditorContext).editorModeStatus; - const showLogic = mode === "logic" || mode === "both"; - const showLayout = mode === "layout" || mode === "both"; - const [styleSegment, setStyleSegment] = useState("normal"); - - return ( - <> - {renderBasicSection(children)} - {showLogic && renderInteractionSection(children)} - {showLayout && renderLayoutSection(children)} - {showLogic && renderAdvancedSection(children)} - {showLayout && renderStyleSections(children, styleSegment, setStyleSegment)} - - ); - }) + .setPropertyViewFn((children) => ) .build(); export const NavComp = withExposingConfigs(NavCompBase, [ diff --git a/client/packages/lowcoder/src/comps/comps/numberInputComp/numberInputComp.tsx b/client/packages/lowcoder/src/comps/comps/numberInputComp/numberInputComp.tsx index fad9d36d14..310f5fab4e 100644 --- a/client/packages/lowcoder/src/comps/comps/numberInputComp/numberInputComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/numberInputComp/numberInputComp.tsx @@ -50,9 +50,9 @@ import { setSelectionRangeMethod, } from "comps/utils/methodUtils"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { migrateOldData } from "comps/generators/simpleGenerators"; +import { withLinkedDefaultValue } from "comps/controls/codeStateControl"; import { fixOldInputCompData } from "../textInputComp/textInputConstants"; const getStyle = (style: InputLikeStyleType) => { @@ -311,7 +311,6 @@ const childrenMap = { const CustomInputNumber = (props: RecordConstructorToView) => { const ref = useRef(null); - const defaultValue = props.defaultValue.value; const mountedRef = useRef(true); // Cleanup on unmount @@ -322,17 +321,6 @@ const CustomInputNumber = (props: RecordConstructorToView) = }; }, []); - useEffect(() => { - if (!mountedRef.current) return; - let value = 0; - if (defaultValue === 'null' && props.allowNull) { - value = NaN; - } else if (!isNaN(Number(defaultValue))) { - value = Number(defaultValue); - } - props.value.onChange(value); - }, [defaultValue, props.allowNull]); - const formatFn = (value: number) => format(value, props.allowNull, props.formatter, props.precision, props.thousandsSeparator); @@ -448,7 +436,9 @@ let NumberInputTmpComp = (function () { ...validate(props), }); }) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.defaultValue.propertyView({ label: trans("prop.defaultValue") })} @@ -458,7 +448,7 @@ let NumberInputTmpComp = (function () { - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && ( <>
{requiredPropertyView(children)} {children.showValidationWhenEmpty.propertyView({label: trans("prop.showEmptyValidation")})} @@ -475,11 +465,11 @@ let NumberInputTmpComp = (function () { )} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( children.label.getPropertyView() )} - {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{children.step.propertyView({ label: trans("numberInput.step") })} {children.precision.propertyView({ label: trans("numberInput.precision") })} @@ -494,7 +484,7 @@ let NumberInputTmpComp = (function () {
)} - {(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || editorModeStatus === "both") && ( <>
{children.style.getPropertyView()} @@ -514,11 +504,24 @@ let NumberInputTmpComp = (function () { )} - )) + ); + }) .build(); })(); -NumberInputTmpComp = migrateOldData(NumberInputTmpComp, fixOldInputCompData); +NumberInputTmpComp = migrateOldData( + withLinkedDefaultValue(NumberInputTmpComp, "defaultValue", "value", (defaultValue: any, comp: any) => { + const allowNull = comp.children.allowNull?.getView?.(); + if (defaultValue === "null" && allowNull) { + return NaN; + } + if (!isNaN(Number(defaultValue))) { + return Number(defaultValue); + } + return 0; + }), + fixOldInputCompData +); const NumberInputTmp2Comp = withMethodExposing( NumberInputTmpComp, diff --git a/client/packages/lowcoder/src/comps/comps/numberInputComp/sliderCompConstants.tsx b/client/packages/lowcoder/src/comps/comps/numberInputComp/sliderCompConstants.tsx index c2a45c121a..c20b03bf10 100644 --- a/client/packages/lowcoder/src/comps/comps/numberInputComp/sliderCompConstants.tsx +++ b/client/packages/lowcoder/src/comps/comps/numberInputComp/sliderCompConstants.tsx @@ -12,8 +12,8 @@ import { darkenColor, fadeColor } from "lowcoder-design"; import { disabledPropertyView, hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps/utils/propertyUtils"; import { IconControl } from "comps/controls/iconControl"; import { trans } from "i18n"; -import { memo, useCallback, useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { memo, useCallback } from "react"; +import { useEditorStore } from "comps/editorStore"; const getStyle = (style: SliderStyleType, vertical: boolean, disabledStyle?: DisabledSliderStyleType) => { return css` @@ -112,7 +112,7 @@ export const SliderChildren = { }; const InteractionSection = memo(({ children }: { children: RecordConstructorToComp }) => { - const editorModeStatus = useContext(EditorContext).editorModeStatus; + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); if (!["logic", "both"].includes(editorModeStatus)) { return null; @@ -130,7 +130,7 @@ const InteractionSection = memo(({ children }: { children: RecordConstructorToCo }); const LayoutSection = memo(({ children }: { children: RecordConstructorToComp }) => { - const editorModeStatus = useContext(EditorContext).editorModeStatus; + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); if (!["layout", "both"].includes(editorModeStatus)) { return null; diff --git a/client/packages/lowcoder/src/comps/comps/progressCircleComp.tsx b/client/packages/lowcoder/src/comps/comps/progressCircleComp.tsx index e4e70a6327..1f3fa50e8f 100644 --- a/client/packages/lowcoder/src/comps/comps/progressCircleComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/progressCircleComp.tsx @@ -11,8 +11,7 @@ import { trans } from "i18n"; import { BoolControl } from "../controls/boolControl"; import { dropdownControl } from "../controls/dropdownControl"; import { NumberControl } from "../controls/codeControl"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { ProgressTypeOptions, StrokeLinecapOptions, @@ -118,6 +117,7 @@ let ProgressCircleTmpComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); const progressType = children.progressType.getView(); const stepsEnabled = children.stepsEnabled.getView(); @@ -184,13 +184,13 @@ let ProgressCircleTmpComp = (function () {
)} - {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{hiddenPropertyView(children)}
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.style.getPropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/progressComp.tsx b/client/packages/lowcoder/src/comps/comps/progressComp.tsx index 1863c01508..4c449465a0 100644 --- a/client/packages/lowcoder/src/comps/comps/progressComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/progressComp.tsx @@ -10,8 +10,7 @@ import styled, { css } from "styled-components"; import { hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps/utils/propertyUtils"; import { trans } from "i18n"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; const getStyle = (style: ProgressStyleType) => { return css` @@ -67,6 +66,7 @@ const ProgressBasicComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -76,7 +76,7 @@ const ProgressBasicComp = (function () { })}
- {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{hiddenPropertyView(children)} {children.showInfo.propertyView({ @@ -86,7 +86,7 @@ const ProgressBasicComp = (function () {
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.style.getPropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/qrCodeComp.tsx b/client/packages/lowcoder/src/comps/comps/qrCodeComp.tsx index 1836bfe9e9..5b35a875a4 100644 --- a/client/packages/lowcoder/src/comps/comps/qrCodeComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/qrCodeComp.tsx @@ -12,8 +12,8 @@ import { hiddenPropertyView } from "comps/utils/propertyUtils"; import { trans } from "i18n"; import { StringControl } from "comps/controls/codeControl"; -import { useContext, useEffect } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEffect } from "react"; +import { useEditorStore } from "comps/editorStore"; import { withDefault } from "../generators"; // TODO: add styling for image (size) @@ -80,7 +80,9 @@ const QRCodeView = (props: RecordConstructorToView) => { let QRCodeBasicComp = (function () { return new UICompBuilder(childrenMap, (props) => { return( )}) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.value.propertyView({ @@ -90,7 +92,7 @@ let QRCodeBasicComp = (function () { })}
- {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && ( <>
{hiddenPropertyView(children)}
@@ -107,7 +109,7 @@ let QRCodeBasicComp = (function () { )} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.style.getPropertyView()} @@ -119,7 +121,8 @@ let QRCodeBasicComp = (function () { )} - )) + ); + }) .build(); })(); diff --git a/client/packages/lowcoder/src/comps/comps/ratingComp.tsx b/client/packages/lowcoder/src/comps/comps/ratingComp.tsx index 025453c256..9e29e9c81f 100644 --- a/client/packages/lowcoder/src/comps/comps/ratingComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/ratingComp.tsx @@ -12,11 +12,12 @@ import { formDataChildren, FormDataPropertyView } from "./formComp/formDataConst import { styleControl } from "comps/controls/styleControl"; import { AnimationStyle, InputFieldStyle, LabelStyle, RatingStyle, RatingStyleType } from "comps/controls/styleControlConstants"; import { migrateOldData } from "comps/generators/simpleGenerators"; +import { withLinkedDefaultValue } from "comps/controls/codeStateControl"; import { disabledPropertyView, hiddenPropertyView, showDataLoadingIndicatorsPropertyView } from "comps/utils/propertyUtils"; import { trans } from "i18n"; -import { useContext, useEffect, useRef } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEffect, useRef } from "react"; +import { useEditorStore } from "comps/editorStore"; const EventOptions = [changeEvent] as const; @@ -56,7 +57,6 @@ const RatingBasicComp = (function () { ...formDataChildren, }; return new UICompBuilder(childrenMap, (props) => { - const defaultValue = { ...props.defaultValue }.value; const value = { ...props.value }.value; const changeRef = useRef(false); const mountedRef = useRef(true); @@ -78,10 +78,6 @@ const RatingBasicComp = (function () { }; }, []); - useEffect(() => { - props.value.onChange(defaultValue); - }, [defaultValue]); - useEffect(() => { if (!changeRef.current) return; @@ -113,6 +109,7 @@ const RatingBasicComp = (function () { }); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -124,7 +121,7 @@ const RatingBasicComp = (function () { - {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && ( <>
{children.onEvent.getPropertyView()} {disabledPropertyView(children)} @@ -140,11 +137,11 @@ const RatingBasicComp = (function () { )} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( children.label.getPropertyView() )} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.style.getPropertyView()} @@ -166,11 +163,14 @@ const RatingBasicComp = (function () { .build(); })(); -export const RatingComp = withExposingConfigs(RatingBasicComp, [ - new NameConfig("value", trans("export.ratingValueDesc")), - new NameConfig("max", trans("export.ratingMaxDesc")), - ...CommonNameConfig, -]); +export const RatingComp = withExposingConfigs( + withLinkedDefaultValue(RatingBasicComp, "defaultValue", "value"), + [ + new NameConfig("value", trans("export.ratingValueDesc")), + new NameConfig("max", trans("export.ratingMaxDesc")), + ...CommonNameConfig, + ] +); const getStyle = (style: RatingStyleType) => { return css` diff --git a/client/packages/lowcoder/src/comps/comps/responsiveLayout/responsiveLayout.tsx b/client/packages/lowcoder/src/comps/comps/responsiveLayout/responsiveLayout.tsx index e4a7fd0b57..1c4ad81b89 100644 --- a/client/packages/lowcoder/src/comps/comps/responsiveLayout/responsiveLayout.tsx +++ b/client/packages/lowcoder/src/comps/comps/responsiveLayout/responsiveLayout.tsx @@ -37,8 +37,7 @@ import { messageInstance } from "lowcoder-design/src/components/GlobalInstances" import { BoolControl } from "comps/controls/boolControl"; import { BoolCodeControl, NumberControl } from "comps/controls/codeControl"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUtils"; import { DisabledContext } from "comps/generators/uiCompBuilder"; @@ -292,6 +291,7 @@ export const ResponsiveLayoutBaseComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -301,14 +301,14 @@ export const ResponsiveLayoutBaseComp = (function () { })}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{disabledPropertyView(children)} {hiddenPropertyView(children)}
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.autoHeight.getPropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/richTextEditorComp.tsx b/client/packages/lowcoder/src/comps/comps/richTextEditorComp.tsx index 979b7fbfa3..6eece5b864 100644 --- a/client/packages/lowcoder/src/comps/comps/richTextEditorComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/richTextEditorComp.tsx @@ -25,8 +25,7 @@ import { default as Skeleton } from "antd/es/skeleton"; import { styleControl } from "comps/controls/styleControl"; import { RichTextEditorStyle, RichTextEditorStyleType } from "comps/controls/styleControlConstants"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; const localizeStyle = css` & .ql-snow { @@ -400,6 +399,7 @@ const RichTextEditorCompBase = new UICompBuilder(childrenMap, (props) => { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -409,7 +409,7 @@ const RichTextEditorCompBase = new UICompBuilder(childrenMap, (props) => { - {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{children.onEvent.getPropertyView()} {hiddenPropertyView(children)} @@ -419,7 +419,7 @@ const RichTextEditorCompBase = new UICompBuilder(childrenMap, (props) => {
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.autoHeight.getPropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/rootComp.tsx b/client/packages/lowcoder/src/comps/comps/rootComp.tsx index 3c663028d7..8c63a97ea3 100644 --- a/client/packages/lowcoder/src/comps/comps/rootComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/rootComp.tsx @@ -8,7 +8,7 @@ import { HookListComp } from "comps/hooks/hookListComp"; import { QueryListComp } from "comps/queries/queryComp"; import { NameAndExposingInfo } from "comps/utils/exposingTypes"; import { handlePromiseAndDispatch } from "util/promiseUtils"; -import { HTMLAttributes, Suspense, lazy, useContext, useEffect, useMemo, useRef, useState } from "react"; +import { HTMLAttributes, Suspense, lazy, useContext, useMemo, useState } from "react"; import { setFieldsNoTypeCheck } from "util/objectUtils"; import { AppSettingsComp } from "./appSettingsComp"; import { PreloadComp } from "./preLoadComp"; @@ -24,11 +24,6 @@ import { getGlobalSettings } from "comps/utils/globalSettings"; import { getCurrentTheme } from "comps/utils/themeUtil"; import { DataChangeResponderListComp } from "./dataChangeResponderComp"; import { FolderListComp } from "./folderListComp"; -import { - PropertySectionContext, - PropertySectionContextType, - PropertySectionState, -} from "lowcoder-design"; import RefTreeComp from "./refTreeComp"; import { ExternalEditorContext } from "util/context/ExternalEditorContext"; import { useUserViewMode } from "util/hooks"; @@ -36,8 +31,9 @@ import React from "react"; import { isEqual } from "lodash"; import {LoadingBarHideTrigger} from "@lowcoder-ee/util/hideLoading"; import clsx from "clsx"; -import { useUnmount } from "react-use"; import { AIHelperModal, AIHelperProvider } from "components/ai-helper"; +import { createEditorStore, EditorStoreProvider } from "comps/editorStore"; +import { EditorPropertySectionProvider } from "comps/editorPropertySectionContext"; const EditorView = lazy( () => import("pages/editor/editorView"), @@ -64,13 +60,20 @@ const childrenMap = { const RootView = React.memo((props: RootViewProps) => { const previewTheme = useContext(ThemeContext); const { comp, isModuleRoot, ...divProps } = props; - const [editorState, setEditorState] = useState(); - const [propertySectionState, setPropertySectionState] = useState({}); + const [editorStore] = useState(createEditorStore); + const [editorState, setEditorState] = useState( + () => + new EditorState( + comp, + (changeEditorStateFn) => { + setEditorState(changeEditorStateFn); + }, + isModuleRoot, + editorStore + ) + ); const { readOnly } = useContext(ExternalEditorContext); const isUserViewMode = useUserViewMode(); - const mountedRef = useRef(true); - const editorStateRef = useRef(); - const prevCompRef = useRef(comp); const appThemeId = comp.children.settings.getView().themeId; const { orgCommonSettings } = getGlobalSettings(); @@ -86,48 +89,13 @@ const RootView = React.memo((props: RootViewProps) => { previewTheme?.previewTheme ? "preview-theme" : 'default-theme-id' ); - useEffect(() => { - return () => { - mountedRef.current = false; - }; - }, []); - - useEffect(() => { - if (!mountedRef.current) return; - - const newEditorState = new EditorState(comp, (changeEditorStateFn) => { - if (mountedRef.current) { - setEditorState((oldState) => { - return (oldState ? changeEditorStateFn(oldState) : undefined) - }); - } - }, undefined, isModuleRoot); - editorStateRef.current = newEditorState; - setEditorState(newEditorState); - - return () => { - if (editorStateRef.current) { - editorStateRef.current = undefined; - } - }; - }, [isModuleRoot]); - - useEffect(() => { - if (!mountedRef.current || !editorState) return; - - if (prevCompRef.current !== comp) { - editorState.setComp(() => comp); - prevCompRef.current = comp; - } - }, [comp, editorState]); - - useUnmount(() => { - setEditorState(undefined); - setPropertySectionState({}); - if (editorStateRef.current) { - editorStateRef.current = undefined; - } - }); + const currentEditorState = useMemo( + () => + editorState.rootComp === comp + ? editorState + : setFieldsNoTypeCheck(editorState, { rootComp: comp }), + [comp, editorState] + ); const themeContextValue = useMemo( () => ({ @@ -137,57 +105,32 @@ const RootView = React.memo((props: RootViewProps) => { [theme, themeId] ); - const propertySectionContextValue = useMemo(() => { - const compName = Object.keys(editorState?.selectedComps() || {})[0]; - return { - compName, - state: propertySectionState, - toggle: (compName: string, sectionName: string) => { - if (!mountedRef.current) return; - - setPropertySectionState((oldState) => { - const nextSectionState: PropertySectionState = { ...oldState }; - const compState = nextSectionState[compName] || {}; - compState[sectionName] = compState[sectionName] === false; - nextSectionState[compName] = compState; - return nextSectionState; - }); - }, - }; - }, [editorState, propertySectionState]); - - if (!editorState && !isUserViewMode && readOnly) { - return ; - } - const SuspenseFallback = isModuleRoot ? : ; - if (!editorState) { - return SuspenseFallback; - } - return (
- - - - - {Object.keys(comp.children.queries.children).map((key) => ( -
{comp.children.queries.children[key].getView()}
- ))} - - - - - {!readOnly && !isUserViewMode && !isModuleRoot && } -
-
-
-
+ + + + + + {Object.keys(comp.children.queries.children).map((key) => ( +
{comp.children.queries.children[key].getView()}
+ ))} + + + + + {!readOnly && !isUserViewMode && !isModuleRoot && } +
+
+
+
+
); }, (prevProps, nextProps) => { @@ -203,7 +146,6 @@ export class RootComp extends RootCompBase { preloaded = false; preloadId = ""; isModuleRoot = false; - private editorStateRef?: EditorState; getView() { if (!this.preloaded) { @@ -214,7 +156,6 @@ export class RootComp extends RootCompBase { clearPreload() { this.children.preload.clear(); - this.editorStateRef = undefined; } setModuleRoot(moduleRoot: boolean) { diff --git a/client/packages/lowcoder/src/comps/comps/selectInputComp/cascaderContants.tsx b/client/packages/lowcoder/src/comps/comps/selectInputComp/cascaderContants.tsx index d88289c880..b61b2ed508 100644 --- a/client/packages/lowcoder/src/comps/comps/selectInputComp/cascaderContants.tsx +++ b/client/packages/lowcoder/src/comps/comps/selectInputComp/cascaderContants.tsx @@ -22,8 +22,7 @@ import { CascaderRef } from "antd/es/cascader"; import { MarginControl } from "../../controls/marginControl"; import { PaddingControl } from "../../controls/paddingControl"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; export const defaultDataSource = JSON.stringify(i18nObjs.cascader, null, " "); @@ -49,7 +48,9 @@ export const CascaderChildren = { export const CascaderPropertyView = ( children: RecordConstructorToComp -) => ( +) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.options.propertyView({ label: trans("cascader.options") })} @@ -57,7 +58,7 @@ export const CascaderPropertyView = ( {placeholderPropertyView(children)}
- {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{children.onEvent.getPropertyView()} {disabledPropertyView(children)} @@ -67,18 +68,18 @@ export const CascaderPropertyView = (
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( children.label.getPropertyView() )} - {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{allowClearPropertyView(children)} {showSearchPropertyView(children)}
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.style.getPropertyView()} @@ -99,3 +100,4 @@ export const CascaderPropertyView = ( )} ); +}; diff --git a/client/packages/lowcoder/src/comps/comps/selectInputComp/checkboxComp.tsx b/client/packages/lowcoder/src/comps/comps/selectInputComp/checkboxComp.tsx index 6f3cfec54b..6226b7083a 100644 --- a/client/packages/lowcoder/src/comps/comps/selectInputComp/checkboxComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/selectInputComp/checkboxComp.tsx @@ -23,6 +23,7 @@ import { EllipsisTextCss } from "lowcoder-design"; import { trans } from "i18n"; import { RefControl } from "comps/controls/refControl"; import { migrateOldData } from "comps/generators/simpleGenerators"; +import { withLinkedDefaultValue } from "comps/controls/codeStateControl"; import { fixOldInputCompData } from "../textInputComp/textInputConstants"; import Tooltip from "antd/es/tooltip"; import { useCallback, useRef, useEffect, memo } from "react"; @@ -281,7 +282,10 @@ let CheckboxBasicComp = (function () { .build(); })(); -CheckboxBasicComp = migrateOldData(CheckboxBasicComp, fixOldInputCompData); +CheckboxBasicComp = migrateOldData( + withLinkedDefaultValue(CheckboxBasicComp, "defaultValue", "value"), + fixOldInputCompData +); export const CheckboxComp = withExposingConfigs(CheckboxBasicComp, [ new NameConfig("value", trans("selectInput.valueDesc")), diff --git a/client/packages/lowcoder/src/comps/comps/selectInputComp/multiSelectComp.tsx b/client/packages/lowcoder/src/comps/comps/selectInputComp/multiSelectComp.tsx index 2527d57bd4..9cac2ca2ac 100644 --- a/client/packages/lowcoder/src/comps/comps/selectInputComp/multiSelectComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/selectInputComp/multiSelectComp.tsx @@ -15,6 +15,7 @@ import { SelectInputInvalidConfig, useSelectInputValidate } from "./selectInputC import { PaddingControl } from "../../controls/paddingControl"; import { MarginControl } from "../../controls/marginControl"; import { migrateOldData } from "comps/generators/simpleGenerators"; +import { withLinkedDefaultValue } from "comps/controls/codeStateControl"; import { fixOldInputCompData } from "../textInputComp/textInputConstants"; let MultiSelectBasicComp = (function () { @@ -63,7 +64,10 @@ let MultiSelectBasicComp = (function () { .build(); })(); -MultiSelectBasicComp = migrateOldData(MultiSelectBasicComp, fixOldInputCompData); +MultiSelectBasicComp = migrateOldData( + withLinkedDefaultValue(MultiSelectBasicComp, "defaultValue", "value"), + fixOldInputCompData +); export const MultiSelectComp = withExposingConfigs(MultiSelectBasicComp, [ new NameConfig("value", trans("selectInput.valueDesc")), diff --git a/client/packages/lowcoder/src/comps/comps/selectInputComp/radioComp.tsx b/client/packages/lowcoder/src/comps/comps/selectInputComp/radioComp.tsx index 28d5d6f3db..7d4e680957 100644 --- a/client/packages/lowcoder/src/comps/comps/selectInputComp/radioComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/selectInputComp/radioComp.tsx @@ -13,6 +13,7 @@ import { EllipsisTextCss, ValueFromOption } from "lowcoder-design"; import { trans } from "i18n"; import { fixOldInputCompData } from "../textInputComp/textInputConstants"; import { migrateOldData } from "comps/generators/simpleGenerators"; +import { withLinkedDefaultValue } from "comps/controls/codeStateControl"; import Tooltip from "antd/es/tooltip"; import { useCallback, useRef, useEffect, memo } from "react"; @@ -215,7 +216,10 @@ let RadioBasicComp = (function () { .build(); })(); -RadioBasicComp = migrateOldData(RadioBasicComp, fixOldInputCompData); +RadioBasicComp = migrateOldData( + withLinkedDefaultValue(RadioBasicComp, "defaultValue", "value"), + fixOldInputCompData +); export const RadioComp = withExposingConfigs(RadioBasicComp, [ new NameConfig("value", trans("selectInput.valueDesc")), diff --git a/client/packages/lowcoder/src/comps/comps/selectInputComp/radioCompConstants.tsx b/client/packages/lowcoder/src/comps/comps/selectInputComp/radioCompConstants.tsx index 25efd5ef75..57e097d69e 100644 --- a/client/packages/lowcoder/src/comps/comps/selectInputComp/radioCompConstants.tsx +++ b/client/packages/lowcoder/src/comps/comps/selectInputComp/radioCompConstants.tsx @@ -20,8 +20,7 @@ import { hiddenPropertyView, disabledPropertyView, showDataLoadingIndicatorsProp import { trans } from "i18n"; import { RefControl } from "comps/controls/refControl"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { withDefault } from "@lowcoder-ee/comps/generators"; export const RadioLayoutOptions = [ @@ -59,14 +58,16 @@ export const RadioPropertyView = ( | ReturnType; } > -) => ( +) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.options.propertyView({})} {children.defaultValue.propertyView({ label: trans("prop.defaultValue") })}
- {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && ( <>
@@ -79,7 +80,7 @@ export const RadioPropertyView = ( )} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && (
{children.layout.propertyView({ label: trans("radio.options"), @@ -94,11 +95,11 @@ export const RadioPropertyView = (
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( children.label.getPropertyView() )} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.style.getPropertyView()}
{children.labelStyle.getPropertyView()}
@@ -108,3 +109,4 @@ export const RadioPropertyView = ( )} ); +}; diff --git a/client/packages/lowcoder/src/comps/comps/selectInputComp/segmentedControl.tsx b/client/packages/lowcoder/src/comps/comps/selectInputComp/segmentedControl.tsx index 78724cab55..9a37648bc7 100644 --- a/client/packages/lowcoder/src/comps/comps/selectInputComp/segmentedControl.tsx +++ b/client/packages/lowcoder/src/comps/comps/selectInputComp/segmentedControl.tsx @@ -23,9 +23,10 @@ import { trans } from "i18n"; import { hasIcon } from "comps/utils"; import { RefControl } from "comps/controls/refControl"; -import { useContext, useEffect } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEffect } from "react"; +import { useEditorStore } from "comps/editorStore"; import { migrateOldData, withDefault } from "comps/generators/simpleGenerators"; +import { withLinkedDefaultValue } from "comps/controls/codeStateControl"; import { fixOldInputCompData } from "../textInputComp/textInputConstants"; const getStyle = (style: SegmentStyleType) => { @@ -119,14 +120,16 @@ let SegmentedControlBasicComp = (function () { ...validateState, }); }) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.options.propertyView({})} {children.defaultValue.propertyView({ label: trans("prop.defaultValue") })}
- {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && ( <>
@@ -136,11 +139,11 @@ let SegmentedControlBasicComp = (function () {
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( children.label.getPropertyView() )} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.style.getPropertyView()} @@ -154,12 +157,16 @@ let SegmentedControlBasicComp = (function () { )} - )) + ); + }) .setExposeMethodConfigs(selectDivRefMethods) .build(); })(); -SegmentedControlBasicComp = migrateOldData(SegmentedControlBasicComp, fixOldInputCompData); +SegmentedControlBasicComp = migrateOldData( + withLinkedDefaultValue(SegmentedControlBasicComp, "defaultValue", "value"), + fixOldInputCompData +); export const SegmentedControlComp = withExposingConfigs(SegmentedControlBasicComp, [ new NameConfig("value", trans("selectInput.valueDesc")), diff --git a/client/packages/lowcoder/src/comps/comps/selectInputComp/selectComp.tsx b/client/packages/lowcoder/src/comps/comps/selectInputComp/selectComp.tsx index a2415b4a58..662a7b5ab6 100644 --- a/client/packages/lowcoder/src/comps/comps/selectInputComp/selectComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/selectInputComp/selectComp.tsx @@ -15,10 +15,11 @@ import { SelectInputInvalidConfig, useSelectInputValidate, } from "./selectInputConstants"; -import { useContext, useEffect, useRef } from "react"; +import { useEffect, useRef } from "react"; import { RecordConstructorToView } from "lowcoder-core"; import { fixOldInputCompData } from "../textInputComp/textInputConstants"; import { migrateOldData, withDefault } from "comps/generators/simpleGenerators"; +import { withLinkedDefaultValue } from "comps/controls/codeStateControl"; let SelectBasicComp = (function () { const childrenMap = { @@ -64,7 +65,10 @@ let SelectBasicComp = (function () { .build(); })(); -SelectBasicComp = migrateOldData(SelectBasicComp, fixOldInputCompData); +SelectBasicComp = migrateOldData( + withLinkedDefaultValue(SelectBasicComp, "defaultValue", "value"), + fixOldInputCompData +); export const SelectComp = withExposingConfigs(SelectBasicComp, [ new NameConfig("value", trans("selectInput.valueDesc")), diff --git a/client/packages/lowcoder/src/comps/comps/selectInputComp/selectCompConstants.tsx b/client/packages/lowcoder/src/comps/comps/selectInputComp/selectCompConstants.tsx index 08d7690fd9..a474666bd9 100644 --- a/client/packages/lowcoder/src/comps/comps/selectInputComp/selectCompConstants.tsx +++ b/client/packages/lowcoder/src/comps/comps/selectInputComp/selectCompConstants.tsx @@ -57,8 +57,7 @@ import { RefControl } from "comps/controls/refControl"; import { BaseSelectRef } from "rc-select"; import { refMethods } from "comps/generators/withMethodExposing"; import { blurMethod, focusMethod } from "comps/utils/methodUtils"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { styleControl } from "comps/controls/styleControl"; import SupaDemoDisplay from "comps/utils/supademoDisplay"; @@ -335,7 +334,9 @@ export const SelectPropertyView = ( inputFieldStyle: { getPropertyView: () => ControlNode }; childrenInputFieldStyle: { getPropertyView: () => ControlNode }; } -) => ( +) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.options.propertyView({})} @@ -345,7 +346,7 @@ export const SelectPropertyView = ( {placeholderPropertyView(children)}
- {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && ( <> <> @@ -361,10 +362,10 @@ export const SelectPropertyView = ( )} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && + {["layout", "both"].includes(editorModeStatus) && children.label.getPropertyView()} - {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{allowClearPropertyView(children)} {showSearchPropertyView(children)} @@ -372,7 +373,7 @@ export const SelectPropertyView = ( )} {["layout", "both"].includes( - useContext(EditorContext).editorModeStatus + editorModeStatus ) && ( <>
@@ -391,6 +392,7 @@ export const SelectPropertyView = ( )} ); +}; export const baseSelectRefMethods = refMethods([ focusMethod, diff --git a/client/packages/lowcoder/src/comps/comps/selectInputComp/selectInputConstants.tsx b/client/packages/lowcoder/src/comps/comps/selectInputComp/selectInputConstants.tsx index d7b5648e17..96b17c21fa 100644 --- a/client/packages/lowcoder/src/comps/comps/selectInputComp/selectInputConstants.tsx +++ b/client/packages/lowcoder/src/comps/comps/selectInputComp/selectInputConstants.tsx @@ -61,7 +61,6 @@ export const useSelectInputValidate = (props: ValidationParams) => { propsRef.current = props; const selectValue = props.value.value; - const defaultValue = props.defaultValue?.value; const handleValidate = (value: string | (string | number)[]) => { setValidateState( @@ -74,10 +73,6 @@ export const useSelectInputValidate = (props: ValidationParams) => { ); }; - useEffect(() => { - props.value.onChange?.(defaultValue) - }, [defaultValue]); - useEffect(() => { if (!changeRef.current) return; diff --git a/client/packages/lowcoder/src/comps/comps/selectInputComp/stepControl.tsx b/client/packages/lowcoder/src/comps/comps/selectInputComp/stepControl.tsx index a3aad710ea..be1739dd8c 100644 --- a/client/packages/lowcoder/src/comps/comps/selectInputComp/stepControl.tsx +++ b/client/packages/lowcoder/src/comps/comps/selectInputComp/stepControl.tsx @@ -34,8 +34,7 @@ import { trans } from "i18n"; import { hasIcon } from "comps/utils"; import { RefControl } from "comps/controls/refControl"; import { dropdownControl } from "comps/controls/dropdownControl"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { getBackgroundStyle } from "@lowcoder-ee/util/styleUtils"; import { AutoHeightControl } from "@lowcoder-ee/comps/controls/autoHeightControl"; @@ -404,7 +403,9 @@ let StepControlBasicComp = (function () { ); }) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.options.propertyView({})} @@ -414,9 +415,7 @@ let StepControlBasicComp = (function () { })}
- {["logic", "both"].includes( - useContext(EditorContext).editorModeStatus, - ) && ( + {["logic", "both"].includes(editorModeStatus) && ( <>
{children.onEvent.getPropertyView()} @@ -439,9 +438,7 @@ let StepControlBasicComp = (function () { )} - {["layout", "both"].includes( - useContext(EditorContext).editorModeStatus, - ) && ( + {["layout", "both"].includes(editorModeStatus) && (
{children.autoHeight.getPropertyView()} {children.size.propertyView({ @@ -484,9 +481,7 @@ let StepControlBasicComp = (function () {
)} - {["layout", "both"].includes( - useContext(EditorContext).editorModeStatus, - ) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.style.getPropertyView()} @@ -497,7 +492,8 @@ let StepControlBasicComp = (function () { )} - )) + ); + }) .setExposeMethodConfigs(selectDivRefMethods) .build(); })(); diff --git a/client/packages/lowcoder/src/comps/comps/shapeComp/shapeComp.tsx b/client/packages/lowcoder/src/comps/comps/shapeComp/shapeComp.tsx index fca9c6b8b8..10f406a31a 100644 --- a/client/packages/lowcoder/src/comps/comps/shapeComp/shapeComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/shapeComp/shapeComp.tsx @@ -23,8 +23,8 @@ import { import { trans } from "i18n"; import { BoolCodeControl } from "comps/controls/codeControl"; import { DisabledContext } from "comps/generators/uiCompBuilder"; -import React, { useContext, useEffect, useState } from "react"; -import { EditorContext } from "comps/editorState"; +import React, { useEffect, useState } from "react"; +import { useEditorStore } from "comps/editorStore"; export const ContainerBaseComp = (function () { const childrenMap = { @@ -41,6 +41,7 @@ export const ContainerBaseComp = (function () { ); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -49,8 +50,8 @@ export const ContainerBaseComp = (function () { IconType: "All", })}
- {(useContext(EditorContext).editorModeStatus === "logic" || - useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || + editorModeStatus === "both") && (
{disabledPropertyView(children)} {hiddenPropertyView(children)} @@ -58,8 +59,8 @@ export const ContainerBaseComp = (function () {
)} - {(useContext(EditorContext).editorModeStatus === "layout" || - useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "layout" || + editorModeStatus === "both") && ( <>
{children.container.getPropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/signatureComp.tsx b/client/packages/lowcoder/src/comps/comps/signatureComp.tsx index d113e08df4..10d951f09c 100644 --- a/client/packages/lowcoder/src/comps/comps/signatureComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/signatureComp.tsx @@ -27,8 +27,7 @@ import { UICompBuilder } from "../generators"; import { NameConfig, NameConfigHidden, withExposingConfigs } from "../generators/withExposing"; import { formDataChildren, FormDataPropertyView } from "./formComp/formDataConstants"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; const Wrapper = styled.div<{ $style: SignatureStyleType; $isEmpty: boolean }>` height: 100%; @@ -227,6 +226,7 @@ let SignatureTmpComp = (function () { }); }) .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); return ( <>
@@ -235,7 +235,7 @@ let SignatureTmpComp = (function () { - {["logic", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["logic", "both"].includes(editorModeStatus) && (
{children.onEvent.getPropertyView()} {hiddenPropertyView(children)} @@ -245,11 +245,11 @@ let SignatureTmpComp = (function () {
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( children.label.getPropertyView() )} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.style.getPropertyView()} diff --git a/client/packages/lowcoder/src/comps/comps/splitLayout/splitLayout.tsx b/client/packages/lowcoder/src/comps/comps/splitLayout/splitLayout.tsx index 04f3ca3d66..15daa723c3 100644 --- a/client/packages/lowcoder/src/comps/comps/splitLayout/splitLayout.tsx +++ b/client/packages/lowcoder/src/comps/comps/splitLayout/splitLayout.tsx @@ -15,8 +15,7 @@ import { BackgroundColorContext } from "comps/utils/backgroundColorContext"; import { Section, sectionNames} from "lowcoder-design"; import { trans } from "i18n"; import { ContainerBaseProps, gridItemCompToGridItems, InnerGrid } from "../containerComp/containerView"; -import { useContext } from "react"; -import { EditorContext } from "comps/editorState"; +import { useEditorStore } from "comps/editorStore"; import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUtils"; import { DisabledContext } from "comps/generators/uiCompBuilder"; @@ -196,19 +195,21 @@ const SplitLayout = (props: SplitLayoutProps) => { export const SplitLayoutBaseComp = (function () { return new UICompBuilder(childrenMap, (props, dispatch) => ) - .setPropertyViewFn((children) => ( + .setPropertyViewFn((children) => { + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); + return ( <>
{children.columns.propertyView({ title: trans("splitLayout.column") })}
- {(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && ( + {(editorModeStatus === "logic" || editorModeStatus === "both") && (
{disabledPropertyView(children)} {hiddenPropertyView(children)}
)} - {["layout", "both"].includes(useContext(EditorContext).editorModeStatus) && ( + {["layout", "both"].includes(editorModeStatus) && ( <>
{children.orientation.propertyView({ @@ -242,7 +243,8 @@ export const SplitLayoutBaseComp = (function () { )} - )) + ); + }) .build(); })(); @@ -348,4 +350,4 @@ class SplitLayoutImplComp extends SplitLayoutBaseComp implements IContainer { export const SplitLayoutComp = withExposingConfigs( SplitLayoutImplComp, [ NameConfigHidden] -); \ No newline at end of file +); diff --git a/client/packages/lowcoder/src/comps/comps/switchComp.tsx b/client/packages/lowcoder/src/comps/comps/switchComp.tsx index 40bada394f..df0b68c3c2 100644 --- a/client/packages/lowcoder/src/comps/comps/switchComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/switchComp.tsx @@ -6,6 +6,7 @@ import { LabelControl } from "comps/controls/labelControl"; import { styleControl } from "comps/controls/styleControl"; import { SwitchStyle, SwitchStyleType, LabelStyle, InputFieldStyle, AnimationStyle } from "comps/controls/styleControlConstants"; import { migrateOldData } from "comps/generators/simpleGenerators"; +import { withLinkedDefaultValue } from "comps/controls/codeStateControl"; import { Section, lightenColor, sectionNames } from "lowcoder-design"; import styled, { css } from "styled-components"; import { UICompBuilder } from "../generators"; @@ -18,8 +19,8 @@ import { refMethods } from "comps/generators/withMethodExposing"; import { blurMethod, clickMethod, focusWithOptions } from "comps/utils/methodUtils"; import { fixOldInputCompData } from "./textInputComp/textInputConstants"; -import { useCallback, useContext, useEffect } from "react"; -import { EditorContext } from "comps/editorState"; +import { useCallback } from "react"; +import { useEditorStore } from "comps/editorStore"; const EventOptions = [ changeEvent, @@ -108,13 +109,8 @@ let SwitchTmpComp = (function () { ...formDataChildren, }; return new UICompBuilder(childrenMap, (props) => { - const defaultValue = { ...props.defaultValue }.value; const value = { ...props.value }.value; - useEffect(() => { - props.value.onChange(defaultValue); - }, [defaultValue]); - const handleChange = useCallback((checked: boolean) => { props.value.onChange(checked); props.onEvent("change"); @@ -140,7 +136,7 @@ let SwitchTmpComp = (function () { }); }) .setPropertyViewFn((children) => { - const editorModeStatus = useContext(EditorContext).editorModeStatus; + const editorModeStatus = useEditorStore((state) => state.editorModeStatus); const isLogicMode = ["logic", "both"].includes(editorModeStatus); const isLayoutMode = ["layout", "both"].includes(editorModeStatus); @@ -189,7 +185,10 @@ let SwitchTmpComp = (function () { .build(); })(); -SwitchTmpComp = migrateOldData(SwitchTmpComp, fixOldInputCompData); +SwitchTmpComp = migrateOldData( + withLinkedDefaultValue(SwitchTmpComp, "defaultValue", "value"), + fixOldInputCompData +); export const SwitchComp = withExposingConfigs(SwitchTmpComp, [ new NameConfig("value", trans("switchComp.valueDesc")), diff --git a/client/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComps/columnMultilineTextComp.tsx b/client/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComps/columnMultilineTextComp.tsx index 5006e86f3f..196bce238f 100644 --- a/client/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComps/columnMultilineTextComp.tsx +++ b/client/packages/lowcoder/src/comps/comps/tableComp/column/columnTypeComps/columnMultilineTextComp.tsx @@ -61,7 +61,7 @@ const MultilineEditModal = React.memo((props: { cancelText={trans("table.multilineEditorCancel")} width={560} maskClosable={false} - destroyOnClose + destroyOnHidden >