Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to typescript #229

Merged
merged 42 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ce0ae57
Upgraded rollup and added TS support
Apr 17, 2022
9c3a515
Conversion in-progress
May 2, 2022
a2ffce0
Converted toasts reducer to TS
May 8, 2022
690f94b
Adds Toaster.tsx & css module support
May 9, 2022
1b0d2de
Converted context and textInput
May 9, 2022
a08d10d
Converted cache, commentsReducer, constants, stageReducer
May 9, 2022
8537fc8
Updated connectionCalculator
May 9, 2022
2158956
Converted Draggable component
May 9, 2022
6ff57d3
Converted Checkbox
May 9, 2022
0ca6f72
Converted connections container
May 9, 2022
a81ab62
Converted Connection
May 9, 2022
b50c561
Converted ContextMenu
May 9, 2022
09570e7
Converted Select
May 9, 2022
455a5ba
Converted NodesReducer & Control
May 10, 2022
e68d38e
Converted Comment
May 10, 2022
06364f2
Converted Stage
May 10, 2022
6896849
Converted Color Picker
May 11, 2022
2e44b57
Converted IoPorts
May 13, 2022
6b10301
Tightened up typebuilder types
May 13, 2022
1fa8c6e
Converted Node
May 13, 2022
fa44fb7
Converted NodeEditor
May 13, 2022
340a36c
Stage cleanup
May 13, 2022
68a0928
Converted root engine
May 13, 2022
7785667
Added basic documentation on types
May 13, 2022
032eb1e
port type builder config is now optional
May 13, 2022
be6897c
v1.0.0-0
May 16, 2022
cdba857
Merge branch 'master' into feature/convert-to-typescript
chrisjpatty Mar 18, 2023
3f2b7a6
Fixed types for control builders
chrisjpatty Mar 18, 2023
609b6a8
Moved useRootEngine to its own file
chrisjpatty Mar 18, 2023
3bde09d
v1.0.1-0
chrisjpatty Mar 18, 2023
fdb74f3
Exported colors object now autocompletes correctly
chrisjpatty Mar 18, 2023
89bd4c5
Context is now an optional prop of useRootEngine
chrisjpatty Mar 18, 2023
6ad4ac6
v1.0.2-0
chrisjpatty Mar 18, 2023
16bc96d
Fixed type for custom render functions
chrisjpatty Mar 19, 2023
6738062
v1.0.2-1
chrisjpatty Mar 19, 2023
d03265e
Merge branch 'master' into feature/convert-to-typescript
chrisjpatty Mar 19, 2023
e7383c6
v1.0.2-2
chrisjpatty Mar 19, 2023
0607251
Lightened default theme and updated docs
chrisjpatty Aug 26, 2023
0a311b5
Fixed bug preventing color picker
chrisjpatty Aug 26, 2023
0d9d159
Published 1.0.2-3
chrisjpatty Aug 26, 2023
e7b7919
v1.0.2-4
chrisjpatty Aug 26, 2023
8ce93f7
Merge branch 'master' into feature/convert-to-typescript
chrisjpatty Aug 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"presets": [
["env", {
"modules": false
}],
"stage-0",
"react"
]
}
[
"@babel/preset-env",
{
"modules": false
}
],
"@babel/preset-typescript",
"@babel/preset-react"
],
"plugins": ["@babel/plugin-transform-runtime"]
}
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"globals": {
"cy": true,
"Cypress": true
},
"plugins": ["eslint-plugin-tsdoc"],
"rules": {
"tsdoc/syntax": "warn"
}
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnSave": true
}
11 changes: 11 additions & 0 deletions docs/docs/saving-nodes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import config from './config'

const App = () => {
const [nodes, setNodes] = React.useState({})

React.useCallback((nodes) => {
// Do whatever you want with the nodes
setNodes(nodes)
}, [])

return (
<div style={{width: 800, height: 600}}>
<NodeEditor
Expand All @@ -30,6 +36,11 @@ const App = () => {

The `onChange` handler will be called any time any of the nodes change? This includes any time their position or control values change.

:::warning
It's critical to note that the `onChange` handler **MUST** be memoized. If you don't memoize the handler you will get an infinite loop.
:::


## `getNodes`

Because the `onChange` handler may be called quite often, there are times you may want to only get out the nodes when the user is done editing. For these times the node editor provides an imperative handler for extracting the nodes.
Expand Down
18 changes: 15 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
"dependencies": {
"@emotion/core": "^10.0.28",
"@emotion/styled": "^10.0.27",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.3",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"axios": "^0.19.2",
"decode-query-string": "^0.1.2",
"docz": "^2.3.1",
Expand All @@ -17,8 +21,9 @@
"react": "link:../node_modules/react",
"react-dom": "link:../node_modules/react-dom",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react-scripts": "5.0.1"
"react-router-dom": "5.3.3",
"react-scripts": "^5.0.1",
"typescript": "^5.0.2"
},
"scripts": {
"start": "react-scripts start",
Expand All @@ -29,6 +34,12 @@
"docz:build": "DOCZ_SOURCE=./src docz build",
"docz:serve": "DOCZ_SOURCE=./src docz build && docz serve"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
Expand All @@ -40,5 +51,6 @@
"last 1 firefox version",
"last 1 safari version"
]
}
},
"devDependencies": {}
}
38 changes: 26 additions & 12 deletions example/src/App.js → example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
Controls,
Colors,
RootEngine,
useRootEngine
useRootEngine,
NodeMap
} from "node-editor";

