-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Feature/taipy designer react #2418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
2c5c915
TaipyRendered with updated webpack
dinhlongviolin1 ab6c09c
add npm pack for gui base export
dinhlongviolin1 449931c
add elementmanager
dinhlongviolin1 81c0ab0
update string type
dinhlongviolin1 789640f
per Fred
dinhlongviolin1 ff7985f
render from backend
dinhlongviolin1 d669466
add callback on re render
dinhlongviolin1 ec8b99f
both edit + view mode working (still some issues on resizing + mode s…
dinhlongviolin1 3f6da5c
add elementaction callback
dinhlongviolin1 f627f24
each element is rendered as a separate jsx
dinhlongviolin1 0ed1c15
elementaction behavior update - with action prediction
dinhlongviolin1 7927b1d
add property editor handler for sidebar
dinhlongviolin1 98ce90a
property selection
dinhlongviolin1 5de0431
add more input element
dinhlongviolin1 e644a10
add docs
dinhlongviolin1 f6595a6
re organize variable fetcher
dinhlongviolin1 e881a15
add expression editor
dinhlongviolin1 82bbb82
add new range calculation
dinhlongviolin1 d62ede4
add client config option to resources
dinhlongviolin1 2d9817f
add important taipy config
dinhlongviolin1 0415585
add boolean input + update viselements input slider button
dinhlongviolin1 908b446
add chart + table config + some viselements config
dinhlongviolin1 dfa54c1
Merge branch 'develop' into feature/taipy-designer-react
dinhlongviolin1 552890c
allow theme modification
dinhlongviolin1 4d81217
add style handler
dinhlongviolin1 51aa72f
update viselementsjson
dinhlongviolin1 61df55a
remove css
dinhlongviolin1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
frontend/taipy-gui/base/src/components/Taipy/TaipyRendered.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2021-2025 Avaiga Private Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import React, { ComponentType, useEffect, useMemo, useReducer } from "react"; | ||
import { ErrorBoundary } from "react-error-boundary"; | ||
import JsxParser from "react-jsx-parser"; | ||
|
||
import { ThemeProvider } from "@mui/system"; | ||
import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider"; | ||
import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFnsV3"; | ||
|
||
import { PageContext, TaipyContext } from "../../../../src/context/taipyContext"; | ||
import { emptyArray } from "../../../../src/utils"; | ||
import ErrorFallback from "../../../../src/utils/ErrorBoundary"; | ||
import { getRegisteredComponents } from "../../../../src/components/Taipy"; | ||
import { renderError, unregisteredRender } from "../../../../src/components/Taipy/Unregistered"; | ||
import { | ||
INITIAL_STATE, | ||
initializeWebSocket, | ||
taipyInitialize, | ||
taipyReducer, | ||
} from "../../../../src/context/taipyReducers"; | ||
import useStore from "../../store"; | ||
|
||
const TaipyRendered = () => { | ||
const jsx = useStore((state) => state.jsx); | ||
const module = useStore((state) => state.module); | ||
const pageState = useMemo(() => { | ||
return { jsx, module }; | ||
}, [jsx, module]); | ||
const [state, dispatch] = useReducer(taipyReducer, INITIAL_STATE, taipyInitialize); | ||
const themeClass = "taipy-" + state.theme.palette.mode; | ||
|
||
useEffect(() => { | ||
initializeWebSocket(state.socket, dispatch); | ||
}, [state.socket]); | ||
|
||
useEffect(() => { | ||
const classes = [themeClass]; | ||
document.body.classList.forEach((cls) => { | ||
if (!cls.startsWith("taipy-")) { | ||
classes.push(cls); | ||
} | ||
}); | ||
document.body.className = classes.join(" "); | ||
}, [themeClass]); | ||
|
||
return ( | ||
<TaipyContext.Provider value={{ state, dispatch }}> | ||
<ThemeProvider theme={state.theme}> | ||
<LocalizationProvider dateAdapter={AdapterDateFns}> | ||
<PageContext.Provider value={pageState}> | ||
<ErrorBoundary FallbackComponent={ErrorFallback}> | ||
<JsxParser | ||
disableKeyGeneration={true} | ||
bindings={state.data} | ||
components={getRegisteredComponents() as Record<string, ComponentType>} | ||
jsx={pageState.jsx} | ||
renderUnrecognized={unregisteredRender} | ||
allowUnknownElements={false} | ||
renderError={renderError} | ||
blacklistedAttrs={emptyArray} | ||
/> | ||
</ErrorBoundary> | ||
</PageContext.Provider> | ||
</LocalizationProvider> | ||
</ThemeProvider> | ||
</TaipyContext.Provider> | ||
); | ||
}; | ||
|
||
export default TaipyRendered; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { TaipyApp } from "../app"; | ||
import { createRoot } from "react-dom/client"; | ||
import useStore from "../store"; | ||
import { createElement } from "react"; | ||
import TaipyRendered from "../components/Taipy/TaipyRendered"; | ||
|
||
export class TaipyCanvas { | ||
taipyApp: TaipyApp; | ||
|
||
constructor(taipyApp: TaipyApp) { | ||
this.taipyApp = taipyApp; | ||
} | ||
|
||
init(domElement: HTMLElement) { | ||
if (domElement) { | ||
const root = createRoot(domElement); | ||
root.render(createElement(TaipyRendered)); | ||
useStore.getState().setModule(this.taipyApp.getContext()); | ||
} else { | ||
console.error("Root element not found!"); | ||
} | ||
} | ||
|
||
updateContent(jsx: string) { | ||
useStore.getState().setJsx(jsx); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { TaipyApp } from "../app"; | ||
import { TaipyCanvas } from "./canvas"; | ||
import { FrontendRenderer, TaipyRenderer } from "./elementRenderer"; | ||
|
||
export interface Element { | ||
id: string | undefined; | ||
type: string; | ||
bindingEncodedVarName: string | undefined; | ||
wrapperHtml: [string, string] | undefined; | ||
} | ||
|
||
export class ElementManager { | ||
_elements: Element[]; | ||
_renderer: TaipyRenderer; | ||
_canvas: TaipyCanvas; | ||
taipyApp: TaipyApp; | ||
|
||
constructor(taipyApp: TaipyApp) { | ||
this.taipyApp = taipyApp; | ||
this._elements = []; | ||
this._renderer = new FrontendRenderer(taipyApp); | ||
this._canvas = new TaipyCanvas(taipyApp); | ||
} | ||
|
||
init(domElement: HTMLElement) { | ||
this._canvas.init(domElement); | ||
} | ||
|
||
addElement(element: Element) { | ||
if (element.id === undefined) { | ||
element.id = Math.random().toString(36).substring(10); | ||
dinhlongviolin1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
this._elements.push(element); | ||
this._canvas.updateContent(this._renderer.render(this._elements)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { TaipyApp } from "../app"; | ||
import { Element } from "./elementManager"; | ||
|
||
export interface TaipyRenderer { | ||
render(elements: Element[]): string; | ||
} | ||
|
||
export class FrontendRenderer implements TaipyRenderer { | ||
dinhlongviolin1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
taipyApp: TaipyApp; | ||
|
||
constructor(taipyApp: TaipyApp) { | ||
this.taipyApp = taipyApp; | ||
} | ||
|
||
render(elements: Element[]): string { | ||
const elList: string[] = []; | ||
for (const e of elements) { | ||
dinhlongviolin1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const defaultValue = e.bindingEncodedVarName | ||
? this.taipyApp?.variableData?.get(e.bindingEncodedVarName) | ||
: undefined; | ||
const bindingVarStr = defaultValue | ||
? ` defaultValue={"${defaultValue}"} updateVarName="${e.bindingEncodedVarName}" value={${e.bindingEncodedVarName}}` | ||
dinhlongviolin1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: ""; | ||
elList.push( | ||
`${e.wrapperHtml && e.wrapperHtml[0]}<${e.type} key="${e.id}" ${bindingVarStr} />${e.wrapperHtml && e.wrapperHtml[1]}`, | ||
); | ||
} | ||
return elList.join("\n"); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { create } from "zustand"; | ||
dinhlongviolin1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
interface TaipyGuiBaseState { | ||
jsx: string; | ||
module: string; | ||
setJsx: (newJsx: string) => void; | ||
setModule: (newModule: string) => void; | ||
} | ||
|
||
const useStore = create<TaipyGuiBaseState>()((set) => ({ | ||
jsx: "", | ||
module: "", | ||
setJsx: (newJsx: string) => set(() => ({ jsx: newJsx })), | ||
setModule: (newModule: string) => set(() => ({ module: newModule })), | ||
})); | ||
|
||
export default useStore; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.