Compare commits
45 Commits
drag-dop-f
...
code-edito
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdd3bab3a5 | ||
|
|
53aaa8a670 | ||
|
|
64631caaaa | ||
|
|
8e1f042350 | ||
|
|
128a7c49b9 | ||
|
|
e0fa421459 | ||
|
|
0438480620 | ||
|
|
d64f87847c | ||
|
|
c6fd4a8275 | ||
|
|
bfeb1c55b9 | ||
|
|
9949fb8335 | ||
|
|
86f84ef998 | ||
|
|
fc68d407b7 | ||
|
|
16e0b5862e | ||
|
|
d36fca5cc6 | ||
|
|
7f379c0ae6 | ||
|
|
45847df63d | ||
|
|
c177a16b33 | ||
|
|
92a967721a | ||
|
|
1b8ab3938d | ||
|
|
dcc90dd954 | ||
|
|
565b69db9f | ||
|
|
5004dd140e | ||
|
|
ede5f276cf | ||
|
|
c7d30dc392 | ||
|
|
8b386e3263 | ||
|
|
1912e53672 | ||
|
|
b9139469d4 | ||
|
|
c2b0532e96 | ||
|
|
22718369e1 | ||
|
|
4403c27c76 | ||
|
|
14866c8aaf | ||
|
|
4a85f86c95 | ||
|
|
a4365861c9 | ||
|
|
81ddfc58c5 | ||
|
|
5f2d80755e | ||
|
|
ee57b43d0e | ||
|
|
dc892e6f61 | ||
|
|
9fad1bc5a1 | ||
|
|
ddb1bcae97 | ||
|
|
e8ab297af0 | ||
|
|
94850c99b1 | ||
|
|
6d6ce019f1 | ||
|
|
b3ab3b1193 | ||
|
|
81c3056a10 |
@@ -5,7 +5,7 @@ Below is the License for source code of PyUIBuilder. For license regarding sourc
|
||||
|
||||
-----------------------
|
||||
|
||||
The source code for PyUIBuilder is Dual licensed, most parts of the code comes under AGPL,
|
||||
The source code for PyUIBuilder is Dual licensed, some parts of the code comes under AGPL,
|
||||
some parts under a different non-commercial use license. Read the second part after the definition of the AGPL license.
|
||||
|
||||
Sub-folders with non-commercial use license will contain the second license as well.
|
||||
|
||||
10
README.md
10
README.md
@@ -1,4 +1,6 @@
|
||||
# PyUIBuilder - Build python GUIs like Webflow
|
||||
# PyUIBuilder - Python GUI Builder
|
||||
Build python GUIs like Webflow
|
||||
|
||||
<sub>Not affiliated to Webflow</sub>
|
||||
|
||||
<p align="center">
|
||||
@@ -28,7 +30,7 @@ https://github.com/user-attachments/assets/ac91aa98-843d-4578-b646-88e66bc113de
|
||||
<sub>**Don't like background music? fell free to mute it**</sub>
|
||||
|
||||
## Try PyUIBuilder
|
||||
Try [PyUIBuilder](https://pyuibuilder.pages.dev/)
|
||||
Try [PyUIBuilder](https://pyuibuilder.com)
|
||||
|
||||
## Table of contents
|
||||
|
||||
@@ -51,7 +53,7 @@ Try [PyUIBuilder](https://pyuibuilder.pages.dev/)
|
||||
|
||||
|
||||
## Docs - Getting started
|
||||
Read the docs on the [Docs page](https://pyuibuilder-docs.pages.dev/)
|
||||
Read the docs on the [Docs page](https://docs.pyuibuilder.com/)
|
||||
|
||||
## Example app
|
||||
|
||||
@@ -107,7 +109,7 @@ While there are a lot of features, here are few you need to know.
|
||||
* Framework agnostic - Can outputs code in multiple frameworks.
|
||||
* Pre-built UI widgets
|
||||
* Plugins to extend 3rd party UI libraries
|
||||
* Supports layout managers, such as flex, grid and absolute positioning [read docs](https://pyuibuilder-docs.pages.dev/)
|
||||
* Supports layout managers, such as flex, grid and absolute positioning [read docs](https://docs.pyuibuilder.com/)
|
||||
* Generates python Code.
|
||||
* Support to upload local assets.
|
||||
* Generates requirements.txt file when needed
|
||||
|
||||
@@ -10,7 +10,7 @@ Let's start with the basics of UI
|
||||
|
||||

|
||||
|
||||
1. The sidebar on the left will have multiple buttons, each button will provide you with necessary tools.
|
||||
1. The sidebar on the left will have multiple tabs, each tabs will provide you with necessary tools.
|
||||
2. The Place where you drag and drop widgets is the canvas
|
||||
3. The toolbar will only appear if a widget is selected.
|
||||
|
||||
@@ -26,7 +26,7 @@ Things you can do on canvas.
|
||||
4. Delete widgets using `del` key or right clicking on the widget
|
||||
|
||||
## Project name
|
||||
By default all project's are named untitled project, you can change this from the header input next to export code.
|
||||
By default all project's are named `"untitled project"`, you can change this from the header input next to export code.
|
||||
|
||||
## Selecting a UI library
|
||||
You can select the UI library from the header dropdown. Once selected changing the UI library in between your work, will erase the canvas.
|
||||
|
||||
@@ -249,7 +249,7 @@
|
||||
|
||||
</ul>
|
||||
<a
|
||||
href="https://pyuibuilder.pages.dev/"
|
||||
href="https://pyuibuilder.com"
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
class=" !tw-bg-[#0F1727] tw-duration-[0.3s] hover:tw-transition-transform hover:tw-scale-[1.01] !tw-mt-auto !tw-text-white tw-gap-2 tw-text-lg tw-rounded-md tw-w-full tw-flex tw-place-content-center tw-p-2 tw-mx-2"
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -24,6 +24,7 @@
|
||||
"fabric": "^6.1.0",
|
||||
"file-saver": "^2.0.5",
|
||||
"jszip": "^3.10.1",
|
||||
"lodash": "^4.17.21",
|
||||
"postcss-cli": "^11.0.0",
|
||||
"re-resizable": "^6.9.17",
|
||||
"react": "^18.3.1",
|
||||
@@ -14728,7 +14729,8 @@
|
||||
"node_modules/lodash": {
|
||||
"version": "4.17.21",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
|
||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.debounce": {
|
||||
"version": "4.0.8",
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
"fabric": "^6.1.0",
|
||||
"file-saver": "^2.0.5",
|
||||
"jszip": "^3.10.1",
|
||||
"lodash": "^4.17.21",
|
||||
"postcss-cli": "^11.0.0",
|
||||
"re-resizable": "^6.9.17",
|
||||
"react": "^18.3.1",
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
content="A python GUI builder. Create tkinter, Customtk, Kivy and PySide using GUI builder"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
@@ -17,6 +17,8 @@
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css" integrity="sha512-dPXYcDub/aeb08c63jRq/k6GaKccl256JQy/AnOq7CAnEZ9FzSL9wSbcZkMp4R26vBsMLFYH4kQ67/bbV8XaCQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
|
||||
<script async src="https://tally.so/widgets/embed.js"></script>
|
||||
|
||||
<!-- Google tag (gtag.js) -->
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id=%REACT_APP_ANALYTICS_SCRIPT_ID%"></script>
|
||||
<script>
|
||||
@@ -42,5 +44,6 @@
|
||||
<div id="root"></div>
|
||||
|
||||
</body>
|
||||
|
||||
<!-- Author: Paul Github: PaulleDemon -->
|
||||
</html>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"short_name": "PyUiBuilder",
|
||||
"name": "PyUiBuilder - Python GUI Builder",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
|
||||
104
src/App.js
104
src/App.js
@@ -33,6 +33,8 @@ import TkMainWindow from './frameworks/tkinter/widgets/mainWindow'
|
||||
import CTkMainWindow from './frameworks/customtk/widgets/mainWindow'
|
||||
import TreeviewContainer from './sidebar/treeviewContainer'
|
||||
import { WidgetContextProvider } from './canvas/context/widgetContext'
|
||||
import { isChromium } from './utils/system'
|
||||
import { Modal } from 'antd'
|
||||
|
||||
|
||||
function App() {
|
||||
@@ -44,6 +46,8 @@ function App() {
|
||||
|
||||
const [projectName, setProjectName] = useState('untitled project')
|
||||
const [UIFramework, setUIFramework] = useState(FrameWorks.TKINTER)
|
||||
|
||||
const [shownNotChromiumAlert, setShownNotChromiumAlert] = useState(false) // if the user isn't using a chromium based browser alerts the user
|
||||
|
||||
// const [uploadedAssets, setUploadedAssets] = useState([]) // a global storage for assets, since redux can't store files(serialize files)
|
||||
|
||||
@@ -55,6 +59,28 @@ function App() {
|
||||
// NOTE: the below reference is no longer required
|
||||
const [canvasWidgets, setCanvasWidgets] = useState([]) // contains the reference to the widgets inside the canvas
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
if (!shownNotChromiumAlert){
|
||||
// this modal may rerender twice only in dev mode because of how react works
|
||||
isChromium().then((isChrome) => {
|
||||
|
||||
if (!isChrome){
|
||||
Modal.warning({
|
||||
title: "Use Chromium browser",
|
||||
onOk: () => setShownNotChromiumAlert(true),
|
||||
content: (<span>We recommend using Chromium based browser such as Chrome, Brave, Edge etc for best results.
|
||||
<br />
|
||||
Join us on
|
||||
<a href="https://discord.gg/dHXjrrCA7G" target='_blank' rel='noreferrer noopener'> Discord</a> for help and updates</span>)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
setShownNotChromiumAlert(true)
|
||||
|
||||
}, [shownNotChromiumAlert])
|
||||
|
||||
const sidebarTabs = [
|
||||
{
|
||||
name: "Widgets",
|
||||
@@ -85,15 +111,59 @@ function App() {
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
if (!canvasRef)
|
||||
return
|
||||
|
||||
const canvasBoundingBox = canvasRef.current.getCanvasContainerBoundingRect()
|
||||
const canvasCenterX = (canvasBoundingBox.width - canvasBoundingBox.left) / 2
|
||||
const canvasCenterY = (canvasBoundingBox.height - canvasBoundingBox.top) / 2
|
||||
|
||||
// console.log("position: ", TkMainWindow.)
|
||||
if (UIFramework === FrameWorks.TKINTER){
|
||||
canvasRef?.current?.createWidget(TkMainWindow)
|
||||
|
||||
const widgetCenterX = (TkMainWindow.initialSize.width - canvasBoundingBox.left) / 2
|
||||
const widgetCenterY = (TkMainWindow.initialSize.height - canvasBoundingBox.top) / 2
|
||||
|
||||
canvasRef?.current?.createWidget(TkMainWindow, {x: canvasCenterX - widgetCenterX, y: canvasCenterY - widgetCenterY}, ({id, widgetRef}) => {
|
||||
|
||||
// center the widget when adding to canvas
|
||||
if (!widgetRef.current){
|
||||
return
|
||||
}
|
||||
|
||||
const widgetBoundingBox = widgetRef.current?.getBoundingRect()
|
||||
const widgetCenterX = (widgetBoundingBox.width - widgetBoundingBox.left) / 2
|
||||
const widgetCenterY = (widgetBoundingBox.height - widgetBoundingBox.top) / 2
|
||||
|
||||
|
||||
// widgetRef.current?.setPos(canvasCenterX-widgetCenterX, canvasCenterY-widgetCenterY)
|
||||
})
|
||||
|
||||
}else if (UIFramework === FrameWorks.CUSTOMTK){
|
||||
canvasRef?.current?.createWidget(CTkMainWindow)
|
||||
|
||||
const widgetCenterX = (TkMainWindow.initialSize.width - canvasBoundingBox.left) / 2
|
||||
const widgetCenterY = (TkMainWindow.initialSize.height - canvasBoundingBox.top) / 2
|
||||
|
||||
|
||||
canvasRef?.current?.createWidget(CTkMainWindow, {x: canvasCenterX - widgetCenterX, y: canvasCenterY - widgetCenterY}, ({id, widgetRef}) => {
|
||||
|
||||
// center the widget when adding to canvas
|
||||
if (!widgetRef.current){
|
||||
return
|
||||
}
|
||||
|
||||
const widgetBoundingBox = widgetRef.current?.getBoundingRect()
|
||||
const widgetCenterX = (widgetBoundingBox.width - widgetBoundingBox.left) / 2
|
||||
const widgetCenterY = (widgetBoundingBox.height - widgetBoundingBox.top) / 2
|
||||
|
||||
|
||||
// widgetRef.current?.setPos(canvasCenterX-widgetCenterX, canvasCenterY-widgetCenterY)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}, [UIFramework])
|
||||
}, [UIFramework, canvasRef])
|
||||
|
||||
// const handleDragStart = (event) => {
|
||||
// console.log("Drag start: ", event)
|
||||
@@ -169,7 +239,6 @@ function App() {
|
||||
|
||||
const handleWidgetAddedToCanvas = (widgets) => {
|
||||
setCanvasWidgets(widgets)
|
||||
console.log("widget added: ", widgets)
|
||||
}
|
||||
|
||||
const handleCodeGen = () => {
|
||||
@@ -215,20 +284,21 @@ function App() {
|
||||
onOk={handleOk} okType={okButtonType} onCancel={handleCancel}>
|
||||
<p>Are you sure you want to change the framework? This will clear the canvas.</p>
|
||||
</Modal> */}
|
||||
|
||||
|
||||
<WidgetContextProvider>
|
||||
<DragProvider>
|
||||
<div className="tw-w-full tw-h-[94vh] tw-flex">
|
||||
<Sidebar tabs={sidebarTabs}/>
|
||||
|
||||
{/* <ActiveWidgetProvider> */}
|
||||
<Canvas ref={canvasRef} widgets={canvasWidgets}
|
||||
onWidgetAdded={handleWidgetAddedToCanvas}/>
|
||||
{/* </ActiveWidgetProvider> */}
|
||||
</div>
|
||||
{/* dragOverlay (dnd-kit) helps move items from one container to another */}
|
||||
</DragProvider>
|
||||
</WidgetContextProvider>
|
||||
<WidgetContextProvider>
|
||||
<DragProvider>
|
||||
<div className="tw-w-full tw-h-[94vh] tw-flex">
|
||||
<Sidebar tabs={sidebarTabs}/>
|
||||
|
||||
{/* <ActiveWidgetProvider> */}
|
||||
<Canvas ref={canvasRef} widgets={canvasWidgets}
|
||||
/>
|
||||
{/* </ActiveWidgetProvider> */}
|
||||
</div>
|
||||
{/* dragOverlay (dnd-kit) helps move items from one container to another */}
|
||||
</DragProvider>
|
||||
</WidgetContextProvider>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ License in short
|
||||
* You are free fork, modify and redistribute it given the original or derived works is kept free and open-source and under the same licese.
|
||||
* Another restriction is you can't redistribute in binary or executable formats without asking me first.
|
||||
* If you plan on making money on this work or derived work you need permission first.
|
||||
* No AI Training on this source code
|
||||
|
||||
License was planned to be kept under one AGPL or less restrictive license, but since its difficult for me to continue providing free and open-source software without proper funding. It's under this license.
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class Canvas extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
const { canvasWidgets, onWidgetListUpdated } = props
|
||||
// const { canvasWidgets, onWidgetListUpdated } = props
|
||||
|
||||
this.canvasRef = React.createRef()
|
||||
this.canvasContainerRef = React.createRef()
|
||||
@@ -90,7 +90,7 @@ class Canvas extends React.Component {
|
||||
toolbarAttrs: null
|
||||
}
|
||||
|
||||
this._onWidgetListUpdated = onWidgetListUpdated // a function callback when the widget is added to the canvas
|
||||
// this._onWidgetListUpdated = onWidgetListUpdated // a function callback when the widget is added to the canvas
|
||||
|
||||
this.resetTransforms = this.resetTransforms.bind(this)
|
||||
this.renderWidget = this.renderWidget.bind(this)
|
||||
@@ -130,12 +130,11 @@ class Canvas extends React.Component {
|
||||
this.initEvents()
|
||||
|
||||
// NOTE: adding the transform will make the inner fixed position to be relative
|
||||
// NOTE: this is needed to keep the resize widget poition correct in base widget
|
||||
// NOTE: this is needed to keep the resize widget position correct in base widget
|
||||
this.applyTransform()
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
console.log("unmounted")
|
||||
|
||||
this.canvasContainerRef.current.removeEventListener("mousedown", this.mouseDownEvent)
|
||||
this.canvasContainerRef.current.removeEventListener("mouseup", this.mouseUpEvent)
|
||||
@@ -244,8 +243,16 @@ class Canvas extends React.Component {
|
||||
|
||||
}
|
||||
|
||||
mouseDownEvent(event) {
|
||||
openToolbar = (widget) => {
|
||||
this.setState({
|
||||
// selectedWidget: selectedWidget,
|
||||
toolbarAttrs: widget?.getToolbarAttrs(),
|
||||
toolbarOpen: true
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
mouseDownEvent(event) {
|
||||
this.mousePos = { x: event.clientX, y: event.clientY }
|
||||
|
||||
let selectedWidget = this.getWidgetFromTarget(event.target)
|
||||
@@ -263,11 +270,12 @@ class Canvas extends React.Component {
|
||||
selectedWidget.setZIndex(1000)
|
||||
selectedWidget.select()
|
||||
// console.log("selected widget", selectedWidget.getToolbarAttrs(), selectedWidget, this.state.selectedWidget)
|
||||
this.setState({
|
||||
// selectedWidget: selectedWidget,
|
||||
toolbarAttrs: selectedWidget.getToolbarAttrs(),
|
||||
toolbarOpen: true
|
||||
})
|
||||
// this.setState({
|
||||
// // selectedWidget: selectedWidget,
|
||||
// toolbarAttrs: selectedWidget.getToolbarAttrs(),
|
||||
// toolbarOpen: true
|
||||
// })
|
||||
// this.openToolbar(selectedWidget)
|
||||
|
||||
this.setSelectedWidget(selectedWidget)
|
||||
|
||||
@@ -307,7 +315,7 @@ class Canvas extends React.Component {
|
||||
} else if (event.button === 2) {
|
||||
//right click
|
||||
|
||||
if (this.selectedWidget && this.selectedWidget.__id !== selectedWidget.__id) {
|
||||
if (this.selectedWidget && this.selectedWidget.__id !== selectedWidget?.__id) {
|
||||
this.clearSelections()
|
||||
}
|
||||
|
||||
@@ -751,8 +759,8 @@ class Canvas extends React.Component {
|
||||
}
|
||||
|
||||
// if the widget is being dropped from the sidebar, use the info to create the widget first
|
||||
this.createWidget(widgetClass, ({ id, widgetRef }) => {
|
||||
widgetRef.current.setPos(finalPosition.x, finalPosition.y)
|
||||
this.createWidget(widgetClass, {x: finalPosition.x, y: finalPosition.y},({ id, widgetRef }) => {
|
||||
// widgetRef.current.setPos(finalPosition.x, finalPosition.y)
|
||||
})
|
||||
|
||||
} else if ([WidgetContainer.CANVAS, WidgetContainer.WIDGET].includes(container)) {
|
||||
@@ -999,7 +1007,9 @@ class Canvas extends React.Component {
|
||||
|
||||
setTimeout(() => {
|
||||
if (parentLayout !== Layouts.PLACE) {
|
||||
// FIXME: need to swap grid col and row as well for this to be effective
|
||||
// swap only for grid and flex placements
|
||||
/** TODO: Fix and uncomment below later
|
||||
const swapClosest = this.__checkClosestShiftElement({
|
||||
event,
|
||||
parentWidgetId,
|
||||
@@ -1009,6 +1019,7 @@ class Canvas extends React.Component {
|
||||
if (swapClosest.closestChild) {
|
||||
this.shiftWidgetPosition(parentWidgetId, dragElementID, swapClosest.closestIndex)
|
||||
}
|
||||
*/
|
||||
}
|
||||
}, 1)
|
||||
|
||||
@@ -1035,7 +1046,7 @@ class Canvas extends React.Component {
|
||||
*
|
||||
* @param {Widget} widgetComponentType - don't pass <Widget /> instead pass Widget object/class
|
||||
*/
|
||||
createWidget(widgetComponentType, callback) {
|
||||
createWidget(widgetComponentType, initialPos={x: 0, y: 0}, callback,) {
|
||||
|
||||
if (!isSubClassOfWidget(widgetComponentType)) {
|
||||
throw new Error("widgetComponentType must be a subclass of Widget class")
|
||||
@@ -1057,7 +1068,7 @@ class Canvas extends React.Component {
|
||||
widgetType: widgetComponentType,
|
||||
children: [],
|
||||
parent: "",
|
||||
initialData: {} // useful for serializing and deserializing (aka, saving and loading)
|
||||
initialData: {pos: initialPos} // useful for serializing and deserializing (aka, saving and loading)
|
||||
}
|
||||
|
||||
const widgets = [...this.widgets, newWidget] // don't add the widget refs in the state
|
||||
@@ -1068,8 +1079,8 @@ class Canvas extends React.Component {
|
||||
if (callback)
|
||||
callback({ id, widgetRef })
|
||||
|
||||
if (this._onWidgetListUpdated)
|
||||
this._onWidgetListUpdated(widgets) // inform the parent container
|
||||
// if (this._onWidgetListUpdated)
|
||||
// this._onWidgetListUpdated(widgets) // inform the parent container
|
||||
}, 1)
|
||||
|
||||
// Update the state to include the new widget's type and ID
|
||||
@@ -1128,8 +1139,8 @@ class Canvas extends React.Component {
|
||||
// widgets: []
|
||||
// })
|
||||
|
||||
if (this._onWidgetListUpdated)
|
||||
this._onWidgetListUpdated([])
|
||||
// if (this._onWidgetListUpdated)
|
||||
// this._onWidgetListUpdated([])
|
||||
}
|
||||
|
||||
getWidgetByIdFromWidgetList = (widgetId) => {
|
||||
@@ -1165,12 +1176,12 @@ class Canvas extends React.Component {
|
||||
// })
|
||||
this.setWidgets(widgets)
|
||||
|
||||
if (this._onWidgetListUpdated)
|
||||
this._onWidgetListUpdated(widgets)
|
||||
// if (this._onWidgetListUpdated)
|
||||
// this._onWidgetListUpdated(widgets)
|
||||
}
|
||||
|
||||
onActiveWidgetUpdate(widgetId) {
|
||||
|
||||
// TODO: remove this as it may no longer be required also remove toolbarAttrs
|
||||
if (!this.selectedWidget || widgetId !== this.selectedWidget.__id)
|
||||
return
|
||||
|
||||
@@ -1200,6 +1211,86 @@ class Canvas extends React.Component {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the widget's initial data, else when there is a remount, you'll loose all the state
|
||||
*
|
||||
* TODO: Find a efficient way to call this function
|
||||
*
|
||||
* NOTE: this would cause entire widgetList to remount
|
||||
* NOTE: this would cause the toolbar to loose active widget
|
||||
*/
|
||||
updateWidgetData = (widgetId) => {
|
||||
|
||||
const widgetObj = this.getWidgetById(widgetId)?.current
|
||||
// console.log("Data unmount: ", this.widgets, this.widgetRefs, widgetObj, widgetId, widgetObj?.serialize(), latestData)
|
||||
|
||||
if (!widgetObj){
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
this.setWidgets(prevWidgets => {
|
||||
const updateWidget = (widgets) => {
|
||||
return widgets.map(widget => {
|
||||
if (widget.id === widgetId) {
|
||||
return {
|
||||
...widget,
|
||||
initialData: {
|
||||
...widget.initialData,
|
||||
...widgetObj.serialize()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (widget.children && widget.children.length > 0) {
|
||||
return {
|
||||
...widget,
|
||||
children: updateWidget(widget.children) // Always return new children
|
||||
};
|
||||
}
|
||||
|
||||
return widget; // Return unchanged widget
|
||||
});
|
||||
};
|
||||
|
||||
return updateWidget(prevWidgets);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
updateWidgetAndChildren = (widgetId) => {
|
||||
const serializeWidgetRecursively = (widget) => {
|
||||
const widgetObj = this.getWidgetById(widget.id)?.current;
|
||||
if (!widgetObj) return widget; // If no widget reference found, return unchanged
|
||||
return {
|
||||
...widget,
|
||||
initialData: {
|
||||
...widget.initialData,
|
||||
...widgetObj.serialize()
|
||||
},
|
||||
children: widget.children?.map(serializeWidgetRecursively) || [] // Recursively serialize children
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
this.setWidgets(prevWidgets => {
|
||||
const updateWidgets = (widgets) => {
|
||||
return widgets.map(widget => {
|
||||
if (widget.id === widgetId) {
|
||||
return serializeWidgetRecursively(widget)
|
||||
}
|
||||
// Search inside children recursively
|
||||
return {
|
||||
...widget,
|
||||
children: updateWidgets(widget.children || [])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return updateWidgets(prevWidgets)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
renderWidget = (widget) => {
|
||||
|
||||
@@ -1216,6 +1307,17 @@ class Canvas extends React.Component {
|
||||
})
|
||||
}
|
||||
|
||||
const handleWidgetSelect = (widgetId) => {
|
||||
|
||||
if (this.selectedWidget && this.selectedWidget.getId() !== widgetId){
|
||||
this.selectedWidget?.deSelect() // deselect the previous widget before adding the new one
|
||||
}
|
||||
|
||||
const widget = this.getWidgetById(widgetId)?.current
|
||||
this.setSelectedWidget(widget)
|
||||
this.openToolbar(widget)
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
<ComponentType
|
||||
@@ -1231,19 +1333,26 @@ class Canvas extends React.Component {
|
||||
pan: this.state.currentTranslate
|
||||
}}
|
||||
|
||||
onSelect={(widgetId) => this.setSelectedWidget(this.getWidgetById(widgetId)?.current)}
|
||||
|
||||
onSelect={handleWidgetSelect}
|
||||
|
||||
onWidgetDeleteRequest={this.removeWidget}
|
||||
|
||||
onPanToWidget={this.panToWidget}
|
||||
|
||||
requestWidgetDataUpdate={this.updateWidgetAndChildren}
|
||||
// requestWidgetDataUpdate={this.updateWidgetData}
|
||||
// onWidgetUpdate={this.onActiveWidgetUpdate}
|
||||
// onWidgetUpdate={this.updateWidgetDataOnUnmount}
|
||||
// onUnmount={this.updateWidgetDataOnUnmount}
|
||||
|
||||
onWidgetUpdate={this.onActiveWidgetUpdate}
|
||||
onAddChildWidget={this.handleAddWidgetChild}
|
||||
onCreateWidgetRequest={this.createWidget} // create widget when dropped from sidebar
|
||||
onWidgetResizing={(resizeSide) => this.setState({ widgetResizing: resizeSide })}
|
||||
// onWidgetDragStart={() => this.setState({isWidgetDragging: true})}
|
||||
// onWidgetDragEnd={() => this.setState({isWidgetDragging: false})}
|
||||
onLayoutUpdate={this.updateChildLayouts}
|
||||
|
||||
>
|
||||
{/* Render children inside the parent with layout applied */}
|
||||
{renderChildren(children)}
|
||||
@@ -1268,7 +1377,7 @@ class Canvas extends React.Component {
|
||||
return (<div className="tw-relative tw-overflow-hidden tw-flex tw-w-full tw-h-full tw-max-h-[100vh]">
|
||||
|
||||
<div className="tw-absolute tw-p-2 tw-bg-white tw-z-10 tw-min-w-[100px] tw-h-[50px] tw-gap-2
|
||||
tw-top-4 tw-place-items-center tw-right-4 tw-shadow-md tw-rounded-md tw-flex">
|
||||
tw-top-4 tw-place-items-center tw-left-4 tw-shadow-md tw-rounded-md tw-flex">
|
||||
|
||||
<Tooltip title="Reset viewport">
|
||||
<Button icon={<ReloadOutlined />} onClick={this.resetTransforms} />
|
||||
@@ -1332,7 +1441,7 @@ class Canvas extends React.Component {
|
||||
</DroppableWrapper>
|
||||
|
||||
<CanvasToolBar isOpen={this.state.toolbarOpen}
|
||||
widgetType={this.selectedWidget?.getWidgetType() || ""}
|
||||
widgetType={this.selectedWidget?.getDisplayName() || ""}
|
||||
attrs={this.state.toolbarAttrs}
|
||||
/>
|
||||
{/* </ActiveWidgetProvider> */}
|
||||
|
||||
@@ -11,6 +11,8 @@ const Tools = {
|
||||
|
||||
LAYOUT_MANAGER: "layout_manager",
|
||||
UPLOADED_LIST: "uploaded_list",
|
||||
|
||||
CUSTOM: "Custom"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { memo, useEffect, useMemo, useState } from "react"
|
||||
import { memo, useEffect, useMemo, useRef, useState } from "react"
|
||||
|
||||
import {
|
||||
Checkbox, ColorPicker, Input,
|
||||
@@ -12,26 +12,67 @@ import { Layouts } from "./constants/layouts.js"
|
||||
import { DynamicRadioInputList } from "../components/inputs.js"
|
||||
import { useFileUploadContext } from "../contexts/fileUploadContext.js"
|
||||
import { AudioOutlined, FileImageOutlined, FileTextOutlined, VideoCameraOutlined } from "@ant-design/icons"
|
||||
import { useWidgetContext } from "./context/widgetContext.js"
|
||||
|
||||
|
||||
// FIXME: Maximum recursion error
|
||||
// FIXME: Every time the parent attrs are changed a remount happens, which causes input cursor to go to the end
|
||||
/**
|
||||
*
|
||||
* @param {boolean} isOpen
|
||||
* @param {string} widgetType
|
||||
* @param {object} attrs - widget attributes
|
||||
*/
|
||||
const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
const CanvasToolBar = memo(({ isOpen, widgetType, }) => {
|
||||
|
||||
// const { activeWidgetAttrs } = useActiveWidget()
|
||||
|
||||
const {activeWidget} = useWidgetContext()
|
||||
|
||||
// console.log("active widget context: ", activeWidgetAttrs)
|
||||
const [toolbarOpen, setToolbarOpen] = useState(isOpen)
|
||||
const [toolbarAttrs, setToolbarAttrs] = useState(attrs)
|
||||
const [toolbarAttrs, setToolbarAttrs] = useState({})
|
||||
|
||||
const focusedInputRef = useRef()
|
||||
|
||||
const [cursorPos, setCursorPos] = useState(0) // store cursor position for focused input so during remount if the cursor position goes to end we can use this
|
||||
const [activeInputKey, setActiveInputKey] = useState(null)
|
||||
|
||||
const {uploadedAssets} = useFileUploadContext()
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
const stateUpdatedCallback = () => {
|
||||
setToolbarAttrs(activeWidget.getToolbarAttrs())
|
||||
}
|
||||
|
||||
if (activeWidget){
|
||||
activeWidget.stateChangeSubscriberCallback(stateUpdatedCallback)
|
||||
// console.log("sytate update: ", activeWidget.getToolbarAttrs())
|
||||
setToolbarAttrs(activeWidget.getToolbarAttrs())
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}, [activeWidget, focusedInputRef, cursorPos]) // , activeWidget?.state
|
||||
|
||||
useEffect(() => {
|
||||
setToolbarOpen(isOpen)
|
||||
}, [isOpen])
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (focusedInputRef.current?.input && activeInputKey) {
|
||||
// this fixes the cursor going to the end issue during remount
|
||||
focusedInputRef.current.setSelectionRange(cursorPos, cursorPos)
|
||||
}
|
||||
}, [toolbarAttrs, focusedInputRef, cursorPos])
|
||||
|
||||
// useEffect(() => {
|
||||
|
||||
// setToolbarAttrs(activeWidget.getToolbarAttrs())
|
||||
|
||||
// }, [])
|
||||
|
||||
const uploadItems = useMemo(() => {
|
||||
|
||||
const returnComponentBasedOnFileType = (file) => {
|
||||
@@ -81,19 +122,30 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
|
||||
}, [uploadedAssets])
|
||||
|
||||
useEffect(() => {
|
||||
setToolbarOpen(isOpen)
|
||||
}, [isOpen])
|
||||
const handleInputFocus = (key, event) => {
|
||||
|
||||
useEffect(() => {
|
||||
setToolbarAttrs(attrs)
|
||||
}, [attrs])
|
||||
const {value, target} = event
|
||||
|
||||
setActiveInputKey(key)
|
||||
setCursorPos(target.selectionStart)
|
||||
focusedInputRef.current = event.target
|
||||
}
|
||||
|
||||
const handleInputBlur = () => {
|
||||
setActiveInputKey(null);
|
||||
focusedInputRef.current = null;
|
||||
}
|
||||
|
||||
const handleChange = (value, callback) => {
|
||||
if (callback) {
|
||||
callback(value)
|
||||
}
|
||||
|
||||
if (focusedInputRef.current?.input) {
|
||||
setCursorPos(focusedInputRef.current.input.selectionStart)
|
||||
}else{
|
||||
setCursorPos(0)
|
||||
}
|
||||
}
|
||||
|
||||
function getUploadFileFromName(name){
|
||||
@@ -119,6 +171,7 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
placeholder="select content"
|
||||
showSearch
|
||||
className="tw-w-full"
|
||||
notFoundContent="Start uploading from uploads tab"
|
||||
value={val.value?.name || ""}
|
||||
onChange={(value) => {
|
||||
|
||||
@@ -165,7 +218,7 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
onChange={(value) => handleChange({ ...val.value, direction: value }, val.onChange)}
|
||||
/>
|
||||
</div>
|
||||
<div className="tw-flex tw-flex-col tw-gap-1">
|
||||
{/* <div className="tw-flex tw-flex-col tw-gap-1">
|
||||
<span className="tw-text-sm">Align items</span>
|
||||
<Select
|
||||
options={[
|
||||
@@ -178,7 +231,7 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
placeholder={`${val.label}`}
|
||||
onChange={(value) => handleChange({ ...val.value, align: value }, val.onChange)}
|
||||
/>
|
||||
</div>
|
||||
</div> */}
|
||||
<div className="tw-flex tw-flex-col">
|
||||
<span className="tw-text-sm">Gap</span>
|
||||
<InputNumber
|
||||
@@ -186,6 +239,9 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
min={1}
|
||||
value={val.value?.gap || 10}
|
||||
size="small"
|
||||
onFocus={(e) => handleInputFocus(val.label, e)}
|
||||
onBlur={handleInputBlur}
|
||||
ref={activeInputKey === val.label ? focusedInputRef : null}
|
||||
onChange={(value) => {
|
||||
handleChange({ ...val.value, gap: value }, val.onChange)
|
||||
}}
|
||||
@@ -235,6 +291,18 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
}
|
||||
|
||||
|
||||
const renderCustomTool = (val) => {
|
||||
return (
|
||||
// NOTE: custom components must accept value and onChange
|
||||
<val.Component
|
||||
{...val.toolProps}
|
||||
value={val.value}
|
||||
onChange={(value) => handleChange(value, val.onChange)}>
|
||||
|
||||
</val.Component>
|
||||
)
|
||||
}
|
||||
|
||||
const renderTool = (keyName, val) => {
|
||||
|
||||
return (
|
||||
@@ -242,6 +310,10 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
{val.tool === Tools.INPUT && (
|
||||
<Input
|
||||
{...val.toolProps}
|
||||
// value={val.value}
|
||||
onFocus={(event) => handleInputFocus(val.label, event)}
|
||||
onBlur={handleInputBlur}
|
||||
ref={activeInputKey === val.label ? focusedInputRef : null}
|
||||
value={val.value}
|
||||
onChange={(e) => handleChange(e.target.value, val.onChange)}
|
||||
/>
|
||||
@@ -252,6 +324,9 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
{...val.toolProps}
|
||||
value={val.value || 0}
|
||||
size="small"
|
||||
onFocus={(event) => handleInputFocus(val.label, event)}
|
||||
onBlur={handleInputBlur}
|
||||
ref={activeInputKey === val.label ? focusedInputRef : null}
|
||||
onChange={(value) => handleChange(value, val.onChange)}
|
||||
/>
|
||||
)}
|
||||
@@ -277,7 +352,7 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
showSearch
|
||||
value={val.value || ""}
|
||||
placeholder={`${val.label}`}
|
||||
className="tw-w-full"
|
||||
className="tw-w-full tw-min-w-[80px]"
|
||||
filterOption={(input, option) =>
|
||||
(option?.label ?? '').toLowerCase().includes(input.toLowerCase())
|
||||
}
|
||||
@@ -294,6 +369,7 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
)}
|
||||
|
||||
{val.tool === Tools.INPUT_RADIO_LIST && (
|
||||
// FIXME: problem with maximum recursion error
|
||||
<DynamicRadioInputList
|
||||
defaultInputs={val.value.inputs}
|
||||
defaultSelected={val.value.selectedRadio}
|
||||
@@ -312,6 +388,12 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
)
|
||||
}
|
||||
|
||||
{
|
||||
val.tool === Tools.CUSTOM && (
|
||||
renderCustomTool(val)
|
||||
)
|
||||
}
|
||||
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -319,10 +401,12 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
|
||||
|
||||
const renderToolbar = (obj, parentKey = "", toolCount=0) => {
|
||||
// console.log("obj: ", obj)
|
||||
const keys = []
|
||||
|
||||
return Object.entries(obj).map(([key, val], i) => {
|
||||
const keyName = parentKey ? `${parentKey}.${key}` : key
|
||||
// console.log("obj2: ", key, val)
|
||||
|
||||
// Highlight outer labels in blue for first-level keys
|
||||
const isFirstLevel = parentKey === ""
|
||||
@@ -331,6 +415,10 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
? "tw-text-sm tw-text-black tw-font-medium"
|
||||
: "tw-text-sm"
|
||||
|
||||
if (!val?.label){
|
||||
return null
|
||||
}
|
||||
|
||||
// Render tool widgets
|
||||
if (typeof val === "object" && val.tool) {
|
||||
|
||||
@@ -338,7 +426,7 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
|
||||
if (isFirstLevel){
|
||||
return (
|
||||
<Collapse key={keyName} ghost defaultActiveKey={keys}>
|
||||
<Collapse key={keyName} defaultActiveKey={keys}>
|
||||
<Collapse.Panel header={val.label} key={keyName}>
|
||||
{renderTool(keyName, val)}
|
||||
</Collapse.Panel>
|
||||
@@ -367,7 +455,7 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
|
||||
if (isFirstLevel){
|
||||
return (
|
||||
<Collapse key={keyName} ghost defaultActiveKey={keys}>
|
||||
<Collapse key={keyName} defaultActiveKey={keys}>
|
||||
<Collapse.Panel header={val.label} key={keyName}>
|
||||
<div className={`${containerClass} tw-px-2`}>
|
||||
{renderToolbar(val, keyName, toolCount+1)}
|
||||
@@ -394,18 +482,20 @@ const CanvasToolBar = memo(({ isOpen, widgetType, attrs = {} }) => {
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`tw-absolute tw-top-20 tw-right-5 tw-bg-white
|
||||
className={`tw-absolute tw-top-10 tw-right-5 tw-bg-white
|
||||
${toolbarOpen ? "tw-translate-x-0" : "tw-translate-x-full"}
|
||||
tw-w-[280px] tw-px-3 tw-p-2 tw-h-[600px] tw-rounded-md tw-z-[1000] tw-shadow-lg
|
||||
tw-w-[280px] tw-px-3 tw-p-2 tw-h-[80vh] tw-rounded-md tw-z-[1000] tw-shadow-lg
|
||||
tw-transition-transform tw-duration-[0.3s] tw-overflow-x-hidden
|
||||
tw-flex tw-flex-col tw-gap-2 tw-overflow-y-auto`}
|
||||
tw-flex tw-flex-col tw-gap-2 tw-overflow-y-auto tw-border-[2px]
|
||||
tw-border-solid tw-border-gray-300`}
|
||||
|
||||
style={{
|
||||
transform: toolbarOpen ? "translateX(0)" : "translateX(calc(100% + 50px))"
|
||||
}}
|
||||
>
|
||||
<h3 className="tw-text-lg tw-text-center">
|
||||
{capitalize(`${widgetType || ""}`).replace(/_/g, " ")}
|
||||
<h3 className="tw-text-lg tw-text-center tw-bg-[#FAFAFA] tw-border-[1px] tw-border-solid tw-border-[#D9D9D9]
|
||||
tw-p-1 tw-px-2 tw-rounded-md tw-font-medium">
|
||||
{capitalize(`${activeWidget?.getDisplayName() || ""}`).replace(/_/g, " ")}
|
||||
</h3>
|
||||
|
||||
<div className="tw-flex tw-flex-col tw-gap-2">
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import React from "react"
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import React, { useEffect, useLayoutEffect, useRef, useState } from "react"
|
||||
|
||||
import lo from 'lodash'
|
||||
|
||||
import { NotImplementedError } from "../../utils/errors"
|
||||
|
||||
import Tools from "../constants/tools"
|
||||
@@ -10,8 +15,7 @@ import EditableDiv from "../../components/editableDiv"
|
||||
|
||||
import WidgetContainer from "../constants/containers"
|
||||
import { DragContext } from "../../components/draggable/draggableContext"
|
||||
import { isNumeric, removeKeyFromObject } from "../../utils/common"
|
||||
import { info } from "autoprefixer"
|
||||
import { getGridPosition, isNumeric, removeKeyFromObject } from "../../utils/common"
|
||||
import { Layout, message } from "antd"
|
||||
|
||||
|
||||
@@ -19,19 +23,20 @@ import { Layout, message } from "antd"
|
||||
|
||||
// FIXME: the drag drop indicator is not going invisible if the drop happens on the child
|
||||
|
||||
// FIXME: once the width and height is set to fit-content, it can no longer be resized
|
||||
// FIXME: once the width and height is set to fit-content, it can no longer be resized (while resizing it shouldn't be fit-width and height instead it should show the actual width and height)
|
||||
|
||||
// FIXME: if the label, buttons are dropped directly on canvas, the background colors don't apply
|
||||
|
||||
const ATTRS_KEYS = ['value', 'label', 'tool', 'onChange', 'options', 'toolProps'] // these are attrs keywords, don't use these keywords as keys while defining the attrs property or serializing
|
||||
|
||||
|
||||
// FIXME: the initial data in canvas should be updated so when it remounts the widget doesn't change state
|
||||
/**
|
||||
* Base class to be extended
|
||||
*/
|
||||
class Widget extends React.Component {
|
||||
|
||||
static widgetType = "widget"
|
||||
static displayName = "Widget"
|
||||
|
||||
static requirements = [] // requirements for the widgets (libraries) eg: tkvideoplayer, tktimepicker
|
||||
static requiredImports = [] // import statements
|
||||
@@ -64,6 +69,8 @@ class Widget extends React.Component {
|
||||
this.swappableAreaRef = React.createRef() // helps identify if the users intent is to swap or drop inside the widget
|
||||
this.innerAreaRef = React.createRef() // this is the inner area where swap is prevented and only drop is accepted
|
||||
|
||||
this.styleAreaRef = React.createRef() // use ref this where inner widget style is applied
|
||||
|
||||
this.functions = {
|
||||
"load": { "args1": "number", "args2": "string" }
|
||||
}
|
||||
@@ -77,6 +84,8 @@ class Widget extends React.Component {
|
||||
selected: false,
|
||||
isWidgetVisible: true,
|
||||
|
||||
// forceRerenderId: "",
|
||||
|
||||
widgetName: widgetName || 'widget', // this will later be converted to variable name
|
||||
enableRename: false, // will open the widgets editable div for renaming
|
||||
|
||||
@@ -103,10 +112,10 @@ class Widget extends React.Component {
|
||||
widgetInnerStyling: {
|
||||
// use for widget's inner styling
|
||||
backgroundColor: "#fff",
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
// display: "flex",
|
||||
// flexDirection: "row",
|
||||
gap: 10,
|
||||
flexWrap: "wrap"
|
||||
// flexWrap: "wrap" // NOTE: this has been uncommented
|
||||
},
|
||||
|
||||
attrs: {
|
||||
@@ -114,7 +123,7 @@ class Widget extends React.Component {
|
||||
backgroundColor: {
|
||||
label: "Background Color",
|
||||
tool: Tools.COLOR_PICKER, // the tool to display, can be either HTML ELement or a constant string
|
||||
value: "#fff",
|
||||
value: "#E4E2E2",
|
||||
onChange: (value) => {
|
||||
this.setWidgetInnerStyle("backgroundColor", value)
|
||||
this.setAttrValue("styling.backgroundColor", value)
|
||||
@@ -127,7 +136,7 @@ class Widget extends React.Component {
|
||||
label: "Layout",
|
||||
tool: Tools.LAYOUT_MANAGER, // the tool to display, can be either HTML ELement or a constant string
|
||||
value: {
|
||||
layout: "flex",
|
||||
layout: Layouts.PLACE,
|
||||
direction: "row",
|
||||
// grid: {
|
||||
// rows: 12,
|
||||
@@ -201,46 +210,100 @@ class Widget extends React.Component {
|
||||
this.getRenderSize = this.getRenderSize.bind(this)
|
||||
this.getInnerRenderStyling = this.getInnerRenderStyling.bind(this)
|
||||
|
||||
this.updateState = this.updateState.bind(this)
|
||||
|
||||
this.stateUpdateCallback = null // allowing other components such as toolbar to subscribe to changes in this widget
|
||||
this.resizeObserver = null
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
if (this.state.attrs.layout){
|
||||
this.setLayout(this.state.attrs.layout.value)
|
||||
// console.log("prior layout: ", this.state.attrs.layout.value)
|
||||
}
|
||||
this.setLayout({layout: Layouts.PLACE, gap: 10})
|
||||
|
||||
// if (this.state.attrs.layout){
|
||||
// this.setLayout(this.state.attrs.layout.value)
|
||||
// // console.log("prior layout: ", this.state.attrs.layout.value)
|
||||
// }
|
||||
|
||||
if (this.state.attrs.styling.backgroundColor)
|
||||
this.setWidgetInnerStyle('backgroundColor', this.state.attrs.styling?.backgroundColor.value || "#fff")
|
||||
|
||||
this.load(this.props.initialData || {}) // load the initial data
|
||||
|
||||
// The elementRect is received only after the elemet is added so, it may not be accurate so use resize handler
|
||||
// this.resizeObserver = new MutationObserver(this.handleResizeEvents)
|
||||
// if (this.elementRef.current) {
|
||||
// // this.resizeObserver.observe(this.elementRef.current, { attributes: true})
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
|
||||
if (prevProps !== this.props) {
|
||||
this.canvasMetaData = this.props.canvasMetaData
|
||||
}
|
||||
|
||||
const compareAttrs = ['attrs', 'widgetName', 'parentLayout', 'positionType']
|
||||
|
||||
// TODO: maybe find more efficient way to update the canvas about teh child updates???
|
||||
if (!lo.isEqual(lo.pick(prevState, compareAttrs), lo.pick(this.state, compareAttrs))){
|
||||
// THIS IS inefficeint
|
||||
// this.props.requestThisWidgetDataUpdate(this.__id)
|
||||
// setTimeout(() => this.props.requestWidgetDataUpdate(this.__id), 1)
|
||||
this.props.requestWidgetDataUpdate(this.__id)
|
||||
}
|
||||
// call update widgets
|
||||
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
componentWillUnmount(){
|
||||
// this.resizeObserver.disconnect()
|
||||
}
|
||||
|
||||
// componentWillUnmount(){
|
||||
// // TODO: serialize and store the widget data in setWidgets under widget context especially initialData
|
||||
// console.log("unmounting widget: ", this.state.attrs, this.serialize())
|
||||
|
||||
// // this.props.onUnmount(this.__id, this.serialize())
|
||||
// }
|
||||
|
||||
|
||||
updateState = (newState, callback) => {
|
||||
stateChangeSubscriberCallback = (callback) => {
|
||||
// NOTE: don't subscribe to multiple callbacks, only the last one will work
|
||||
// allowing other components such as toolbar to subscribe to changes in this widget
|
||||
this.stateUpdateCallback = callback
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will notify the canvas of the updates to the widgets
|
||||
*
|
||||
* @param {} newState - this can either be a callback or a new State like (prevState) => ({key: value})
|
||||
* @param {*} callback - callback to run after setState
|
||||
*/
|
||||
updateState(newState, callback){
|
||||
// console.trace("Callback trace");
|
||||
// debugger;
|
||||
|
||||
// FIXME: maximum recursion error when updating size, color etc
|
||||
this.setState(newState, () => {
|
||||
// console.log("updatinhg./..: ", this.state, newState)
|
||||
|
||||
const { onWidgetUpdate } = this.props
|
||||
if (onWidgetUpdate) {
|
||||
onWidgetUpdate(this.__id)
|
||||
}
|
||||
|
||||
// const { activeWidgetId, updateToolAttrs } = this.context
|
||||
|
||||
if (this.stateUpdateCallback)
|
||||
this.stateUpdateCallback()
|
||||
|
||||
// if (activeWidgetId === this.__id)
|
||||
// updateToolAttrs(this.getToolbarAttrs())
|
||||
// FIXME: super inefficient
|
||||
// if (onWidgetUpdate) {
|
||||
// onWidgetUpdate(this.__id)
|
||||
// }
|
||||
|
||||
if (callback) callback()
|
||||
|
||||
@@ -308,6 +371,12 @@ class Widget extends React.Component {
|
||||
...this.state.attrs,
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
forceRerender = () => {
|
||||
// this.forceUpdate() // Don't use forceUpdate widgets will loose their states
|
||||
this.setState({forceRerenderId: `${uuidv4()}`})
|
||||
}
|
||||
|
||||
// TODO: add context menu items such as delete, add etc
|
||||
@@ -347,6 +416,10 @@ class Widget extends React.Component {
|
||||
return this.constructor.widgetType
|
||||
}
|
||||
|
||||
getDisplayName(){
|
||||
return this.constructor.displayName
|
||||
}
|
||||
|
||||
getRequirements(){
|
||||
return this.constructor.requirements
|
||||
}
|
||||
@@ -430,10 +503,6 @@ class Widget extends React.Component {
|
||||
return this.functions
|
||||
}
|
||||
|
||||
getId() {
|
||||
return this.__id
|
||||
}
|
||||
|
||||
getElement() {
|
||||
return this.elementRef.current
|
||||
}
|
||||
@@ -472,23 +541,30 @@ class Widget extends React.Component {
|
||||
* @param {string} path - path to the key, eg: styling.backgroundColor
|
||||
* @param {any} value
|
||||
*/
|
||||
setAttrValue(path, value) {
|
||||
const keys = path.split('.')
|
||||
const lastKey = keys.pop()
|
||||
setAttrValue(path, value, callback) {
|
||||
|
||||
|
||||
// Traverse the state and update the nested value immutably
|
||||
let newAttrs = { ...this.state.attrs }
|
||||
let nestedObject = newAttrs
|
||||
|
||||
keys.forEach(key => {
|
||||
nestedObject[key] = { ...nestedObject[key] } // Ensure immutability
|
||||
nestedObject = nestedObject[key]
|
||||
})
|
||||
|
||||
nestedObject[lastKey].value = value
|
||||
this.updateState((prevState) => { // since the setState is Async only the prevState contains the latest state
|
||||
const keys = path.split('.')
|
||||
const lastKey = keys.pop()
|
||||
|
||||
this.updateState({ attrs: newAttrs })
|
||||
// Traverse the state and update the nested value immutably
|
||||
let newAttrs = { ...prevState.attrs }
|
||||
let nestedObject = newAttrs
|
||||
|
||||
keys.forEach(key => {
|
||||
nestedObject[key] = { ...nestedObject[key] } // Ensure immutability
|
||||
nestedObject = nestedObject[key]
|
||||
})
|
||||
|
||||
if (nestedObject[lastKey]) {
|
||||
nestedObject[lastKey] = { ...nestedObject[lastKey], value }
|
||||
} else {
|
||||
nestedObject[lastKey] = { value }
|
||||
}
|
||||
|
||||
return { attrs: newAttrs }
|
||||
|
||||
}, callback)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -501,7 +577,6 @@ class Widget extends React.Component {
|
||||
|
||||
// Traverse the state and get the nested value
|
||||
let nestedObject = this.state.attrs
|
||||
|
||||
for (const key of keys) {
|
||||
if (nestedObject[key] !== undefined) {
|
||||
nestedObject = nestedObject[key]
|
||||
@@ -509,7 +584,6 @@ class Widget extends React.Component {
|
||||
return undefined // Return undefined if the key doesn't exist
|
||||
}
|
||||
}
|
||||
|
||||
return nestedObject?.value // Return the value (assuming it has a 'value' field)
|
||||
}
|
||||
|
||||
@@ -567,7 +641,8 @@ class Widget extends React.Component {
|
||||
* @param {Layouts} parentLayout
|
||||
*/
|
||||
setParentLayout(parentLayout){
|
||||
|
||||
// FIXME: changing from one layout to another isn't working as expected
|
||||
// TODO: add styleAreaRef to every where there is innerWidgetSTyle
|
||||
if (!parentLayout){
|
||||
// if parent layout is null (i,e the widget is on the canvas)
|
||||
return {}
|
||||
@@ -589,16 +664,29 @@ class Widget extends React.Component {
|
||||
|
||||
const elementRect = this.elementRef.current.getBoundingClientRect()
|
||||
// console.log("winner: ", this.props.parentWidgetRef.current.getBoundingRect())
|
||||
const parentRect = this.props.parentWidgetRef.current.getBoundingRect()
|
||||
const parentRect = this.props.parentWidgetRef.current?.getBoundingRect()
|
||||
|
||||
// FIXME: (low priority) once the place is moved and back to flex the position the updated position is not reflected
|
||||
let pos = {
|
||||
x: (elementRect.left - parentRect.left) / this.canvasMetaData.zoom,
|
||||
y: (elementRect.top - parentRect.top) / this.canvasMetaData.zoom
|
||||
x: (elementRect.left - (parentRect?.left || 0)) / this.canvasMetaData.zoom,
|
||||
y: (elementRect.top - (parentRect?.top || 0)) / this.canvasMetaData.zoom
|
||||
}
|
||||
|
||||
this.setPos(pos.x, pos.y)
|
||||
// console.log("setting pos: ", pos)
|
||||
|
||||
if (layout === Layouts.GRID){
|
||||
setTimeout(() => {
|
||||
const gridPos = getGridPosition(this.elementRef.current, this.props.parentWidgetRef.current.styleAreaRef.current)
|
||||
if (gridPos){
|
||||
this.setAttrValue("gridManager.row", gridPos.row)
|
||||
this.setAttrValue("gridManager.column", gridPos.column)
|
||||
this.setWidgetOuterStyle("gridRow", `${gridPos.row + ' / span ' + 1}`)
|
||||
this.setWidgetOuterStyle("gridColumn", `${gridPos.column + ' / span ' + 1}`)
|
||||
}
|
||||
|
||||
}, 1)
|
||||
}
|
||||
|
||||
}else if (layout === Layouts.PLACE){
|
||||
updates = {
|
||||
@@ -607,7 +695,7 @@ class Widget extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
this.setState(updates)
|
||||
this.setState((prevState) => ({...prevState, ...updates}))
|
||||
|
||||
return updates
|
||||
}
|
||||
@@ -617,8 +705,7 @@ class Widget extends React.Component {
|
||||
}
|
||||
|
||||
getLayout(){
|
||||
|
||||
return this.state?.attrs?.layout?.value || Layouts.FLEX
|
||||
return this.getAttrValue("layout") || {layout: Layouts.PLACE}
|
||||
}
|
||||
|
||||
setLayout(value) {
|
||||
@@ -631,30 +718,30 @@ class Widget extends React.Component {
|
||||
display: layout !== Layouts.PLACE ? layout : "block",
|
||||
flexDirection: direction,
|
||||
gap: `${gap}px`,
|
||||
flexWrap: "wrap",
|
||||
gridTemplateColumns: "repeat(auto-fill, minmax(100px, 1fr))",
|
||||
gridTemplateRows: "repeat(auto-fill, minmax(100px, 1fr))",
|
||||
// flexWrap: "wrap",
|
||||
gridTemplateColumns: "repeat(auto-fill, minmax(100px, auto))",
|
||||
gridTemplateRows: "repeat(auto-fill, minmax(100px, auto))",
|
||||
// gridAutoRows: 'minmax(100px, auto)', // Rows with minimum height of 100px, and grow to fit content
|
||||
// gridAutoCols: 'minmax(100px, auto)', // Cols with minimum height of 100px, and grow to fit content
|
||||
}
|
||||
|
||||
if (align === "start"){
|
||||
widgetStyle["placeContent"] = "flex-start"
|
||||
}else if (align === "center"){
|
||||
widgetStyle["placeContent"] = "center"
|
||||
}else if (align === "end"){
|
||||
widgetStyle["placeContent"] = "flex-end"
|
||||
}else{
|
||||
widgetStyle["placeContent"] = "unset"
|
||||
}
|
||||
// if (align === "start"){
|
||||
// widgetStyle["placeContent"] = "flex-start"
|
||||
// }else if (align === "center"){
|
||||
// widgetStyle["placeContent"] = "center"
|
||||
// }else if (align === "end"){
|
||||
// widgetStyle["placeContent"] = "flex-end"
|
||||
// }else{
|
||||
// widgetStyle["placeContent"] = "unset"
|
||||
// }
|
||||
|
||||
this.updateState({
|
||||
widgetInnerStyling: widgetStyle
|
||||
this.setAttrValue("layout", value, () => {
|
||||
this.updateState({
|
||||
widgetInnerStyling: widgetStyle
|
||||
})
|
||||
this.props.onLayoutUpdate({parentId: this.__id, parentLayout: value})// inform children about the layout update
|
||||
})
|
||||
|
||||
this.setAttrValue("layout", value)
|
||||
this.props.onLayoutUpdate({parentId: this.__id, parentLayout: value})// inform children about the layout update
|
||||
|
||||
}
|
||||
|
||||
getWidgetInnerStyle = (key) => {
|
||||
@@ -671,14 +758,17 @@ class Widget extends React.Component {
|
||||
* @param {string} value - Value of the style
|
||||
*/
|
||||
setWidgetOuterStyle(key, value){
|
||||
const widgetStyle = {
|
||||
...this.state.widgetOuterStyling,
|
||||
[key]: value
|
||||
}
|
||||
// const widgetStyle = {
|
||||
// ...this.state.widgetOuterStyling,
|
||||
// [key]: value
|
||||
// }
|
||||
|
||||
this.setState({
|
||||
widgetOuterStyling: widgetStyle
|
||||
})
|
||||
this.setState((prevState) => ({
|
||||
widgetOuterStyling: {
|
||||
...prevState.widgetOuterStyling,
|
||||
[key]: value
|
||||
}
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
@@ -688,15 +778,13 @@ class Widget extends React.Component {
|
||||
* @param {string} value - Value of the style
|
||||
*/
|
||||
setWidgetInnerStyle(key, value) {
|
||||
|
||||
const widgetStyle = {
|
||||
...this.state.widgetInnerStyling,
|
||||
[key]: value
|
||||
}
|
||||
|
||||
this.setState({
|
||||
widgetInnerStyling: widgetStyle
|
||||
})
|
||||
this.setState((prevState) => ({
|
||||
widgetInnerStyling: {
|
||||
...prevState.widgetInnerStyling,
|
||||
[key]: value
|
||||
}
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
@@ -732,14 +820,14 @@ class Widget extends React.Component {
|
||||
})
|
||||
}
|
||||
|
||||
openRenaming() {
|
||||
openRenaming = () => {
|
||||
this.select()
|
||||
this.setState({
|
||||
selected: true,
|
||||
enableRename: true
|
||||
})
|
||||
}
|
||||
|
||||
closeRenaming() {
|
||||
closeRenaming = () => {
|
||||
this.setState({
|
||||
enableRename: false
|
||||
})
|
||||
@@ -764,17 +852,27 @@ class Widget extends React.Component {
|
||||
*/
|
||||
serialize(){
|
||||
// NOTE: when serializing make sure, you are only passing serializable objects not functions or other
|
||||
|
||||
const elementRect = this.getBoundingRect()
|
||||
|
||||
const pos = {
|
||||
x: elementRect.x,
|
||||
y: elementRect.y
|
||||
}
|
||||
|
||||
return ({
|
||||
zIndex: this.state.zIndex,
|
||||
selected: this.state.selected,
|
||||
widgetName: this.state.widgetName,
|
||||
pos: this.state.pos,
|
||||
// pos: this.state.pos,
|
||||
pos: pos,
|
||||
size: this.state.size,
|
||||
widgetContainer: this.state.widgetContainer,
|
||||
widgetInnerStyling: this.state.widgetInnerStyling,
|
||||
widgetOuterStyling: this.state.widgetOuterStyling,
|
||||
parentLayout: this.state.parentLayout,
|
||||
positionType: this.state.positionType,
|
||||
attrs: this.serializeAttrsValues() // makes sure that functions are not serialized
|
||||
attrs: this.serializeAttrsValues(), // makes sure that functions are not serialized
|
||||
})
|
||||
|
||||
}
|
||||
@@ -790,11 +888,13 @@ class Widget extends React.Component {
|
||||
|
||||
data = {...data} // create a shallow copy
|
||||
|
||||
const {attrs, parentLayout, ...restData} = data
|
||||
const {attrs={}, selected, pos={x: 0, y: 0}, ...restData} = data
|
||||
|
||||
const parentLayout = this.props.parentWidgetRef?.current?.getLayout() // don't get the parentLayout from serialized data as it may have become stale
|
||||
|
||||
|
||||
let layoutUpdates = {
|
||||
parentLayout: parentLayout.layout || null
|
||||
parentLayout: parentLayout?.layout || null
|
||||
}
|
||||
|
||||
if (parentLayout?.layout === Layouts.FLEX || parentLayout?.layout === Layouts.GRID){
|
||||
@@ -814,7 +914,8 @@ class Widget extends React.Component {
|
||||
|
||||
const newData = {
|
||||
...restData,
|
||||
...layoutUpdates
|
||||
...layoutUpdates,
|
||||
pos
|
||||
}
|
||||
|
||||
this.setState(newData, () => {
|
||||
@@ -846,6 +947,9 @@ class Widget extends React.Component {
|
||||
|
||||
this.updateState({ attrs: newAttrs }, callback)
|
||||
|
||||
if (selected){
|
||||
this.select()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1033,21 +1137,17 @@ class Widget extends React.Component {
|
||||
|
||||
} else if (container === WidgetContainer.SIDEBAR) {
|
||||
|
||||
// const { initialPos } = posMetaData
|
||||
|
||||
// const canvasInnerRect = this.props.canvasInnerContainerRef.current.getBoundingClientRect()
|
||||
|
||||
// const newInitialPos = {
|
||||
// x: (initialPos.x - canvasInnerRect.left),
|
||||
// y: (initialPos.y - canvasInnerRect.top)
|
||||
// }
|
||||
const canvasRect = this.props.canvasInnerContainerRef.current.getBoundingClientRect()
|
||||
|
||||
// posMetaData = {
|
||||
// ...posMetaData,
|
||||
// initialPos: newInitialPos,
|
||||
// }
|
||||
// console.log("Dropped on Sidebar: ", this.__id)
|
||||
this.props.onCreateWidgetRequest(widgetClass, ({ id, widgetRef }) => {
|
||||
const {zoom, pan} = this.props.canvasMetaData
|
||||
|
||||
let initialPos = {
|
||||
x: (e.clientX - canvasRect.left) / zoom,
|
||||
y: (e.clientY - canvasRect.top) / zoom,
|
||||
}
|
||||
|
||||
this.props.onCreateWidgetRequest(widgetClass, {x: initialPos.x, y: initialPos.y},({ id, widgetRef }) => {
|
||||
this.props.onAddChildWidget({
|
||||
event: e,
|
||||
parentWidgetId: this.__id,
|
||||
@@ -1131,6 +1231,7 @@ class Widget extends React.Component {
|
||||
let fitHeight = this.state.fitContent.height
|
||||
|
||||
if (fitWidth){
|
||||
// width = "max-content"
|
||||
width = "max-content"
|
||||
}
|
||||
|
||||
@@ -1141,6 +1242,12 @@ class Widget extends React.Component {
|
||||
// if fit width is enabled then the minsize is the resizable size
|
||||
let minWidth = fitWidth ? this.state.size.width : this.minSize.width
|
||||
let minHeight = fitHeight ? this.state.size.height : this.minSize.height
|
||||
|
||||
// let minWidth = fitWidth ? "max-content" : this.minSize.width
|
||||
// let minHeight = fitHeight ? "max-content" : this.minSize.height
|
||||
|
||||
// let minWidth = this.minSize.width
|
||||
// let minHeight = this.minSize.height
|
||||
|
||||
return {width, height, minWidth, minHeight}
|
||||
|
||||
@@ -1159,6 +1266,31 @@ class Widget extends React.Component {
|
||||
)
|
||||
}
|
||||
|
||||
// requestUpdateWidgetPos = () => {
|
||||
// const canvasRectInner = this.props.canvasInnerContainerRef?.current?.getBoundingClientRect();
|
||||
// const elementRect = this.getBoundingRect();
|
||||
// const { zoom } = this.props.canvasMetaData;
|
||||
|
||||
// const left = ((elementRect?.left || 0) - canvasRectInner?.left) / zoom - 10;
|
||||
// const top = ((elementRect?.top || 0) - canvasRectInner?.top) / zoom - 10;
|
||||
|
||||
// this.setState({ pos: {x: left, y: top} });
|
||||
// }
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {"sw"|"ne"|"se"|"nw"|null} side
|
||||
*/
|
||||
handleWidgetResize = (side) => {
|
||||
if (side){
|
||||
this.props.onWidgetResizing(side)
|
||||
this.setState({ dragEnabled: false })
|
||||
}else{
|
||||
this.setState({ dragEnabled: true })
|
||||
this.props.onWidgetResizing("")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an internal methods don't override
|
||||
* @returns {HTMLElement}
|
||||
@@ -1170,14 +1302,15 @@ class Widget extends React.Component {
|
||||
// NOTE: first check tkinter behaviour with the width and height
|
||||
|
||||
let outerStyle = {
|
||||
|
||||
...this.state.widgetOuterStyling,
|
||||
width: width,
|
||||
height: height,
|
||||
cursor: this.cursor,
|
||||
zIndex: this.state.zIndex,
|
||||
position: this.state.positionType, // don't change this if it has to be movable on the canvas
|
||||
top: `${this.state.pos.y}px`,
|
||||
left: `${this.state.pos.x}px`,
|
||||
width: width,
|
||||
height: height,
|
||||
minWidth: minWidth,
|
||||
minHeight: minHeight,
|
||||
opacity: this.state.isDragging ? 0.3 : 1,
|
||||
@@ -1211,10 +1344,8 @@ class Widget extends React.Component {
|
||||
|
||||
// const boundingRect = this.getBoundingRect
|
||||
|
||||
const {zoom: canvasZoom, pan: canvasPan} = this.canvasMetaData
|
||||
|
||||
|
||||
const elementRect = this.elementRef.current?.getBoundingClientRect()
|
||||
|
||||
return (
|
||||
|
||||
<DragContext.Consumer>
|
||||
@@ -1224,139 +1355,72 @@ class Widget extends React.Component {
|
||||
// const canvasRect = this.canvas.getBoundingClientRect()
|
||||
const canvasRectInner = this.props.canvasInnerContainerRef?.current?.getBoundingClientRect()
|
||||
|
||||
const elementRect = this.getBoundingRect()
|
||||
|
||||
const {zoom, pan} = this.props.canvasMetaData
|
||||
|
||||
const left = ((elementRect?.left || 0) - canvasRectInner?.left) / canvasZoom - 10
|
||||
const top = ((elementRect?.top || 0) - canvasRectInner?.top) / canvasZoom - 10
|
||||
const {zoom} = this.props.canvasMetaData
|
||||
|
||||
return (
|
||||
|
||||
<div data-widget-id={this.__id}
|
||||
ref={this.elementRef}
|
||||
className={`tw-shadow-xl tw-w-fit tw-h-fit ${!this.state.isWidgetVisible ? "tw-hidden" : ""}`}
|
||||
style={outerStyle}
|
||||
data-draggable-type={this.getWidgetType()} // helps with droppable
|
||||
data-container={this.state.widgetContainer} // indicates how the canvas should handle dragging, one is sidebar other is canvas
|
||||
ref={this.elementRef}
|
||||
className={`tw-shadow-xl tw-w-fit tw-h-fit ${!this.state.isWidgetVisible ? "tw-hidden" : ""}`}
|
||||
style={outerStyle}
|
||||
data-draggable-type={this.getWidgetType()} // helps with droppable
|
||||
data-container={this.state.widgetContainer} // indicates how the canvas should handle dragging, one is sidebar other is canvas
|
||||
|
||||
data-drag-start-within // this attribute indicates that the drag is occurring from within the project and not a outside file drop
|
||||
data-drag-start-within // this attribute indicates that the drag is occurring from within the project and not a outside file drop
|
||||
|
||||
draggable={this.state.dragEnabled}
|
||||
draggable={this.state.dragEnabled}
|
||||
|
||||
onDragOver={(e) => this.handleDragOver(e, draggedElement)}
|
||||
onDrop={(e) => {this.handleDropEvent(e, draggedElement, widgetClass, posMetaData); onDragEnd()}}
|
||||
onDragOver={(e) => this.handleDragOver(e, draggedElement)}
|
||||
onDrop={(e) => {this.handleDropEvent(e, draggedElement, widgetClass, posMetaData); onDragEnd()}}
|
||||
|
||||
onDragEnter={(e) => this.handleDragEnter(e, draggedElement, setOverElement)}
|
||||
onDragLeave={(e) => this.handleDragLeave(e, draggedElement, overElement)}
|
||||
onDragEnter={(e) => this.handleDragEnter(e, draggedElement, setOverElement)}
|
||||
onDragLeave={(e) => this.handleDragLeave(e, draggedElement, overElement)}
|
||||
|
||||
onDragStart={(e) => this.handleDragStart(e, onDragStart)}
|
||||
onDragEnd={(e) => this.handleDragEnd(onDragEnd)}
|
||||
onDragStart={(e) => this.handleDragStart(e, onDragStart)}
|
||||
onDragEnd={(e) => this.handleDragEnd(onDragEnd)}
|
||||
|
||||
// onPointerDown={setInitialPos}
|
||||
onPointerDown={(e) => handleSetInitialPosition(e, setPosMetaData)}
|
||||
>
|
||||
<div className="tw-relative tw-w-full tw-h-full tw-top-0 tw-left-0"
|
||||
// onPointerDown={setInitialPos}
|
||||
onPointerDown={(e) => handleSetInitialPosition(e, setPosMetaData)}
|
||||
>
|
||||
<div className="tw-relative tw-w-full tw-h-full tw-top-0 tw-left-0"
|
||||
|
||||
>
|
||||
|
||||
>
|
||||
|
||||
|
||||
<div className="tw-relative tw-top-0 tw-left-0 tw-w-full tw-h-full" ref={this.innerAreaRef}
|
||||
>
|
||||
{this.renderContent()}
|
||||
</div>
|
||||
{
|
||||
// show drop style on drag hover
|
||||
draggedElement && this.state.showDroppableStyle.show &&
|
||||
<div className={`${this.state.showDroppableStyle.allow ? "tw-border-blue-600" : "tw-border-red-600"}
|
||||
tw-absolute tw-top-[-5px] tw-left-[-5px] tw-w-full tw-h-full tw-z-[2]
|
||||
tw-border-2 tw-border-dashed tw-rounded-lg tw-pointer-events-none
|
||||
|
||||
`}
|
||||
style={{
|
||||
width: "calc(100% + 10px)",
|
||||
height: "calc(100% + 10px)",
|
||||
}}
|
||||
>
|
||||
<div className="tw-relative tw-top-0 tw-left-0 tw-w-full tw-h-full" ref={this.innerAreaRef}
|
||||
>
|
||||
{this.renderContent()}
|
||||
</div>
|
||||
}
|
||||
|
||||
<div className={`tw-fixed tw-pointer-events-none tw-bg-transparent tw-opacity-100
|
||||
${this.state.selected ? 'tw-border-2 tw-border-solid tw-border-blue-500' : 'tw-hidden'}`}
|
||||
style={{
|
||||
|
||||
position: "fixed", // transforms are applied on parent so its going to be relative to parent
|
||||
left: left,
|
||||
top: top,
|
||||
{
|
||||
// show drop style on drag hover
|
||||
draggedElement && this.state.showDroppableStyle.show &&
|
||||
<div className={`${this.state.showDroppableStyle.allow ? "tw-border-blue-600" : "tw-border-red-600"}
|
||||
tw-absolute tw-top-[-5px] tw-left-[-5px] tw-w-full tw-h-full tw-z-[2]
|
||||
tw-border-2 tw-border-dashed tw-rounded-lg tw-pointer-events-none
|
||||
|
||||
// width: this.state.size.width + 20,
|
||||
// height: this.state.size.height + 20,
|
||||
// TODO: this isn't smooth when zooming
|
||||
width: (elementRect?.width/zoom || this.state.size.width) + 20,
|
||||
height: (elementRect?.height/zoom || this.state.size.height) + 20,
|
||||
zIndex: 1,
|
||||
}}
|
||||
>
|
||||
`}
|
||||
style={{
|
||||
width: "calc(100% + 10px)",
|
||||
height: "calc(100% + 10px)",
|
||||
}}
|
||||
>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div className={`"tw-relative tw-w-full tw-h-full"`}> {/* ${this.state.isDragging ? "tw-pointer-events-none" : "tw-pointer-events-auto"} */}
|
||||
<EditableDiv value={this.state.widgetName} onChange={this.setWidgetName}
|
||||
maxLength={40}
|
||||
openEdit={this.state.enableRename}
|
||||
className="tw-text-sm tw-w-fit tw-max-w-[160px] tw-text-clip tw-min-w-[150px]
|
||||
tw-overflow-hidden tw-absolute tw--top-6 tw-h-6"
|
||||
/>
|
||||
|
||||
<div
|
||||
className="tw-w-2 tw-h-2 tw-rounded-full tw-absolute tw-pointer-events-auto tw--left-1 tw--top-1 tw-bg-blue-500"
|
||||
style={{ cursor: Cursor.NW_RESIZE }}
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
this.props.onWidgetResizing("nw")
|
||||
this.setState({ dragEnabled: false })
|
||||
}}
|
||||
onMouseUp={() => this.setState({ dragEnabled: true })}
|
||||
/>
|
||||
<div
|
||||
className="tw-w-2 tw-h-2 tw-rounded-full tw-absolute tw-pointer-events-auto tw--right-1 tw--top-1 tw-bg-blue-500"
|
||||
style={{ cursor: Cursor.SW_RESIZE }}
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
this.props.onWidgetResizing("ne")
|
||||
this.setState({ dragEnabled: false })
|
||||
}}
|
||||
onMouseUp={() => this.setState({ dragEnabled: true })}
|
||||
/>
|
||||
<div
|
||||
className="tw-w-2 tw-h-2 tw-rounded-full tw-absolute tw-pointer-events-auto tw--left-1 tw--bottom-1 tw-bg-blue-500"
|
||||
style={{ cursor: Cursor.SW_RESIZE }}
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
this.props.onWidgetResizing("sw")
|
||||
this.setState({ dragEnabled: false })
|
||||
}}
|
||||
onMouseUp={() => this.setState({ dragEnabled: true })}
|
||||
/>
|
||||
<div
|
||||
className="tw-w-2 tw-h-2 tw-rounded-full tw-absolute tw-pointer-events-auto tw--right-1 tw--bottom-1 tw-bg-blue-500"
|
||||
style={{ cursor: Cursor.SE_RESIZE }}
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
this.props.onWidgetResizing("se")
|
||||
this.setState({ dragEnabled: false })
|
||||
}}
|
||||
onMouseUp={() => this.setState({ dragEnabled: true })}
|
||||
/>
|
||||
|
||||
</div>
|
||||
<ResizeHandle
|
||||
canvasRect={canvasRectInner}
|
||||
canvasZoom={zoom}
|
||||
elementRef={this.elementRef}
|
||||
show={this.state.selected}
|
||||
onWidgetResizing={this.handleWidgetResize}
|
||||
enableRename={this.state.enableRename}
|
||||
widgetName={this.state.widgetName}
|
||||
setWidgetName={this.setWidgetName}
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1368,5 +1432,138 @@ class Widget extends React.Component {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* a component that displays resize handles, don't remove this function and try to add it directly
|
||||
* to base widget as with base widget getBoundingClient rect is always stale without useEffect
|
||||
*
|
||||
* // TODO: make this smoother
|
||||
*
|
||||
*/
|
||||
function ResizeHandle({elementRef, show, canvasRect,
|
||||
canvasZoom, onWidgetResizing,
|
||||
widgetName, setWidgetName, enableRename
|
||||
}){
|
||||
const [rect, setRect] = useState({
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: 0,
|
||||
height: 0
|
||||
})
|
||||
|
||||
const timeoutRef = useRef(null)
|
||||
const isResizingRef = useRef(false)
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!elementRef.current)
|
||||
return
|
||||
|
||||
const updateRect = () => {
|
||||
const elementRect = elementRef.current?.getBoundingClientRect()
|
||||
|
||||
if (!elementRect){
|
||||
return
|
||||
}
|
||||
|
||||
const left = ((elementRect.left || 0) - canvasRect.left) / canvasZoom - 10;
|
||||
const top = ((elementRect.top || 0) - canvasRect.top) / canvasZoom - 10;
|
||||
const width = (elementRect.width / canvasZoom) + 20;
|
||||
const height = (elementRect.height / canvasZoom) + 20;
|
||||
setRect({ left, top, width, height });
|
||||
}
|
||||
|
||||
clearTimeout(timeoutRef.current);
|
||||
|
||||
if (!isResizingRef.current)
|
||||
timeoutRef.current = setTimeout(updateRect, 16); // ~60fps
|
||||
|
||||
else{
|
||||
updateRect()
|
||||
}
|
||||
|
||||
}, [elementRef, canvasZoom, canvasRect, enableRename])
|
||||
|
||||
const handleResizing = (side) => {
|
||||
|
||||
onWidgetResizing(side)
|
||||
|
||||
if (side){
|
||||
isResizingRef.current = true
|
||||
}else{
|
||||
isResizingRef.current = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`tw-fixed tw-pointer-events-none tw-bg-transparent tw-opacity-100
|
||||
${show ? 'tw-border-2 tw-border-solid tw-border-blue-500' : 'tw-hidden'}`}
|
||||
style={{
|
||||
|
||||
position: "fixed", // transforms are applied on parent so its going to be relative to parent
|
||||
left: rect.left,
|
||||
top: rect.top,
|
||||
width: rect.width, // (elementRect?.width/zoom || this.state.size.width) + 20,
|
||||
height: rect.height, //(elementRect?.height/zoom || this.state.size.height) + 20,
|
||||
zIndex: 1,
|
||||
}}
|
||||
>
|
||||
|
||||
<div className={`"tw-relative tw-w-full tw-h-full"`}> {/* ${this.state.isDragging ? "tw-pointer-events-none" : "tw-pointer-events-auto"} */}
|
||||
<EditableDiv value={widgetName} onChange={setWidgetName}
|
||||
maxLength={40}
|
||||
openEdit={enableRename}
|
||||
className="tw-text-sm tw-w-fit tw-max-w-[160px] tw-text-clip tw-min-w-[150px]
|
||||
tw-overflow-hidden tw-absolute tw--top-6 tw-h-6"
|
||||
/>
|
||||
|
||||
<div
|
||||
className="tw-w-2 tw-h-2 tw-rounded-full tw-absolute tw-pointer-events-auto tw--left-1 tw--top-1 tw-bg-blue-500"
|
||||
style={{ cursor: Cursor.NW_RESIZE }}
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
handleResizing("nw")
|
||||
}}
|
||||
onMouseUp={() => handleResizing(null)}
|
||||
/>
|
||||
<div
|
||||
className="tw-w-2 tw-h-2 tw-rounded-full tw-absolute tw-pointer-events-auto tw--right-1 tw--top-1 tw-bg-blue-500"
|
||||
style={{ cursor: Cursor.SW_RESIZE }}
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
handleResizing("ne")
|
||||
}}
|
||||
onMouseUp={() => handleResizing(null)}
|
||||
/>
|
||||
<div
|
||||
className="tw-w-2 tw-h-2 tw-rounded-full tw-absolute tw-pointer-events-auto tw--left-1 tw--bottom-1 tw-bg-blue-500"
|
||||
style={{ cursor: Cursor.SW_RESIZE }}
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
handleResizing("sw")
|
||||
}}
|
||||
onMouseUp={() => handleResizing(null)}
|
||||
/>
|
||||
<div
|
||||
className="tw-w-2 tw-h-2 tw-rounded-full tw-absolute tw-pointer-events-auto tw--right-1 tw--bottom-1 tw-bg-blue-500"
|
||||
style={{ cursor: Cursor.SE_RESIZE }}
|
||||
onMouseDown={(e) => {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
handleResizing("se")
|
||||
}}
|
||||
onMouseUp={() => handleResizing(null)}
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export default Widget
|
||||
@@ -3,6 +3,7 @@ import { useDragWidgetContext } from "./draggableWidgetContext"
|
||||
import { useDragContext } from "../../components/draggable/draggableContext"
|
||||
|
||||
|
||||
// NOTE: not in use
|
||||
// FIXME: sometimes even after drag end the showDroppable is visible
|
||||
/**
|
||||
* @param {} - widgetRef - the widget ref for your widget
|
||||
|
||||
@@ -42,7 +42,7 @@ export function SidebarWidgetCard({ name, img, url, license, widgetClass, innerR
|
||||
<div ref={innerRef} className="tw-select-none tw-h-[200px] tw-w-[230px] tw-flex tw-flex-col
|
||||
tw-rounded-md tw-overflow-hidden
|
||||
tw-gap-2 tw-text-gray-600 tw-bg-[#ffffff44] tw-border-solid tw-border-[1px]
|
||||
tw-border-blue-500 tw-shadow-md">
|
||||
tw-border-gray-500 tw-shadow-md">
|
||||
<div className="tw-h-[200px] tw-pointer-events-none tw-w-full tw-overflow-hidden">
|
||||
<img src={img} alt={name} className="tw-object-contain tw-h-full tw-w-full tw-select-none" />
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
import { Select, Input, Button } from "antd"
|
||||
import { CrownFilled, DownloadOutlined, DownOutlined } from "@ant-design/icons"
|
||||
import { CrownFilled, DownloadOutlined, DownOutlined, PlayCircleFilled, VideoCameraOutlined } from "@ant-design/icons"
|
||||
import FrameWorks from "../constants/frameworks"
|
||||
import Premium from "../sidebar/utils/premium"
|
||||
import VideoPopUp from "./video-popup"
|
||||
|
||||
|
||||
const items = [
|
||||
@@ -23,19 +24,36 @@ function Header({projectName, onProjectNameChange, framework, onFrameworkChange,
|
||||
|
||||
|
||||
return (
|
||||
<div className={`tw-w-full tw-bg-primaryBg tw-p-2 tw-flex tw-place-items-center
|
||||
<div className={`tw-w-full tw-bg-primaryBg tw-gap-2 tw-overflow-x-auto tw-p-2 tw-flex tw-place-items-center
|
||||
${className||''}`}>
|
||||
|
||||
<Select
|
||||
// defaultValue={framework}
|
||||
value={framework}
|
||||
options={items}
|
||||
// onSelect={(key) => {console.log("value: ", key); onFrameworkChange(key); }}
|
||||
onChange={(key) => {onFrameworkChange(key)}}
|
||||
className="tw-min-w-[150px]"
|
||||
/>
|
||||
|
||||
<div className="tw-flex tw-gap-2 tw-place-content-center">
|
||||
<Select
|
||||
// defaultValue={framework}
|
||||
value={framework}
|
||||
options={items}
|
||||
// onSelect={(key) => {console.log("value: ", key); onFrameworkChange(key); }}
|
||||
onChange={(key) => {onFrameworkChange(key)}}
|
||||
className="tw-min-w-[150px]"
|
||||
/>
|
||||
<VideoPopUp>
|
||||
<div className="tw-p-1 tw-w-full tw-outline-none tw-bg-transparent tw-border-[1px]
|
||||
tw-border-gray-400 tw-rounded-md tw-no-underline tw-border-solid hover:tw-bg-[#9333EA]
|
||||
hover:tw-text-white tw-duration-200 tw-flex tw-gap-1
|
||||
tw-text-black tw-text-center tw-px-4 tw-text-sm tw-cursor-pointer">
|
||||
Watch demo
|
||||
<PlayCircleFilled className="tw-text-lg"/>
|
||||
</div>
|
||||
</VideoPopUp>
|
||||
</div>
|
||||
<div className="tw-ml-auto tw-flex tw-gap-2 tw-place-content-center">
|
||||
<button data-tally-open="mVDY7N" data-tally-layout="modal" data-tally-emoji-text="👋"
|
||||
data-tally-emoji-animation="wave" className="tw-p-1 tw-w-full tw-outline-none tw-bg-transparent tw-border-[1px]
|
||||
tw-border-gray-400 tw-rounded-md tw-no-underline tw-border-solid hover:tw-bg-[#9333EA]
|
||||
hover:tw-text-white tw-duration-200
|
||||
tw-text-black tw-text-center tw-px-4 tw-text-sm tw-cursor-pointer">
|
||||
Get Updates
|
||||
</button>
|
||||
<Premium className="tw-text-2xl tw-bg-purple-600 tw-text-center
|
||||
tw-w-[40px] tw-min-w-[40px] tw-h-[35px] tw-rounded-md
|
||||
tw-cursor-pointer tw-text-white
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useState, useRef } from "react"
|
||||
import { Input, Button, Space, Radio } from "antd"
|
||||
import { Input, Button, Space, Radio, InputNumber } from "antd"
|
||||
import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons"
|
||||
import { SearchOutlined, CloseCircleFilled } from '@ant-design/icons'
|
||||
|
||||
@@ -87,19 +87,20 @@ export const DynamicInputList = () => {
|
||||
}
|
||||
|
||||
|
||||
export const DynamicRadioInputList = React.memo(({defaultInputs=[""], defaultSelected=null, onChange}) => {
|
||||
const [inputs, setInputs] = useState([""]) // Initialize with one input
|
||||
const [selectedRadio, setSelectedRadio] = useState(null) // Tracks selected radio button
|
||||
export const DynamicRadioInputList = React.memo(({defaultInputs, defaultSelected=null, onChange}) => {
|
||||
const [inputs, setInputs] = useState(defaultInputs || [""]) // Initialize with one input
|
||||
const [selectedRadio, setSelectedRadio] = useState(defaultSelected) // Tracks selected radio button
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
setInputs(defaultInputs)
|
||||
setInputs(defaultInputs || [""])
|
||||
|
||||
}, [defaultInputs])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
setSelectedRadio(defaultSelected)
|
||||
|
||||
}, [defaultSelected])
|
||||
|
||||
useEffect(() => {
|
||||
@@ -165,4 +166,95 @@ export const DynamicRadioInputList = React.memo(({defaultInputs=[""], defaultSel
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* defaultWeightMapping structure: {0: {gridNo: 0, weight: 0}}
|
||||
*/
|
||||
export const DynamicGridWeightInput = React.memo(({value, onChange, gridInputProps, weightInputProps}) => {
|
||||
|
||||
const [weightMapping, setWeightMapping] = useState(value) // Initialize with one input
|
||||
|
||||
useEffect(() => {
|
||||
setWeightMapping(value || {})
|
||||
}, [value])
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
if(onChange){
|
||||
onChange(weightMapping)
|
||||
}
|
||||
|
||||
}, [weightMapping])
|
||||
|
||||
// Add a new input
|
||||
const addInput = () => {
|
||||
|
||||
const newObjectIndex = Object.keys(weightMapping).length
|
||||
setWeightMapping({...weightMapping, [newObjectIndex]: {gridNo: 1, weight: 0}})
|
||||
}
|
||||
|
||||
// Remove an input by index, but keep the first one
|
||||
const removeInput = (index) => {
|
||||
const newInputs = { ...weightMapping }; // Create a shallow copy
|
||||
delete newInputs[index]; // Remove the entry by key
|
||||
setWeightMapping(newInputs); // Update state
|
||||
}
|
||||
|
||||
// Update input value
|
||||
const handleGridNoChange = (index, gridNo, weight) => {
|
||||
const newInputs = {...weightMapping}
|
||||
newInputs[index] = {
|
||||
weight,
|
||||
gridNo
|
||||
}
|
||||
setWeightMapping(newInputs)
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
{weightMapping && Object.entries(weightMapping).map(([idx, {weight, gridNo}], index) => (
|
||||
<Space key={index} style={{ display: "flex", marginBottom: 8 }} align="baseline">
|
||||
|
||||
<div className="tw-flex tw-flex-col tw-gap-2">
|
||||
{ index === 0 &&
|
||||
<span>Grid no</span>
|
||||
}
|
||||
<InputNumber
|
||||
value={gridNo}
|
||||
min={1}
|
||||
onChange={(value) => handleGridNoChange(idx, value, weight)}
|
||||
placeholder={`Input ${index + 1}`}
|
||||
{...gridInputProps}
|
||||
/>
|
||||
</div>
|
||||
<div className="tw-flex tw-flex-col tw-gap-2">
|
||||
{ index === 0 &&
|
||||
<span>Weight</span>
|
||||
}
|
||||
<InputNumber
|
||||
min={0}
|
||||
value={weight}
|
||||
onChange={(value) => handleGridNoChange(idx, gridNo, value)}
|
||||
placeholder={`Input ${index + 1}`}
|
||||
{...weightInputProps}
|
||||
/>
|
||||
</div>
|
||||
{/* {index !== 0 && ( // Do not show delete button for the first input */}
|
||||
<div>
|
||||
<MinusCircleOutlined className="tw-text-xl tw-text-red-500"
|
||||
onClick={() => removeInput(index)} />
|
||||
</div>
|
||||
{/* )} */}
|
||||
</Space>
|
||||
))}
|
||||
|
||||
<Button type="dashed" onClick={addInput} icon={<PlusOutlined />}>
|
||||
Add Weight
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
47
src/components/video-popup.js
Normal file
47
src/components/video-popup.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Modal } from "antd"
|
||||
import { useState } from "react"
|
||||
|
||||
|
||||
const VideoPopUp = ({children, url}) => {
|
||||
|
||||
const [popUpOpen, setPopUpOpen] = useState(false)
|
||||
|
||||
|
||||
const handleVideoOpen = () => {
|
||||
setPopUpOpen(true)
|
||||
}
|
||||
|
||||
const handleVideoClose = (event) => {
|
||||
event.stopPropagation()
|
||||
|
||||
setPopUpOpen(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div onClick={handleVideoOpen} >
|
||||
{children}
|
||||
|
||||
<Modal title={"demo"}
|
||||
style={{ zIndex: 14000, gap: '5px', placeContent: "center", }}
|
||||
className="max-xl:tw-max-w-full max-lg:!tw-max-h-[450px]"
|
||||
styles={{body: {height: "80vh", width: "100%"}, content: {width: "100%",}}}
|
||||
onCancel={handleVideoClose}
|
||||
centered
|
||||
onOk={handleVideoClose}
|
||||
footer={null}
|
||||
width={'90%'}
|
||||
height={1000}
|
||||
open={popUpOpen}>
|
||||
<div className="tw-mt-5 tw-text-lg tw-min-w-[350px] tw-rounded-md tw-overflow-hidden tw-h-full tw-w-full ">
|
||||
<iframe src="https://www.youtube.com/embed/MkeMv0X-w_4?si=lJNCB18a2XKdY7Y6"
|
||||
className="tw-w-full tw-h-full"
|
||||
title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen>
|
||||
</iframe>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default VideoPopUp
|
||||
@@ -3,684 +3,20 @@ Github username: PaulleDemon
|
||||
|
||||
Below is the License for source code of PyUIBuilder. For license regarding source code generated by PyUIBuilder Refer Readme.md file (it has basically no restrictions).
|
||||
|
||||
The source code for PyUIBuilder is Dual licensed, some parts of the code comes under AGPL,
|
||||
some parts under a different non-commercial use license.
|
||||
|
||||
|
||||
-----------------------
|
||||
|
||||
The source code for PyUIBuilder is Dual licensed, most parts of the code comes under AGPL,
|
||||
some parts under a different non-commercial use license. Read the second part after the definition of the AGPL license.
|
||||
|
||||
Sub-folders with non-commercial use license will contain the second license as well.
|
||||
|
||||
--------------------------
|
||||
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
--------------------------
|
||||
|
||||
License for non-commercial use in short
|
||||
License in short
|
||||
* You are free fork, modify and redistribute it given the original or derived works is kept free and open-source and under the same licese.
|
||||
* Another restriction is you can't redistribute in binary or executable formats without asking me first.
|
||||
* If you plan on making money on this work or derived work you need permission first.
|
||||
* No AI Training on this source code
|
||||
|
||||
License was planned to be kept under one AGPL or less restrictive license, but since its difficult for me to continue providing free and open-source software without proper funding. It's under this license.
|
||||
|
||||
Once there enough money to fund this project and my upcoming FOSS projects, The license will be brought back to a single AGPL or much lesser restrictive license. The fastest way to make this happen is by purchasing a one-time license or fund me.
|
||||
|
||||
Read the full license below.
|
||||
--------------------
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
export const Tkinter_TO_WEB_CURSOR_MAPPING = {
|
||||
|
||||
"": "",
|
||||
"arrow": "default",
|
||||
"circle": "wait",
|
||||
"clock": "wait",
|
||||
|
||||
@@ -20,5 +20,25 @@ export const ANCHOR = [
|
||||
"s",
|
||||
"e",
|
||||
"w",
|
||||
"center"
|
||||
]
|
||||
"center",
|
||||
"ne",
|
||||
"se",
|
||||
"sw",
|
||||
"nw",
|
||||
]
|
||||
|
||||
|
||||
export const GRID_STICKY = {
|
||||
N: "n",
|
||||
S: "s",
|
||||
E: "e",
|
||||
W: "w",
|
||||
WE: "we",
|
||||
NS: "ns",
|
||||
NW: "nw",
|
||||
NE: "ne",
|
||||
SW: "sw",
|
||||
SE: "se",
|
||||
NEWS: "news",
|
||||
NONE: "",
|
||||
}
|
||||
@@ -117,7 +117,7 @@ async function generateCustomTkCode(projectName, widgetList=[], widgetRefs=[], a
|
||||
|
||||
// TODO: avoid adding \n inside the list instead rewrite using code.join("\n")
|
||||
const code = [
|
||||
"# This code is generated by PyUIbuilder: https://github.com/PaulleDemon/PyUIBuilder",
|
||||
"# This code is generated by PyUIbuilder: https://pyuibuilder.com",
|
||||
"\n\n",
|
||||
...imports.flatMap((item, index) => index < imports.length - 1 ? [item, "\n"] : [item]), //add \n to every line
|
||||
"\n\n",
|
||||
|
||||
@@ -20,6 +20,7 @@ const Themes = {
|
||||
class AnalogTimePicker extends CustomTkBase{
|
||||
|
||||
static widgetType = "analog_timepicker"
|
||||
static displayName = "Analog Timepicker"
|
||||
|
||||
static requiredImports = [
|
||||
...CustomTkBase.requiredImports,
|
||||
|
||||
@@ -13,6 +13,8 @@ import { CustomTkBase } from "../widgets/base"
|
||||
class MapView extends CustomTkBase{
|
||||
|
||||
static widgetType = "map_view"
|
||||
static displayName = "Map View"
|
||||
|
||||
|
||||
static requiredImports = [
|
||||
...CustomTkBase.requiredImports,
|
||||
|
||||
@@ -70,6 +70,7 @@ const ResizableTable = ({minRows=5, minCols=5}) => {
|
||||
class PandasTable extends CustomTkBase{
|
||||
|
||||
static widgetType = "pandas_table"
|
||||
static displayName = "Pandas Table"
|
||||
|
||||
static requiredImports = [
|
||||
...CustomTkBase.requiredImports,
|
||||
|
||||
@@ -12,6 +12,7 @@ import { getPythonAssetPath } from "../../utils/pythonFilePath"
|
||||
class VideoPlayer extends CustomTkBase{
|
||||
|
||||
static widgetType = "video_player"
|
||||
static displayName = "Video Player"
|
||||
|
||||
static requiredImports = [
|
||||
...CustomTkBase.requiredImports,
|
||||
|
||||
@@ -7,7 +7,7 @@ import Label from "./widgets/label"
|
||||
import Button from "./widgets/button"
|
||||
import OptionMenu from "./widgets/optionMenu"
|
||||
import Slider from "./widgets/slider"
|
||||
import { CheckBox, RadioButton } from "./widgets/ checkButton"
|
||||
import { CheckBox, RadioButton } from "./widgets/checkButton"
|
||||
import { Input, Text } from "./widgets/input"
|
||||
import SpinBox from "./widgets/spinBox"
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,7 @@ import { CustomTkWidgetBase } from "./base"
|
||||
class Button extends CustomTkWidgetBase{
|
||||
|
||||
static widgetType = "button"
|
||||
static displayName = "Button"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -69,6 +70,7 @@ class Button extends CustomTkWidgetBase{
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md
|
||||
tw-border tw-border-solid tw-border-gray-400 tw-overflow-hidden">
|
||||
<div className="tw-p-2 tw-w-full tw-flex tw-place-content-center tw-place-items-center tw-h-full tw-text-center"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
{/* {this.props.children} */}
|
||||
<div className="tw-text-sm" style={{color: this.getAttrValue("styling.foregroundColor")}}>
|
||||
|
||||
@@ -8,6 +8,8 @@ import { CustomTkWidgetBase } from "./base"
|
||||
export class CheckBox extends CustomTkWidgetBase{
|
||||
|
||||
static widgetType = "check_button"
|
||||
static displayName = "Check Box"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
@@ -211,6 +213,7 @@ export class RadioButton extends CustomTkWidgetBase{
|
||||
|
||||
return (
|
||||
<div className="tw-flex tw-p-1 tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}
|
||||
>
|
||||
<div className="tw-flex tw-flex-col tw-gap-2 tw-w-fit tw-h-fit">
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Layouts } from "../../../canvas/constants/layouts"
|
||||
import Tools from "../../../canvas/constants/tools"
|
||||
import Widget from "../../../canvas/widgets/base"
|
||||
import { CustomTkBase } from "./base"
|
||||
|
||||
@@ -5,6 +7,7 @@ import { CustomTkBase } from "./base"
|
||||
class Frame extends CustomTkBase{
|
||||
|
||||
static widgetType = "frame"
|
||||
static displayName = "Frame"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -16,7 +19,99 @@ class Frame extends CustomTkBase{
|
||||
this.state = {
|
||||
...this.state,
|
||||
fitContent: {width: true, height: true},
|
||||
widgetName: "Frame"
|
||||
widgetName: "Frame",
|
||||
attrs: {
|
||||
...this.state.attrs,
|
||||
padding: {
|
||||
label: "padding",
|
||||
padX: {
|
||||
label: "Pad X",
|
||||
tool: Tools.NUMBER_INPUT,
|
||||
toolProps: {min: 0, max: 140},
|
||||
value: null,
|
||||
onChange: (value) => {
|
||||
// this.setWidgetInnerStyle("paddingLeft", `${value}px`)
|
||||
// this.setWidgetInnerStyle("paddingRight", `${value}px`)
|
||||
|
||||
// const widgetStyle = {
|
||||
|
||||
// }
|
||||
this.setState((prevState) => ({
|
||||
|
||||
widgetInnerStyling: {
|
||||
...prevState.widgetInnerStyling,
|
||||
paddingLeft: `${value}px`,
|
||||
paddingRight: `${value}px`
|
||||
}
|
||||
}))
|
||||
|
||||
|
||||
this.setAttrValue("padding.padX", value)
|
||||
}
|
||||
},
|
||||
padY: {
|
||||
label: "Pad Y",
|
||||
tool: Tools.NUMBER_INPUT,
|
||||
toolProps: {min: 0, max: 140},
|
||||
value: null,
|
||||
onChange: (value) => {
|
||||
|
||||
this.setState((prevState) => ({
|
||||
|
||||
widgetInnerStyling: {
|
||||
...prevState.widgetInnerStyling,
|
||||
paddingTop: `${value}px`,
|
||||
paddingBottom: `${value}px`
|
||||
}
|
||||
}))
|
||||
// this.setState({
|
||||
|
||||
// widgetInnerStyling: widgetStyle
|
||||
// })
|
||||
this.setAttrValue("padding.padY", value)
|
||||
}
|
||||
},
|
||||
},
|
||||
margin: {
|
||||
label: "Margin",
|
||||
marginX: {
|
||||
label: "Margin X",
|
||||
tool: Tools.NUMBER_INPUT,
|
||||
toolProps: {min: 0, max: 140},
|
||||
value: null,
|
||||
onChange: (value) => {
|
||||
|
||||
|
||||
this.updateState((prev) => ({
|
||||
widgetOuterStyling: {
|
||||
...prev.widgetOuterStyling,
|
||||
marginLeft: `${value}px`,
|
||||
marginRight: `${value}px`
|
||||
},
|
||||
}))
|
||||
this.setAttrValue("margin.marginX", value)
|
||||
}
|
||||
},
|
||||
marginY: {
|
||||
label: "Margin Y",
|
||||
tool: Tools.NUMBER_INPUT,
|
||||
toolProps: {min: 0, max: 140},
|
||||
value: null,
|
||||
onChange: (value) => {
|
||||
|
||||
this.updateState((prev) => ({
|
||||
widgetOuterStyling: {
|
||||
...prev.widgetOuterStyling,
|
||||
marginTop: `${value}px`,
|
||||
marginBottom: `${value}px`
|
||||
},
|
||||
}))
|
||||
|
||||
this.setAttrValue("margin.marginY", value)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +121,34 @@ class Frame extends CustomTkBase{
|
||||
this.setAttrValue("styling.backgroundColor", "#EDECEC")
|
||||
}
|
||||
|
||||
getConfigCode(){
|
||||
const bg = this.getAttrValue("styling.backgroundColor")
|
||||
|
||||
const fitWidth = this.state.fitContent.width
|
||||
const fitHeight = this.state.fitContent.height
|
||||
|
||||
const {width, height} = this.getSize()
|
||||
|
||||
const {layout} = this.getParentLayout()
|
||||
|
||||
const config = {
|
||||
bg: `"${bg}"`
|
||||
}
|
||||
|
||||
if (layout !== Layouts.PLACE){
|
||||
if (!fitWidth){
|
||||
config['width'] = width
|
||||
}
|
||||
|
||||
if (!fitHeight){
|
||||
config['height'] = height
|
||||
}
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
|
||||
generateCode(variableName, parent){
|
||||
|
||||
const bg = this.getAttrValue("styling.backgroundColor")
|
||||
@@ -33,20 +156,36 @@ class Frame extends CustomTkBase{
|
||||
return [
|
||||
`${variableName} = ctk.CTkFrame(master=${parent})`,
|
||||
`${variableName}.configure(fg_color="${bg}")`,
|
||||
`${variableName}.${this.getLayoutCode()}`
|
||||
`${variableName}.${this.getLayoutCode()}`,
|
||||
...this.getGridLayoutConfigurationCode(variableName)
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
getToolbarAttrs(){
|
||||
const {layout, gridConfig, gridWeights, ...toolBarAttrs} = super.getToolbarAttrs()
|
||||
|
||||
// places layout at the end
|
||||
return ({
|
||||
id: this.__id,
|
||||
...toolBarAttrs,
|
||||
padding: this.state.attrs.padding,
|
||||
margin: this.state.attrs.margin,
|
||||
layout,
|
||||
gridConfig,
|
||||
gridWeights
|
||||
})
|
||||
}
|
||||
|
||||
renderContent(){
|
||||
// console.log("bounding rect: ", this.getBoundingRect())
|
||||
|
||||
// console.log("widget styling: ", this.state.widgetInnerStyling)
|
||||
return (
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-relative tw-rounded-md tw-overflow-hidden">
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-content-start" style={this.getInnerRenderStyling()}>
|
||||
{this.props.children}
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-content-start"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
{this.renderTkinterLayout()}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ import { CustomTkWidgetBase } from "./base"
|
||||
export class Input extends CustomTkWidgetBase{
|
||||
|
||||
static widgetType = "entry"
|
||||
static displayName = "Entry"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -65,6 +66,7 @@ export class Input extends CustomTkWidgetBase{
|
||||
return (
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-flex tw-place-items-center"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
<div className="tw-text-sm tw-text-gray-300">
|
||||
{this.getAttrValue("placeHolder")}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { CustomTkWidgetBase } from "./base"
|
||||
class Label extends CustomTkWidgetBase{
|
||||
|
||||
static widgetType = "label"
|
||||
|
||||
static displayName = "Label"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -116,6 +116,22 @@ class Label extends CustomTkWidgetBase{
|
||||
})
|
||||
}
|
||||
|
||||
getAnchorStyle = (anchor) => {
|
||||
const anchorStyles = {
|
||||
n: { justifyContent: 'center', alignItems: 'flex-start' },
|
||||
s: { justifyContent: 'center', alignItems: 'flex-end' },
|
||||
e: { justifyContent: 'flex-end', alignItems: 'center' },
|
||||
w: { justifyContent: 'flex-start', alignItems: 'center' },
|
||||
ne: { justifyContent: 'flex-end', alignItems: 'flex-start' },
|
||||
se: { justifyContent: 'flex-end', alignItems: 'flex-end' },
|
||||
nw: { justifyContent: 'flex-start', alignItems: 'flex-start' },
|
||||
sw: { justifyContent: 'flex-start', alignItems: 'flex-end' },
|
||||
center: { justifyContent: 'center', alignItems: 'center' }
|
||||
}
|
||||
|
||||
return anchorStyles[anchor] || anchorStyles["w"];
|
||||
}
|
||||
|
||||
renderContent(){
|
||||
|
||||
const image = this.getAttrValue("imageUpload")
|
||||
@@ -129,6 +145,7 @@ class Label extends CustomTkWidgetBase{
|
||||
}}
|
||||
>
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-flex tw-place-content-center tw-place-items-center "
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
{/* {this.props.children} */}
|
||||
{
|
||||
@@ -136,7 +153,10 @@ class Label extends CustomTkWidgetBase{
|
||||
<img src={image.previewUrl} className="tw-bg-contain tw-w-full tw-h-full" />
|
||||
)
|
||||
}
|
||||
<div className="" style={{color: this.getAttrValue("styling.foregroundColor")}}>
|
||||
<div className={`tw-flex ${!image ? "tw-w-full tw-h-full" : ""}`} style={{
|
||||
color: this.getAttrValue("styling.foregroundColor"),
|
||||
...this.getAnchorStyle(this.getAttrValue("styling.anchor"))
|
||||
}}>
|
||||
{this.getAttrValue("labelWidget")}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
import Widget from "../../../canvas/widgets/base"
|
||||
import Tools from "../../../canvas/constants/tools"
|
||||
import { CustomTkBase } from "./base"
|
||||
import { getPythonAssetPath } from "../../utils/pythonFilePath"
|
||||
|
||||
|
||||
class MainWindow extends CustomTkBase{
|
||||
|
||||
static widgetType = "main_window"
|
||||
static displayName = "Main Window"
|
||||
|
||||
|
||||
static initialSize = {
|
||||
width: 700,
|
||||
height: 400
|
||||
}
|
||||
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -26,6 +35,13 @@ class MainWindow extends CustomTkBase{
|
||||
toolProps: {placeholder: "Window title", maxLength: 40},
|
||||
value: "Main Window",
|
||||
onChange: (value) => this.setAttrValue("title", value)
|
||||
},
|
||||
logo: {
|
||||
label: "Window Logo",
|
||||
tool: Tools.UPLOADED_LIST,
|
||||
toolProps: {filterOptions: ["image/jpg", "image/jpeg", "image/png"]},
|
||||
value: "",
|
||||
onChange: (value) => this.setAttrValue("logo", value)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,12 +58,48 @@ class MainWindow extends CustomTkBase{
|
||||
generateCode(variableName, parent){
|
||||
|
||||
const backgroundColor = this.getAttrValue("styling.backgroundColor")
|
||||
const logo = this.getAttrValue("logo")
|
||||
|
||||
return [
|
||||
`${variableName} = ctk.CTk()`,
|
||||
`${variableName}.configure(fg_color="${backgroundColor}")`,
|
||||
`${variableName}.title("${this.getAttrValue("title")}")`
|
||||
]
|
||||
const {width, height} = this.getSize()
|
||||
|
||||
const code = [
|
||||
`${variableName} = ctk.CTk()`,
|
||||
`${variableName}.configure(fg_color="${backgroundColor}")`,
|
||||
`${variableName}.title("${this.getAttrValue("title")}")`,
|
||||
`${variableName}.geometry("${width}x${height}")`,
|
||||
...this.getGridLayoutConfigurationCode(variableName)
|
||||
]
|
||||
|
||||
if (logo?.name){
|
||||
|
||||
// code.push(`\n`)
|
||||
code.push(`${variableName}_img = Image.open(${getPythonAssetPath(logo.name, "image")})`)
|
||||
code.push(`${variableName}_img = ImageTk.PhotoImage(${variableName}_img)`)
|
||||
code.push(`${variableName}.iconphoto(False, ${variableName}_img)`)
|
||||
// code.push("\n")
|
||||
}
|
||||
|
||||
return code
|
||||
}
|
||||
|
||||
getImports(){
|
||||
const imports = super.getImports()
|
||||
|
||||
if (this.getAttrValue("logo"))
|
||||
imports.push("import os", "from PIL import Image, ImageTk", )
|
||||
|
||||
return imports
|
||||
}
|
||||
|
||||
|
||||
getRequirements(){
|
||||
const requirements = super.getRequirements()
|
||||
|
||||
|
||||
if (this.getAttrValue("logo"))
|
||||
requirements.push("pillow")
|
||||
|
||||
return requirements
|
||||
}
|
||||
|
||||
getToolbarAttrs(){
|
||||
@@ -57,8 +109,8 @@ class MainWindow extends CustomTkBase{
|
||||
id: this.__id,
|
||||
widgetName: toolBarAttrs.widgetName,
|
||||
title: this.state.attrs.title,
|
||||
logo: this.state.attrs.logo,
|
||||
size: toolBarAttrs.size,
|
||||
|
||||
...this.state.attrs,
|
||||
|
||||
})
|
||||
@@ -80,8 +132,9 @@ class MainWindow extends CustomTkBase{
|
||||
</div>
|
||||
</div>
|
||||
<div className="tw-p-2 tw-w-full tw-relative tw-h-full tw-overflow-hidden tw-content-start"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.state.widgetInnerStyling}>
|
||||
{this.props.children}
|
||||
{this.renderTkinterLayout()}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import { convertObjectToKeyValueString, removeKeyFromObject } from "../../../uti
|
||||
class OptionMenu extends CustomTkWidgetBase{
|
||||
|
||||
static widgetType = "option_menu"
|
||||
static displayName = "Option Menu"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -102,6 +103,7 @@ class OptionMenu extends CustomTkWidgetBase{
|
||||
|
||||
return (
|
||||
<div className="tw-flex tw-p-1 tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}
|
||||
onClick={this.toggleDropDownOpen}
|
||||
>
|
||||
|
||||
@@ -7,6 +7,8 @@ import { CustomTkWidgetBase } from "./base"
|
||||
class Slider extends CustomTkWidgetBase{
|
||||
|
||||
static widgetType = "scale"
|
||||
static displayName = "Scale"
|
||||
|
||||
// FIXME: You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -141,7 +143,9 @@ class Slider extends CustomTkWidgetBase{
|
||||
return (
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
|
||||
<div className="flex flex-col items-center justify-center h-screen
|
||||
bg-gray-100" style={this.getInnerRenderStyling()}>
|
||||
bg-gray-100"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
<div className="w-full max-w-md">
|
||||
<input
|
||||
type="range"
|
||||
|
||||
@@ -8,6 +8,7 @@ import { CustomTkWidgetBase } from "./base"
|
||||
class SpinBox extends CustomTkWidgetBase{
|
||||
|
||||
static widgetType = "spin_box"
|
||||
static displayName = "Spin Box"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -109,6 +110,7 @@ class SpinBox extends CustomTkWidgetBase{
|
||||
return (
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-flex tw-place-items-center tw-justify-between"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
<div className="tw-text-sm ">
|
||||
{this.getAttrValue("spinProps.default")}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import Widget from "../../../canvas/widgets/base"
|
||||
import Tools from "../../../canvas/constants/tools"
|
||||
import { getPythonAssetPath } from "../../utils/pythonFilePath"
|
||||
import { CustomTkBase } from "./base"
|
||||
|
||||
|
||||
class TopLevel extends Widget{
|
||||
class TopLevel extends CustomTkBase{
|
||||
|
||||
static widgetType = "toplevel"
|
||||
static displayName = "Top Level"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -26,6 +29,13 @@ class TopLevel extends Widget{
|
||||
toolProps: {placeholder: "Window title", maxLength: 40},
|
||||
value: "Top level",
|
||||
onChange: (value) => this.setAttrValue("title", value)
|
||||
},
|
||||
logo: {
|
||||
label: "Toplevel Logo",
|
||||
tool: Tools.UPLOADED_LIST,
|
||||
toolProps: {filterOptions: ["image/jpg", "image/jpeg", "image/png"]},
|
||||
value: "",
|
||||
onChange: (value) => this.setAttrValue("logo", value)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,11 +51,49 @@ class TopLevel extends Widget{
|
||||
|
||||
const backgroundColor = this.getAttrValue("styling.backgroundColor")
|
||||
|
||||
return [
|
||||
`${variableName} = ctk.CTkToplevel(master=${parent})`,
|
||||
`${variableName}.configure(fg_color="${backgroundColor}")`,
|
||||
`${variableName}.title("${this.getAttrValue("title")}")`
|
||||
]
|
||||
const logo = this.getAttrValue("logo")
|
||||
|
||||
const {width, height} = this.getSize()
|
||||
|
||||
const code = [
|
||||
`${variableName} = ctk.CTkToplevel(master=${parent})`,
|
||||
`${variableName}.configure(fg_color="${backgroundColor}")`,
|
||||
`${variableName}.title("${this.getAttrValue("title")}")`,
|
||||
`${variableName}.geometry("${width}x${height}")`,
|
||||
|
||||
...this.getGridLayoutConfigurationCode(variableName)
|
||||
]
|
||||
|
||||
if (logo?.name){
|
||||
|
||||
// code.push(`\n`)
|
||||
code.push(`${variableName}_img = Image.open(${getPythonAssetPath(logo.name, "image")})`)
|
||||
code.push(`${variableName}_img = ImageTk.PhotoImage(${variableName}_img)`)
|
||||
code.push(`${variableName}.iconphoto(False, ${variableName}_img)`)
|
||||
// code.push("\n")
|
||||
}
|
||||
|
||||
return code
|
||||
}
|
||||
|
||||
getImports(){
|
||||
const imports = super.getImports()
|
||||
|
||||
if (this.getAttrValue("logo"))
|
||||
imports.push("import os", "from PIL import Image, ImageTk", )
|
||||
|
||||
return imports
|
||||
}
|
||||
|
||||
|
||||
getRequirements(){
|
||||
const requirements = super.getRequirements()
|
||||
|
||||
|
||||
if (this.getAttrValue("logo"))
|
||||
requirements.push("pillow")
|
||||
|
||||
return requirements
|
||||
}
|
||||
|
||||
getToolbarAttrs(){
|
||||
@@ -54,8 +102,8 @@ class TopLevel extends Widget{
|
||||
return ({
|
||||
widgetName: toolBarAttrs.widgetName,
|
||||
title: this.state.attrs.title,
|
||||
logo: this.state.attrs.logo,
|
||||
size: toolBarAttrs.size,
|
||||
|
||||
...this.state.attrs,
|
||||
|
||||
})
|
||||
@@ -76,8 +124,10 @@ class TopLevel extends Widget{
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-content-start" style={this.state.widgetInnerStyling}>
|
||||
{this.props.children}
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-content-start"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.state.widgetInnerStyling}>
|
||||
{this.renderTkinterLayout()}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
export const Tkinter_TO_WEB_CURSOR_MAPPING = {
|
||||
|
||||
"": "",
|
||||
"arrow": "default",
|
||||
"circle": "wait",
|
||||
"clock": "wait",
|
||||
|
||||
@@ -20,5 +20,25 @@ export const ANCHOR = [
|
||||
"s",
|
||||
"e",
|
||||
"w",
|
||||
"center"
|
||||
]
|
||||
"center",
|
||||
"ne",
|
||||
"se",
|
||||
"sw",
|
||||
"nw",
|
||||
]
|
||||
|
||||
|
||||
export const GRID_STICKY = {
|
||||
N: "n",
|
||||
S: "s",
|
||||
E: "e",
|
||||
W: "w",
|
||||
WE: "we",
|
||||
NS: "ns",
|
||||
NW: "nw",
|
||||
NE: "ne",
|
||||
SW: "sw",
|
||||
SE: "se",
|
||||
NEWS: "news",
|
||||
NONE: "",
|
||||
}
|
||||
@@ -117,7 +117,7 @@ async function generateTkinterCode(projectName, widgetList=[], widgetRefs=[], as
|
||||
|
||||
// TODO: avoid adding \n inside the list instead rewrite using code.join("\n")
|
||||
const code = [
|
||||
"# This code is generated by PyUIbuilder: https://github.com/PaulleDemon/PyUIBuilder",
|
||||
"# This code is generated by PyUIbuilder: https://pyuibuilder.com",
|
||||
"\n\n",
|
||||
...imports.flatMap((item, index) => index < imports.length - 1 ? [item, "\n"] : [item]), //add \n to every line
|
||||
"\n\n",
|
||||
|
||||
@@ -20,6 +20,7 @@ const Themes = {
|
||||
class AnalogTimePicker extends TkinterBase{
|
||||
|
||||
static widgetType = "analog_timepicker"
|
||||
static displayName = "Analog Timepicker"
|
||||
|
||||
static requiredImports = [
|
||||
...TkinterBase.requiredImports,
|
||||
|
||||
@@ -13,6 +13,7 @@ import { TkinterBase } from "../widgets/base"
|
||||
class MapView extends TkinterBase{
|
||||
|
||||
static widgetType = "map_view"
|
||||
static displayName = "Map View"
|
||||
|
||||
static requiredImports = [
|
||||
...TkinterBase.requiredImports,
|
||||
|
||||
@@ -70,6 +70,7 @@ const ResizableTable = ({minRows=5, minCols=5}) => {
|
||||
class PandasTable extends TkinterBase{
|
||||
|
||||
static widgetType = "pandas_table"
|
||||
static displayName = "Pandas Table"
|
||||
|
||||
static requiredImports = [
|
||||
...TkinterBase.requiredImports,
|
||||
|
||||
@@ -12,6 +12,7 @@ import { getPythonAssetPath } from "../../utils/pythonFilePath"
|
||||
class VideoPlayer extends TkinterBase{
|
||||
|
||||
static widgetType = "video_player"
|
||||
static displayName = "Video Player"
|
||||
|
||||
static requiredImports = [
|
||||
...TkinterBase.requiredImports,
|
||||
|
||||
@@ -7,7 +7,7 @@ import Label from "./widgets/label"
|
||||
import Button from "./widgets/button"
|
||||
import OptionMenu from "./widgets/optionMenu"
|
||||
import Slider from "./widgets/slider"
|
||||
import { CheckBox, RadioButton } from "./widgets/ checkButton"
|
||||
import { CheckBox, RadioButton } from "./widgets/checkButton"
|
||||
import { Input, Text } from "./widgets/input"
|
||||
import SpinBox from "./widgets/spinBox"
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,7 @@ import { TkinterWidgetBase } from "./base"
|
||||
class Button extends TkinterWidgetBase{
|
||||
|
||||
static widgetType = "button"
|
||||
static displayName = "Button"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -68,6 +69,7 @@ class Button extends TkinterWidgetBase{
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md
|
||||
tw-border tw-border-solid tw-border-gray-400 tw-overflow-hidden">
|
||||
<div className="tw-p-2 tw-w-full tw-flex tw-place-content-center tw-place-items-center tw-h-full tw-text-center"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
{/* {this.props.children} */}
|
||||
<div className="tw-text-sm" style={{color: this.getAttrValue("styling.foregroundColor")}}>
|
||||
|
||||
@@ -8,6 +8,8 @@ import { TkinterWidgetBase } from "./base"
|
||||
export class CheckBox extends TkinterWidgetBase{
|
||||
|
||||
static widgetType = "check_button"
|
||||
static displayName = "Check Box"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
@@ -96,6 +98,7 @@ export class CheckBox extends TkinterWidgetBase{
|
||||
return (
|
||||
<div className="tw-flex tw-p-1 tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden"
|
||||
style={this.getInnerRenderStyling()}
|
||||
ref={this.styleAreaRef}
|
||||
>
|
||||
|
||||
<div className="tw-flex tw-gap-2 tw-w-full tw-h-full tw-place-items-center tw-place-content-center">
|
||||
@@ -124,25 +127,30 @@ export class RadioButton extends TkinterWidgetBase{
|
||||
// FIXME: the radio buttons are not visible because of the default heigh provided
|
||||
|
||||
static widgetType = "radio_button"
|
||||
static displayName = "Radio Button"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.minSize = {width: 50, height: 30}
|
||||
|
||||
let newAttrs = removeKeyFromObject("layout", this.state.attrs)
|
||||
|
||||
this.state = {
|
||||
...this.state,
|
||||
size: { width: 80, height: 30 },
|
||||
fitContent: { width: true, height: true },
|
||||
widgetName: "Radio button",
|
||||
attrs: {
|
||||
...this.state.attrs,
|
||||
...newAttrs,
|
||||
radios: {
|
||||
label: "Radio Group",
|
||||
tool: Tools.INPUT_RADIO_LIST,
|
||||
value: {inputs: ["default"], selectedRadio: -1},
|
||||
value: {inputs: ["default"], selectedRadio: null},
|
||||
onChange: ({inputs, selectedRadio}) => {
|
||||
this.setAttrValue("radios", {inputs, selectedRadio})
|
||||
this.setAttrValue("radios", {inputs, selectedRadio}, () => {
|
||||
console.log("attribute set: ", this.state.attrs.radios, {inputs, selectedRadio},)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { Layouts } from "../../../canvas/constants/layouts"
|
||||
import Tools from "../../../canvas/constants/tools"
|
||||
import Widget from "../../../canvas/widgets/base"
|
||||
import { convertObjectToKeyValueString } from "../../../utils/common"
|
||||
import {TkinterBase} from "./base"
|
||||
|
||||
|
||||
class Frame extends TkinterBase{
|
||||
|
||||
static widgetType = "frame"
|
||||
static displayName = "Frame"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -16,7 +20,99 @@ class Frame extends TkinterBase{
|
||||
this.state = {
|
||||
...this.state,
|
||||
fitContent: {width: true, height: true},
|
||||
widgetName: "Frame"
|
||||
widgetName: "Frame",
|
||||
attrs: {
|
||||
...this.state.attrs,
|
||||
padding: {
|
||||
label: "padding",
|
||||
padX: {
|
||||
label: "Pad X",
|
||||
tool: Tools.NUMBER_INPUT,
|
||||
toolProps: {min: 0, max: 140},
|
||||
value: null,
|
||||
onChange: (value) => {
|
||||
// this.setWidgetInnerStyle("paddingLeft", `${value}px`)
|
||||
// this.setWidgetInnerStyle("paddingRight", `${value}px`)
|
||||
|
||||
// const widgetStyle = {
|
||||
|
||||
// }
|
||||
this.setState((prevState) => ({
|
||||
|
||||
widgetInnerStyling: {
|
||||
...prevState.widgetInnerStyling,
|
||||
paddingLeft: `${value}px`,
|
||||
paddingRight: `${value}px`
|
||||
}
|
||||
}))
|
||||
|
||||
|
||||
this.setAttrValue("padding.padX", value)
|
||||
}
|
||||
},
|
||||
padY: {
|
||||
label: "Pad Y",
|
||||
tool: Tools.NUMBER_INPUT,
|
||||
toolProps: {min: 0, max: 140},
|
||||
value: null,
|
||||
onChange: (value) => {
|
||||
|
||||
this.setState((prevState) => ({
|
||||
|
||||
widgetInnerStyling: {
|
||||
...prevState.widgetInnerStyling,
|
||||
paddingTop: `${value}px`,
|
||||
paddingBottom: `${value}px`
|
||||
}
|
||||
}))
|
||||
// this.setState({
|
||||
|
||||
// widgetInnerStyling: widgetStyle
|
||||
// })
|
||||
this.setAttrValue("padding.padY", value)
|
||||
}
|
||||
},
|
||||
},
|
||||
margin: {
|
||||
label: "Margin",
|
||||
marginX: {
|
||||
label: "Margin X",
|
||||
tool: Tools.NUMBER_INPUT,
|
||||
toolProps: {min: 0, max: 140},
|
||||
value: null,
|
||||
onChange: (value) => {
|
||||
|
||||
|
||||
this.updateState((prev) => ({
|
||||
widgetOuterStyling: {
|
||||
...prev.widgetOuterStyling,
|
||||
marginLeft: `${value}px`,
|
||||
marginRight: `${value}px`
|
||||
},
|
||||
}))
|
||||
this.setAttrValue("margin.marginX", value)
|
||||
}
|
||||
},
|
||||
marginY: {
|
||||
label: "Margin Y",
|
||||
tool: Tools.NUMBER_INPUT,
|
||||
toolProps: {min: 0, max: 140},
|
||||
value: null,
|
||||
onChange: (value) => {
|
||||
|
||||
this.updateState((prev) => ({
|
||||
widgetOuterStyling: {
|
||||
...prev.widgetOuterStyling,
|
||||
marginTop: `${value}px`,
|
||||
marginBottom: `${value}px`
|
||||
},
|
||||
}))
|
||||
|
||||
this.setAttrValue("margin.marginY", value)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,18 +122,59 @@ class Frame extends TkinterBase{
|
||||
this.setAttrValue("styling.backgroundColor", "#EDECEC")
|
||||
}
|
||||
|
||||
getConfigCode(){
|
||||
const bg = this.getAttrValue("styling.backgroundColor")
|
||||
|
||||
const fitWidth = this.state.fitContent.width
|
||||
const fitHeight = this.state.fitContent.height
|
||||
|
||||
const {width, height} = this.getSize()
|
||||
|
||||
const {layout} = this.getParentLayout()
|
||||
|
||||
const config = {
|
||||
bg: `"${bg}"`
|
||||
}
|
||||
|
||||
if (layout !== Layouts.PLACE){
|
||||
if (!fitWidth){
|
||||
config['width'] = width
|
||||
}
|
||||
|
||||
if (!fitHeight){
|
||||
config['height'] = height
|
||||
}
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
generateCode(variableName, parent){
|
||||
|
||||
const bg = this.getAttrValue("styling.backgroundColor")
|
||||
const config = convertObjectToKeyValueString(this.getConfigCode())
|
||||
|
||||
return [
|
||||
`${variableName} = tk.Frame(master=${parent})`,
|
||||
`${variableName}.config(bg="${bg}")`,
|
||||
`${variableName}.${this.getLayoutCode()}`
|
||||
`${variableName}.config(${config})`,
|
||||
`${variableName}.${this.getLayoutCode()}`,
|
||||
...this.getGridLayoutConfigurationCode(variableName)
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
getToolbarAttrs(){
|
||||
const {layout, gridConfig, gridWeights, ...toolBarAttrs} = super.getToolbarAttrs()
|
||||
|
||||
// places layout at the end
|
||||
return ({
|
||||
id: this.__id,
|
||||
...toolBarAttrs,
|
||||
padding: this.state.attrs.padding,
|
||||
margin: this.state.attrs.margin,
|
||||
layout,
|
||||
gridConfig,
|
||||
gridWeights
|
||||
})
|
||||
}
|
||||
|
||||
renderContent(){
|
||||
// console.log("bounding rect: ", this.getBoundingRect())
|
||||
@@ -45,8 +182,10 @@ class Frame extends TkinterBase{
|
||||
// console.log("widget styling: ", this.state.widgetInnerStyling)
|
||||
return (
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-relative tw-rounded-md tw-overflow-hidden">
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-content-start" style={this.getInnerRenderStyling()}>
|
||||
{this.props.children}
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-content-start"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
{this.renderTkinterLayout()} {/*This is required for pack layouts, so if your widget accepts child widgets, ensure to add this */}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ import { TkinterWidgetBase } from "./base"
|
||||
export class Input extends TkinterWidgetBase{
|
||||
|
||||
static widgetType = "entry"
|
||||
static displayName = "Entry"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -65,6 +66,7 @@ export class Input extends TkinterWidgetBase{
|
||||
return (
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-flex tw-place-items-center"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
<div className="tw-text-sm tw-text-gray-300">
|
||||
{this.getAttrValue("placeHolder")}
|
||||
@@ -138,6 +140,7 @@ export class Text extends TkinterWidgetBase{
|
||||
return (
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-content-start "
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
<div className="tw-text-sm tw-text-gray-300">
|
||||
{this.getAttrValue("placeHolder")}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import Tools from "../../../canvas/constants/tools"
|
||||
import { convertObjectToKeyValueString } from "../../../utils/common"
|
||||
import { getPythonAssetPath } from "../../utils/pythonFilePath"
|
||||
import { ANCHOR } from "../constants/styling"
|
||||
import { TkinterWidgetBase } from "./base"
|
||||
|
||||
|
||||
class Label extends TkinterWidgetBase{
|
||||
|
||||
static widgetType = "label"
|
||||
static displayName = "Label"
|
||||
|
||||
|
||||
constructor(props) {
|
||||
@@ -19,6 +21,26 @@ class Label extends TkinterWidgetBase{
|
||||
size: { width: 80, height: 40 },
|
||||
attrs: {
|
||||
...this.state.attrs,
|
||||
styling: {
|
||||
...this.state.attrs.styling,
|
||||
anchor: {
|
||||
label: "Text align",
|
||||
tool: Tools.SELECT_DROPDOWN,
|
||||
options: ANCHOR.map((val) => ({value: val, label: val})),
|
||||
value: "",
|
||||
onChange: (value) => {
|
||||
|
||||
this.setAttrValue("styling.anchor", value)
|
||||
|
||||
this.setState((prevState) => ({
|
||||
widgetInnerStyle: {
|
||||
...prevState,
|
||||
...this.getAnchorStyle(value)
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
},
|
||||
labelWidget: {
|
||||
label: "Text",
|
||||
tool: Tools.INPUT,
|
||||
@@ -66,10 +88,22 @@ class Label extends TkinterWidgetBase{
|
||||
return requirements
|
||||
}
|
||||
|
||||
getConfigCode(){
|
||||
const config = super.getConfigCode()
|
||||
|
||||
const anchor = this.getAttrValue("styling.anchor")
|
||||
|
||||
if (anchor)
|
||||
config['anchor'] = `"${anchor}"`
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
generateCode(variableName, parent){
|
||||
|
||||
|
||||
const labelText = this.getAttrValue("labelWidget")
|
||||
|
||||
const config = convertObjectToKeyValueString(this.getConfigCode())
|
||||
const image = this.getAttrValue("imageUpload")
|
||||
|
||||
@@ -108,6 +142,22 @@ class Label extends TkinterWidgetBase{
|
||||
})
|
||||
}
|
||||
|
||||
getAnchorStyle = (anchor) => {
|
||||
const anchorStyles = {
|
||||
n: { justifyContent: 'center', alignItems: 'flex-start' },
|
||||
s: { justifyContent: 'center', alignItems: 'flex-end' },
|
||||
e: { justifyContent: 'flex-end', alignItems: 'center' },
|
||||
w: { justifyContent: 'flex-start', alignItems: 'center' },
|
||||
ne: { justifyContent: 'flex-end', alignItems: 'flex-start' },
|
||||
se: { justifyContent: 'flex-end', alignItems: 'flex-end' },
|
||||
nw: { justifyContent: 'flex-start', alignItems: 'flex-start' },
|
||||
sw: { justifyContent: 'flex-start', alignItems: 'flex-end' },
|
||||
center: { justifyContent: 'center', alignItems: 'center' }
|
||||
}
|
||||
|
||||
return anchorStyles[anchor] || anchorStyles["w"];
|
||||
}
|
||||
|
||||
renderContent(){
|
||||
|
||||
const image = this.getAttrValue("imageUpload")
|
||||
@@ -120,7 +170,8 @@ class Label extends TkinterWidgetBase{
|
||||
minHeight: '100%', // Force the height to 100% of the parent
|
||||
}}
|
||||
>
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-flex tw-place-content-center tw-place-items-center "
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-flex tw-place-content-center tw-place-items-center "
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
{/* {this.props.children} */}
|
||||
{
|
||||
@@ -128,7 +179,10 @@ class Label extends TkinterWidgetBase{
|
||||
<img src={image.previewUrl} className="tw-bg-contain tw-w-full tw-h-full" />
|
||||
)
|
||||
}
|
||||
<div className="" style={{color: this.getAttrValue("styling.foregroundColor")}}>
|
||||
<div className={`tw-flex ${!image ? "tw-w-full tw-h-full" : ""}`} style={{
|
||||
color: this.getAttrValue("styling.foregroundColor"),
|
||||
...this.getAnchorStyle(this.getAttrValue("styling.anchor"))
|
||||
}}>
|
||||
{this.getAttrValue("labelWidget")}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
import Widget from "../../../canvas/widgets/base"
|
||||
import Tools from "../../../canvas/constants/tools"
|
||||
import { TkinterBase } from "./base"
|
||||
import { removeKeyFromObject } from "../../../utils/common"
|
||||
import { getPythonAssetPath } from "../../utils/pythonFilePath"
|
||||
|
||||
|
||||
class MainWindow extends TkinterBase{
|
||||
|
||||
static widgetType = "main_window"
|
||||
static displayName = "Main Window"
|
||||
|
||||
static initialSize = {
|
||||
width: 700,
|
||||
height: 400
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -14,18 +22,27 @@ class MainWindow extends TkinterBase{
|
||||
exclude: ["image", "video", "media", "main_window", "toplevel"]
|
||||
}
|
||||
|
||||
const newAttrs = removeKeyFromObject("margin", this.state.attrs)
|
||||
|
||||
this.state = {
|
||||
...this.state,
|
||||
size: { width: 700, height: 400 },
|
||||
size: { width: MainWindow.initialSize.width, height: MainWindow.initialSize.height },
|
||||
widgetName: "main",
|
||||
attrs: {
|
||||
...this.state.attrs,
|
||||
...newAttrs,
|
||||
title: {
|
||||
label: "Window Title",
|
||||
tool: Tools.INPUT, // the tool to display, can be either HTML ELement or a constant string
|
||||
toolProps: {placeholder: "Window title", maxLength: 40},
|
||||
value: "Main Window",
|
||||
onChange: (value) => this.setAttrValue("title", value)
|
||||
},
|
||||
logo: {
|
||||
label: "Window Logo",
|
||||
tool: Tools.UPLOADED_LIST,
|
||||
toolProps: {filterOptions: ["image/jpg", "image/jpeg", "image/png"]},
|
||||
value: "",
|
||||
onChange: (value) => this.setAttrValue("logo", value)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,29 +50,58 @@ class MainWindow extends TkinterBase{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// componentDidMount(){
|
||||
|
||||
// // this.setAttrValue("styling.backgroundColor", "#E4E2E2")
|
||||
// super.componentDidMount()
|
||||
|
||||
// //this.setAttrValue("styling", { backgroundColor: "#E4E2E2" }) refactor to something like this?
|
||||
// this.setAttrValue("styling.backgroundColor", "#E4E2E2")
|
||||
// console.log("mounted: ", this.state)
|
||||
// }
|
||||
|
||||
componentDidMount(){
|
||||
this.setAttrValue("styling.backgroundColor", "#E4E2E2")
|
||||
super.componentDidMount()
|
||||
}
|
||||
|
||||
generateCode(variableName, parent){
|
||||
|
||||
const backgroundColor = this.getAttrValue("styling.backgroundColor")
|
||||
|
||||
return [
|
||||
`${variableName} = tk.Tk()`,
|
||||
`${variableName}.config(bg="${backgroundColor}")`,
|
||||
`${variableName}.title("${this.getAttrValue("title")}")`
|
||||
]
|
||||
const logo = this.getAttrValue("logo")
|
||||
|
||||
const {width, height} = this.getSize()
|
||||
|
||||
const code = [
|
||||
`${variableName} = tk.Tk()`,
|
||||
`${variableName}.config(bg="${backgroundColor}")`,
|
||||
`${variableName}.title("${this.getAttrValue("title")}")`,
|
||||
`${variableName}.geometry("${width}x${height}")`,
|
||||
...this.getGridLayoutConfigurationCode(variableName)
|
||||
]
|
||||
|
||||
if (logo?.name){
|
||||
|
||||
// code.push(`\n`)
|
||||
code.push(`${variableName}_img = Image.open(${getPythonAssetPath(logo.name, "image")})`)
|
||||
code.push(`${variableName}_img = ImageTk.PhotoImage(${variableName}_img)`)
|
||||
code.push(`${variableName}.iconphoto(False, ${variableName}_img)`)
|
||||
// code.push("\n")
|
||||
}
|
||||
|
||||
|
||||
return code
|
||||
}
|
||||
|
||||
getImports(){
|
||||
const imports = super.getImports()
|
||||
|
||||
if (this.getAttrValue("logo"))
|
||||
imports.push("import os", "from PIL import Image, ImageTk", )
|
||||
|
||||
return imports
|
||||
}
|
||||
|
||||
getRequirements(){
|
||||
const requirements = super.getRequirements()
|
||||
|
||||
|
||||
if (this.getAttrValue("logo"))
|
||||
requirements.push("pillow")
|
||||
|
||||
return requirements
|
||||
}
|
||||
|
||||
getToolbarAttrs(){
|
||||
@@ -65,18 +111,28 @@ class MainWindow extends TkinterBase{
|
||||
id: this.__id,
|
||||
widgetName: toolBarAttrs.widgetName,
|
||||
title: this.state.attrs.title,
|
||||
logo: this.state.attrs.logo,
|
||||
size: toolBarAttrs.size,
|
||||
|
||||
...this.state.attrs,
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
renderContent(){
|
||||
|
||||
const logo = this.getAttrValue("logo")
|
||||
|
||||
return (
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
|
||||
|
||||
<div className="tw-flex tw-w-full tw-h-[25px] tw-bg-[#c7c7c7] tw-p-1
|
||||
tw-overflow-hidden tw-shadow-xl tw-place-items-center">
|
||||
tw-overflow-hidden tw-shadow-xl tw-place-items-center tw-gap-1">
|
||||
{
|
||||
logo && (
|
||||
<img src={logo.previewUrl} alt={logo.name}
|
||||
className="tw-bg-contain tw-w-[15px] tw-h-[15px] tw-rounded-sm" />
|
||||
)
|
||||
}
|
||||
<div className="tw-text-sm">{this.getAttrValue("title")}</div>
|
||||
<div className="tw-ml-auto tw-flex tw-gap-1 tw-place-items-center">
|
||||
<div className="tw-bg-yellow-400 tw-rounded-full tw-w-[15px] tw-h-[15px]">
|
||||
@@ -88,8 +144,10 @@ class MainWindow extends TkinterBase{
|
||||
</div>
|
||||
</div>
|
||||
<div className="tw-p-2 tw-w-full tw-relative tw-h-full tw-overflow-hidden tw-content-start"
|
||||
ref={this.styleAreaRef}
|
||||
style={{...this.getInnerRenderStyling(), width: "100%", height: "calc(100% - 25px)"}}>
|
||||
{this.props.children}
|
||||
{/* {this.props.children} */}
|
||||
{this.renderTkinterLayout()} {/* This is required for pack layouts, so if your widget accepts child widgets, ensure to add this */}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import { convertObjectToKeyValueString } from "../../../utils/common"
|
||||
class OptionMenu extends TkinterWidgetBase{
|
||||
|
||||
static widgetType = "option_menu"
|
||||
static displayName = "Option Menu"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -100,6 +101,7 @@ class OptionMenu extends TkinterWidgetBase{
|
||||
return (
|
||||
<div className="tw-flex tw-p-1 tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden"
|
||||
style={this.getInnerRenderStyling()}
|
||||
ref={this.styleAreaRef}
|
||||
onClick={this.toggleDropDownOpen}
|
||||
>
|
||||
<div className="tw-flex tw-justify-between tw-gap-1">
|
||||
|
||||
@@ -7,6 +7,8 @@ import {TkinterBase, TkinterWidgetBase} from "./base"
|
||||
class Slider extends TkinterWidgetBase{
|
||||
|
||||
static widgetType = "scale"
|
||||
static displayName = "Scale"
|
||||
|
||||
// FIXME: You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -136,7 +138,9 @@ class Slider extends TkinterWidgetBase{
|
||||
return (
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
|
||||
<div className="flex flex-col items-center justify-center h-screen
|
||||
bg-gray-100" style={this.getInnerRenderStyling()}>
|
||||
bg-gray-100"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
<div className="w-full max-w-md">
|
||||
<input
|
||||
type="range"
|
||||
|
||||
@@ -8,6 +8,7 @@ import {TkinterBase, TkinterWidgetBase} from "./base"
|
||||
class SpinBox extends TkinterWidgetBase{
|
||||
|
||||
static widgetType = "spin_box"
|
||||
static displayName = "Spin Box"
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -109,6 +110,7 @@ class SpinBox extends TkinterWidgetBase{
|
||||
return (
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-flex tw-place-items-center tw-justify-between"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.getInnerRenderStyling()}>
|
||||
<div className="tw-text-sm ">
|
||||
{this.getAttrValue("spinProps.default")}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import Widget from "../../../canvas/widgets/base"
|
||||
import Tools from "../../../canvas/constants/tools"
|
||||
import { getPythonAssetPath } from "../../utils/pythonFilePath"
|
||||
import { TkinterBase } from "./base"
|
||||
|
||||
|
||||
class TopLevel extends Widget{
|
||||
class TopLevel extends TkinterBase{
|
||||
|
||||
static widgetType = "toplevel"
|
||||
static displayName = "Top Level"
|
||||
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -26,6 +30,13 @@ class TopLevel extends Widget{
|
||||
toolProps: {placeholder: "Window title", maxLength: 40},
|
||||
value: "Top level",
|
||||
onChange: (value) => this.setAttrValue("title", value)
|
||||
},
|
||||
logo: {
|
||||
label: "Toplevel Logo",
|
||||
tool: Tools.UPLOADED_LIST,
|
||||
toolProps: {filterOptions: ["image/jpg", "image/jpeg", "image/png"]},
|
||||
value: "",
|
||||
onChange: (value) => this.setAttrValue("logo", value)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,15 +48,54 @@ class TopLevel extends Widget{
|
||||
super.componentDidMount()
|
||||
}
|
||||
|
||||
|
||||
generateCode(variableName, parent){
|
||||
|
||||
const backgroundColor = this.getAttrValue("styling.backgroundColor")
|
||||
|
||||
return [
|
||||
`${variableName} = tk.Toplevel(master=${parent})`,
|
||||
`${variableName}.config(bg="${backgroundColor}")`,
|
||||
`${variableName}.title("${this.getAttrValue("title")}")`
|
||||
]
|
||||
const logo = this.getAttrValue("logo")
|
||||
|
||||
const {width, height} = this.getSize()
|
||||
|
||||
const code = [
|
||||
`${variableName} = tk.Toplevel(master=${parent})`,
|
||||
`${variableName}.config(bg="${backgroundColor}")`,
|
||||
`${variableName}.title("${this.getAttrValue("title")}")`,
|
||||
`${variableName}.geometry("${width}x${height}")`,
|
||||
|
||||
...this.getGridLayoutConfigurationCode(variableName)
|
||||
]
|
||||
|
||||
if (logo?.name){
|
||||
|
||||
// code.push(`\n`)
|
||||
code.push(`${variableName}_img = Image.open(${getPythonAssetPath(logo.name, "image")})`)
|
||||
code.push(`${variableName}_img = ImageTk.PhotoImage(${variableName}_img)`)
|
||||
code.push(`${variableName}.iconphoto(False, ${variableName}_img)`)
|
||||
// code.push("\n")
|
||||
}
|
||||
|
||||
|
||||
return code
|
||||
}
|
||||
|
||||
getImports(){
|
||||
const imports = super.getImports()
|
||||
|
||||
if (this.getAttrValue("logo"))
|
||||
imports.push("import os", "from PIL import Image, ImageTk", )
|
||||
|
||||
return imports
|
||||
}
|
||||
|
||||
getRequirements(){
|
||||
const requirements = super.getRequirements()
|
||||
|
||||
|
||||
if (this.getAttrValue("logo"))
|
||||
requirements.push("pillow")
|
||||
|
||||
return requirements
|
||||
}
|
||||
|
||||
getToolbarAttrs(){
|
||||
@@ -54,18 +104,26 @@ class TopLevel extends Widget{
|
||||
return ({
|
||||
widgetName: toolBarAttrs.widgetName,
|
||||
title: this.state.attrs.title,
|
||||
logo: this.state.attrs.logo,
|
||||
size: toolBarAttrs.size,
|
||||
|
||||
...this.state.attrs,
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
renderContent(){
|
||||
const logo = this.getAttrValue("logo")
|
||||
|
||||
return (
|
||||
<div className="tw-w-flex tw-flex-col tw-w-full tw-h-full tw-rounded-md tw-overflow-hidden">
|
||||
<div className="tw-flex tw-w-full tw-h-[25px] tw-bg-[#c7c7c7] tw-p-1
|
||||
<div className="tw-flex tw-w-full tw-h-[25px] tw-bg-[#c7c7c7] tw-p-1 tw-gap-1
|
||||
tw-overflow-hidden tw-shadow-xl tw-place-items-center">
|
||||
{
|
||||
logo && (
|
||||
<img src={logo.previewUrl} alt={logo.name}
|
||||
className="tw-bg-contain tw-w-[15px] tw-h-[15px] tw-rounded-sm" />
|
||||
)
|
||||
}
|
||||
<div className="tw-text-sm">{this.getAttrValue("title")}</div>
|
||||
<div className="tw-ml-auto tw-flex tw-gap-1 tw-place-items-center">
|
||||
<div className="tw-bg-yellow-400 tw-rounded-full tw-w-[15px] tw-h-[15px]">
|
||||
@@ -76,8 +134,10 @@ class TopLevel extends Widget{
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-content-start" style={this.state.widgetInnerStyling}>
|
||||
{this.props.children}
|
||||
<div className="tw-p-2 tw-w-full tw-h-full tw-content-start"
|
||||
ref={this.styleAreaRef}
|
||||
style={this.state.widgetInnerStyling}>
|
||||
{this.renderTkinterLayout()}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import { useEffect, useRef, useMemo, useState } from "react";
|
||||
|
||||
import { BookOutlined, CloseCircleFilled, CrownFilled, GithubFilled, ShareAltOutlined } from "@ant-design/icons";
|
||||
import { BookOutlined, CloseCircleFilled, CrownFilled, DiscordFilled, GithubFilled, ShareAltOutlined } from "@ant-design/icons";
|
||||
|
||||
import KO_FI from "../assets/logo/ko-fi.png"
|
||||
import Premium from "./utils/premium";
|
||||
@@ -62,7 +62,7 @@ function Sidebar({tabs}){
|
||||
>
|
||||
|
||||
|
||||
<div className="tw-min-w-[80px] tw-w-[80px] tw-h-full tw-flex tw-flex-col tw-gap-4 tw-p-3 tw-place-items-center">
|
||||
<div className="tw-min-w-[80px] tw-w-[80px] tw-bg-gray-100 tw-h-full tw-flex tw-flex-col tw-gap-4 tw-p-3 tw-place-items-center">
|
||||
{
|
||||
sidebarTabs.map((tab, index) => {
|
||||
return (
|
||||
@@ -88,6 +88,11 @@ function Sidebar({tabs}){
|
||||
}
|
||||
|
||||
<div className="tw-flex tw-flex-col tw-place-content-items tw-place-items-center tw-gap-3 tw-mt-auto">
|
||||
<a href="https://discord.gg/dHXjrrCA7G" target="_blank"
|
||||
title="discord invite"
|
||||
rel="noopener noreferrer" className="tw-text-3xl tw-cursor-pointer tw-text-[#5562EA]">
|
||||
<DiscordFilled />
|
||||
</a>
|
||||
<Premium className="tw-text-2xl tw-bg-purple-700 tw-text-center
|
||||
tw-w-[35px] tw-h-[35px] tw-rounded-md
|
||||
tw-cursor-pointer tw-text-white
|
||||
@@ -99,7 +104,7 @@ function Sidebar({tabs}){
|
||||
<ShareAltOutlined />
|
||||
</Share>
|
||||
<a className="tw-cursor-pointer tw-text-xl tw-text-gray-700"
|
||||
href="https://pyuibuilder-docs.pages.dev/"
|
||||
href="https://docs.pyuibuilder.com/"
|
||||
target="_blank" rel="noopener noreferrer">
|
||||
<i className="bi bi-book-half"></i>
|
||||
</a>
|
||||
@@ -107,13 +112,15 @@ function Sidebar({tabs}){
|
||||
rel="noopener noreferrer" className="tw-text-2xl tw-cursor-pointer tw-text-black">
|
||||
<GithubFilled />
|
||||
</a>
|
||||
<a href="https://ko-fi.com/artpaul" className="tw-cursor-pointer ">
|
||||
{/* <a href="https://ko-fi.com/artpaul" className="tw-cursor-pointer ">
|
||||
<img src={KO_FI} alt="ko-fi" className="tw-w-[30px] tw-h-[30px]"/>
|
||||
</a>
|
||||
</a> */}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="tw-w-full tw-h-full tw-bg-inherit tw-flex tw-flex-col tw-overflow-x-hidden" ref={sideBarExtraRef}>
|
||||
<div className="tw-w-full tw-h-full tw-bg-inherit tw-rounded-lg
|
||||
tw-shadow-[rgb(207,207,207)] tw-shadow-[rgb(207,207,207,0.5)_-3px_0px_10px_] tw-flex tw-flex-col tw-overflow-x-hidden"
|
||||
ref={sideBarExtraRef}>
|
||||
<div className="tw-w-full tw-h-[50px] tw-flex tw-place-content-end tw-p-1">
|
||||
<button className="tw-outline-none tw-bg-transparent tw-border-none tw-text-gray-600 tw-cursor-pointer tw-text-xl"
|
||||
onClick={closeSidebar}
|
||||
|
||||
@@ -50,10 +50,13 @@ function TemplatesContainer(){
|
||||
|
||||
<div className="tw-flex tw-flex-col tw-mt-6 tw-gap-2">
|
||||
<div>Want to be notified of the release?</div>
|
||||
<a href="https://paulfreeman.substack.com/subscribe?utm_source=pyGUIBuilder_web"
|
||||
<button data-tally-open="mVDY7N" data-tally-layout="modal" data-tally-emoji-text="👋"
|
||||
data-tally-emoji-animation="wave" className="tw-p-2 tw-w-full tw-outline-none tw-bg-blue-500 tw-rounded-md tw-no-underline
|
||||
tw-text-white tw-text-center tw-py-3 tw-border-none tw-text-base tw-shadow-md tw-cursor-pointer">Join the waitlist</button>
|
||||
{/* <a href="https://paulfreeman.substack.com/subscribe?utm_source=pyGUIBuilder_web"
|
||||
className="tw-p-2 tw-w-full tw-bg-blue-500 tw-rounded-md tw-no-underline
|
||||
tw-text-white tw-text-center tw-py-3"
|
||||
target="_blank" rel="noreferrer noopener">Subscribe to newsletter</a>
|
||||
target="_blank" rel="noreferrer noopener">Join the waitlist</a> */}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -13,7 +13,7 @@ import { useWidgetContext } from "../canvas/context/widgetContext"
|
||||
function transformWidgets(widgets, widgetRefs, isTopLevel=true) {
|
||||
// console.log("Wdiegts refs: ", widgetRefs)
|
||||
return widgets.map(widget => ({
|
||||
title: widget.widgetType.name, // Assuming widgetType is a class
|
||||
title: widgetRefs.current[widget.id].current.getDisplayName(), // Assuming widgetType is a class
|
||||
key: widget.id,
|
||||
isTopLevel: isTopLevel,
|
||||
widgetRef: widgetRefs.current[widget.id],
|
||||
|
||||
@@ -38,11 +38,7 @@ function Premium({ children, className = "" }) {
|
||||
If you find this tool useful and want to fund and support it's development, consider buying a <b>one time license</b>.
|
||||
<br />
|
||||
<br />
|
||||
I am working on PYUI builder full time to help you easily build GUI's in python. However as a solo-dev, its super hard
|
||||
to keep working on it without enough funding.
|
||||
<br />
|
||||
<br />
|
||||
By buying pre-order license, I get to complete this faster and you get discounted price, advance features, priority support, early access, upcoming features, and
|
||||
By pre-ordering license, you get discounted price, advance features, priority support, early access, upcoming features, and
|
||||
<a
|
||||
href="https://github.com/PaulleDemon/PyUIBuilder/blob/main/roadmap.md"
|
||||
target="_blank"
|
||||
@@ -51,10 +47,7 @@ function Premium({ children, className = "" }) {
|
||||
>
|
||||
more.
|
||||
</a>
|
||||
<div className="tw-text-sm tw-mt-2">
|
||||
Or you could support development by sharing this tool on your socials and you'll be eligible for a
|
||||
<a href="https://tally.so/r/mJM22X" target="_blank" rel="noreferrer noopener">free license</a>.
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<section className="tw-mt-1 tw-flex tw-w-full tw-flex-col tw-place-items-center tw-p-[2%] max-lg:tw-p-2" id="pricing">
|
||||
@@ -78,6 +71,16 @@ function Premium({ children, className = "" }) {
|
||||
<i className="bi bi-check-circle-fill tw-text-green-600 tw-text-base"></i>
|
||||
<span>Commercial use</span>
|
||||
</li>
|
||||
<li className="tw-flex tw-place-items-center tw-gap-2">
|
||||
<i className="bi bi-x-circle-fill tw-text-red-600 tw-text-base"></i>
|
||||
<span>Premium widgets
|
||||
<span className="tw-text-sm">(eg: tab widget, file upload, multi-page support, 3rd party widget library support etc)</span>
|
||||
</span>
|
||||
</li>
|
||||
<li className="tw-flex tw-place-items-center tw-gap-2">
|
||||
<i className="bi bi-x-circle-fill tw-text-red-600 tw-text-base"></i>
|
||||
<span>Premium Templates</span>
|
||||
</li>
|
||||
<li className="tw-flex tw-place-items-center tw-gap-2">
|
||||
<i className="bi bi-x-circle-fill tw-text-red-600 tw-text-base"></i>
|
||||
<span>Downloadable UI builder exe for local development</span>
|
||||
@@ -138,7 +141,7 @@ function Premium({ children, className = "" }) {
|
||||
Support open-source development 🚀. Plus, get added benefits.
|
||||
</p>
|
||||
<hr />
|
||||
<ul className="tw-mt-4 tw-flex tw-flex-col tw-gap-3 tw-text-xl tw-text-gray-600">
|
||||
<ul className="tw-mt-4 tw-flex tw-flex-col tw-gap-3 tw-text-xl tw-text-black">
|
||||
<li className="tw-flex tw-place-items-center tw-gap-2">
|
||||
<i className="bi bi-check-circle-fill tw-text-green-600 tw-text-base"></i>
|
||||
<span>Access to web-based editor</span>
|
||||
@@ -147,6 +150,16 @@ function Premium({ children, className = "" }) {
|
||||
<i className="bi bi-check-circle-fill tw-text-green-600 tw-text-base"></i>
|
||||
<span>Downloadable UI builder exe for local development</span>
|
||||
</li>
|
||||
<li className="tw-flex tw-place-items-center tw-gap-2">
|
||||
<i className="bi bi-check-circle-fill tw-text-green-600 tw-text-base"></i>
|
||||
<span>Premium widgets
|
||||
<span className="tw-text-sm">(eg: tab widget, file upload, multi-page support, 3rd party widget library support etc)</span>
|
||||
</span>
|
||||
</li>
|
||||
<li className="tw-flex tw-place-items-center tw-gap-2">
|
||||
<i className="bi bi-check-circle-fill tw-text-green-600 tw-text-base"></i>
|
||||
<span>Premium Templates</span>
|
||||
</li>
|
||||
<li className="tw-flex tw-place-items-center tw-gap-2">
|
||||
<i className="bi bi-check-circle-fill tw-text-green-600 tw-text-base"></i>
|
||||
<span>Preview live</span>
|
||||
@@ -217,7 +230,7 @@ function Premium({ children, className = "" }) {
|
||||
Support open-source development 🚀. Plus, get added benefits.
|
||||
</p>
|
||||
<hr />
|
||||
<ul className="tw-mt-4 tw-flex tw-flex-col tw-gap-3 tw-text-xl tw-text-gray-600">
|
||||
<ul className="tw-mt-4 tw-flex tw-flex-col tw-gap-3 tw-text-xl">
|
||||
<li className="tw-flex tw-place-items-center tw-gap-2">
|
||||
<i className="bi bi-check-circle-fill tw-text-green-600 tw-text-base"></i>
|
||||
<span>Access to web-based editor</span>
|
||||
@@ -226,6 +239,16 @@ function Premium({ children, className = "" }) {
|
||||
<i className="bi bi-check-circle-fill tw-text-green-600 tw-text-base"></i>
|
||||
<span>Downloadable UI builder exe for local development</span>
|
||||
</li>
|
||||
<li className="tw-flex tw-place-items-center tw-gap-2">
|
||||
<i className="bi bi-check-circle-fill tw-text-green-600 tw-text-base"></i>
|
||||
<span>Premium widgets
|
||||
<span className="tw-text-sm">(eg: tab widget, file upload, multi-page support, 3rd party widget library support etc)</span>
|
||||
</span>
|
||||
</li>
|
||||
<li className="tw-flex tw-place-items-center tw-gap-2">
|
||||
<i className="bi bi-check-circle-fill tw-text-green-600 tw-text-base"></i>
|
||||
<span>Premium Templates</span>
|
||||
</li>
|
||||
<li className="tw-flex tw-place-items-center tw-gap-2">
|
||||
<i className="bi bi-check-circle-fill tw-text-green-600 tw-text-base"></i>
|
||||
<span>Preview live</span>
|
||||
@@ -276,6 +299,11 @@ function Premium({ children, className = "" }) {
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="tw-text-sm tw-mt-4">
|
||||
Or you could support development by sharing this tool on your socials and you'll be eligible for a
|
||||
<a href="https://tally.so/r/mJM22X" target="_blank" rel="noreferrer noopener">free license</a>.
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ body {
|
||||
|
||||
/* width */
|
||||
::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
/* Track */
|
||||
|
||||
@@ -69,4 +69,29 @@ export function convertObjectToKeyValueString(obj){
|
||||
return Object.entries(obj)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join(', ')
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {HTMLElement} widget
|
||||
* @param {HTMLElement} gridContainer
|
||||
* @returns
|
||||
*/
|
||||
export const getGridPosition = (widget, gridContainer) => {
|
||||
if (!widget || !gridContainer) return null;
|
||||
|
||||
const widgets = Array.from(gridContainer.children); // Get all grid items
|
||||
// const index = widgets.indexOf(widget);
|
||||
const widgetIndex = widgets.indexOf(widget);
|
||||
|
||||
if (widgetIndex === -1) return null; // Widget not found
|
||||
|
||||
const gridStyles = getComputedStyle(gridContainer);
|
||||
const columnCount = gridStyles.gridTemplateColumns.split(' ').length;
|
||||
|
||||
const row = Math.floor(widgetIndex / columnCount) + 1;
|
||||
const column = (widgetIndex % columnCount) + 1;
|
||||
|
||||
return { row, column };
|
||||
}
|
||||
36
src/utils/hooks.js
Normal file
36
src/utils/hooks.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import { useLayoutEffect, useCallback, useState } from 'react';
|
||||
|
||||
export const useRect = (ref) => {
|
||||
|
||||
const [rect, setRect] = useState({ width: 0, height: 0, top: 0, left: 0, right: 0, bottom: 0 });
|
||||
|
||||
const updateRect = useCallback(() => {
|
||||
if (ref.current) {
|
||||
setRect(ref.current.getBoundingClientRect());
|
||||
}
|
||||
}, [ref]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!ref.current) return;
|
||||
|
||||
const timeout = setTimeout(updateRect, 0); // Delay to next event loop
|
||||
|
||||
const observer = new ResizeObserver(updateRect);
|
||||
observer.observe(ref.current);
|
||||
|
||||
return () => {
|
||||
observer.disconnect()
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
}, [updateRect, ref]);
|
||||
|
||||
return rect;
|
||||
};
|
||||
|
||||
/**
|
||||
* Higher order component to make use of the useRect
|
||||
*/
|
||||
export function WithRect({ forwardedRef, children }) {
|
||||
const rect = useRect(forwardedRef)
|
||||
return children(rect)
|
||||
}
|
||||
5
src/utils/random.js
Normal file
5
src/utils/random.js
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
|
||||
export function randomArrayChoice(arr){
|
||||
return arr[Math.floor(Math.random() * arr.length)];
|
||||
}
|
||||
9
src/utils/system.js
Normal file
9
src/utils/system.js
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
export async function isChromium() {
|
||||
if (navigator.userAgentData) {
|
||||
const brands = await navigator.userAgentData.getHighEntropyValues(["brands"])
|
||||
return brands.brands.some(brand => /Chromium|Google Chrome|Microsoft Edge|Opera|Brave/i.test(brand.brand))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user