const colors = [
Expand Down Expand Up @@ -212,7 +213,7 @@ flumeConfig
type: "multiColor",
name: "multiColor",
label: "Multicolor",
multiColor: Colors.grey,
// multiColor: Colors.grey,
controls: [
Controls.multiselect({
name: "multiColor",
Expand Down Expand Up @@ -635,7 +636,7 @@ const App = () => {
border: "none",
padding: 0,
fontSize: 14,
color: '#222'
color: "#222"
}}
onClick={actions.openMenu}
>
Expand All @@ -645,7 +646,7 @@ const App = () => {
</Wrapper>
);
}}
// debug
debug
/>
<div style={{ marginTop: 30 }}>
<Website nodes={nodes} />
Expand All @@ -656,25 +657,38 @@ const App = () => {

export default App;

const useInfiniteEngine = (nodes, engine, context, options = {}) =>
Object.keys(nodes).length ? engine.resolveRootNode(nodes, { context, ...options }) : {};
const useInfiniteEngine = <T extends { [inputName: string]: any }>(
nodes: NodeMap,
engine: RootEngine,
context: any,
options = {}
): T =>
Object.keys(nodes).length
? engine.resolveRootNode<T>(nodes, { context, ...options })
: ({} as T);

const Website = ({ nodes }) => {
const Website = ({ nodes }: { nodes: NodeMap }) => {
const {
title,
description,
showDashboard,
showContactForm,
showLoginButton
} = useInfiniteEngine(nodes, engine, { someContext: true }, { maxLoops: 10 });
showBody,
showLogin
} = useInfiniteEngine<{
title: string;
description: string;
showDashboard: boolean;
showBody: boolean;
showLogin: boolean;
}>(nodes, engine, { someContext: true }, { maxLoops: 10 });

return (
<div className="website-wrapper">
<h1>{title}</h1>
<p>{description}</p>
{showDashboard && <div>Dashboard</div>}
{showContactForm && <div>Contact Form</div>}
{showLoginButton && <button>Login</button>}
{showBody && <div>Contact Form</div>}
{showLogin && <button>Login</button>}
</div>
);
};
79 changes: 0 additions & 79 deletions example/src/TestRoutes/TestEditor.js

This file was deleted.

74 changes: 74 additions & 0 deletions example/src/TestRoutes/TestEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from "react";
import "normalize.css";

import { Controls, FlumeConfig, NodeEditor } from "node-editor";

const Log = console.log;

const config = new FlumeConfig()
.addPortType({
type: "number",
name: "number",
label: "Number",
controls: [
Controls.number({
name: "number"
})
]
})
.addNodeType({
type: "number",
label: "Number",
initialWidth: 150,
inputs: ports => [ports.number()],
outputs: ports => [ports.number()]
})
.addNodeType({
type: "addNumbers",
label: "Add Numbers",
initialWidth: 150,
inputs: ports => [
ports.number({
name: "num1"
}),
ports.number({
name: "num2"
})
],
outputs: ports => [
ports.number({
name: "result"
})
]
});

const TestEditor = () => {
const [output, setOutput] = React.useState<string | undefined>();

React.useEffect(() => {
console.log = log => {
Log(log);
if (typeof log === "object") {
setOutput(JSON.stringify(log));
}
};
return () => {
console.log = Log;
};
});
return (
<div className="wrapper" style={{ width: 800, height: 600 }}>
<NodeEditor
portTypes={config.portTypes}
nodeTypes={config.nodeTypes}
nodes={{}}
debug
/>
<div id="OUTPUT" style={{ display: "none" }}>
{output}
</div>
</div>
);
};

export default TestEditor;
File renamed without changes.
22 changes: 0 additions & 22 deletions example/src/components/Checkbox.js

This file was deleted.

Loading
Loading