@rkmodules/rules 0.0.159 → 0.0.161

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,7 @@ interface FlowProps {
21
21
  fitView?: boolean;
22
22
  onChange?: (updater: Updater<GraphedFunction>) => void;
23
23
  onClick?: (event: React.MouseEvent, position: XYPosition) => void;
24
+ onContextMenu?: (event: React.MouseEvent, position: XYPosition) => void;
24
25
  onSelect?: (ids: string[]) => void;
25
26
  customControls?: Record<string, React.ComponentType<WidgetProps<any>>>;
26
27
  customNodes?: Record<string, React.ComponentType<NodeProps<FunctionNode>>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rkmodules/rules",
3
- "version": "0.0.159",
3
+ "version": "0.0.161",
4
4
  "main": "dist/index.cjs.js",
5
5
  "module": "dist/index.esm.mjs",
6
6
  "types": "./dist/index.d.ts",
package/readme.md CHANGED
@@ -8,6 +8,47 @@ An engine creates a namespace for functions, so create an engine to start with:
8
8
 
9
9
  `const engine = new Engine()`
10
10
 
11
+ ## editor
12
+
13
+ - Create an instance of the rules engine
14
+ - import the css
15
+ - create a function to work with
16
+ - use the `<Flow>` component to create the editor
17
+ - use the `<DDContext>` component around the flow
18
+
19
+ ```tsx
20
+ import "@rkmodules/rules/index.css";
21
+ import {
22
+ DDContext,
23
+ Engine,
24
+ Flow,
25
+ GraphedFunction,
26
+ } from "@rkmodules/rules";
27
+
28
+ const engine = new Engine({
29
+ // map of custom rules
30
+ });
31
+
32
+ const emptyFunction: GraphedFunction = {
33
+ name: "test",
34
+ body: {},
35
+ outputs: {
36
+ documents: "",
37
+ },
38
+ };
39
+
40
+ export default function MyComponent() {
41
+ const [fn, setFn] = React.useState(emptyFunction);
42
+ return (
43
+ <div>
44
+ <DDContext>
45
+ <Flow function={fn} engine={engine} onChange={setFn} />
46
+ </DDContext>
47
+ <div>
48
+ );
49
+ }
50
+ ```
51
+
11
52
  ## Specifying a function
12
53
 
13
54
  A function definition is just a json object. It can be assembled together via code or just hardcoded. It is of type `GraphedFunction` and at least has to have a `name` and `body` field. The latter defines a graph with calls to primitives or other graphed functions:
@@ -53,35 +94,54 @@ We get back to function definitions later
53
94
 
54
95
  `useFunction`
55
96
 
56
- ## editor
97
+ # custom styling
57
98
 
58
- - Create an instance of the rules engine
59
- - create a function to work with
60
- - use the `<Flow>` component to create the editor
99
+ import the css for basic styling:
61
100
 
62
- ```tsx
63
- const engine = new Engine({
64
- // map of custom rules
65
- });
101
+ ```ts
102
+ import "@rkmodules/rules/index.css";
103
+ ```
66
104
 
67
- const emptyFunction: GraphedFunction = {
68
- name: "test",
69
- body: {},
70
- outputs: {
71
- documents: "",
72
- },
73
- };
105
+ The following css variables are defined on root, overwrite if needed
106
+
107
+ ```css
108
+ :root {
109
+ --node-line: #ccc;
110
+ --node-select-line: #007bff;
111
+ --node-active-line: crimson;
112
+ --node-background: #f9f9f9;
113
+ --node-connection: #007bff;
114
+ --node-shadow: none;
115
+ --node-radius: 4px;
116
+ }
117
+ ```
74
118
 
75
- export default function MyComponent() {
76
- const [fn, setFn] = React.useState(emptyFunction);
77
- return (
78
- <div>
79
- <Flow function={fn} engine={engine} onChange={setFn} />
80
- <div>
81
- );
119
+ # custom controls
120
+
121
+ node inputs and params have a particular type. There are standard controls for `string`, `number` and `boolean`. Additional controls can be created using a component with the following props signature:
122
+
123
+ ```ts
124
+ export interface WidgetProps<T> {
125
+ value: T;
126
+ vardef: NormalizedVarDef;
127
+ data: FunctionNode["data"];
128
+ onChange?: (value: T) => void;
82
129
  }
83
130
  ```
84
131
 
132
+ custom contols can be passed into the `<Flow>` component with the `customControls` prop. It should be a map from type to component:
133
+
134
+ ```tsx
135
+ <Flow
136
+ engine={engine}
137
+ function={fn}
138
+ onChange={setFn}
139
+ customControls={{
140
+ color: ColorControl,
141
+ }}
142
+ />
143
+ ```
144
+
85
145
  TODO:
86
146
 
87
147
  - [ ] filtering of lists