@rkmodules/rules 0.0.160 → 0.0.162
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.
- package/dist/index.cjs.css +3 -2
- package/dist/index.cjs.js +64 -28
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.css +3 -2
- package/dist/index.esm.mjs +64 -28
- package/dist/index.esm.mjs.map +1 -1
- package/dist/lib/Engine/types.d.ts +4 -1
- package/dist/lib/Flow/index.d.ts +1 -0
- package/dist/lib/Flow/types.d.ts +1 -0
- package/package.json +2 -1
- package/readme.md +186 -36
|
@@ -30,7 +30,10 @@ export type RecOfTrees = Record<string, Tree<any>>;
|
|
|
30
30
|
export type PrimitiveFunction = {
|
|
31
31
|
name: string;
|
|
32
32
|
label?: string;
|
|
33
|
-
nodeType?: string
|
|
33
|
+
nodeType?: string | {
|
|
34
|
+
name: string;
|
|
35
|
+
props: Record<string, any>;
|
|
36
|
+
};
|
|
34
37
|
description?: string;
|
|
35
38
|
params?: Record<string, VarDef>;
|
|
36
39
|
inputs?: Record<string, VarDef>;
|
package/dist/lib/Flow/index.d.ts
CHANGED
|
@@ -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/dist/lib/Flow/types.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export type FunctionNode = Node<{
|
|
|
11
11
|
outputDefs: Record<string, VarDef>;
|
|
12
12
|
onChange: (newData: Partial<FunctionNode["data"]>) => void;
|
|
13
13
|
onIOChange?: (callback: (fn: GraphedFunction) => Partial<GraphedFunction>) => void;
|
|
14
|
+
nodeProps?: Record<string, any>;
|
|
14
15
|
}>;
|
|
15
16
|
export type NodeDropItem = {
|
|
16
17
|
name: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rkmodules/rules",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.162",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"module": "dist/index.esm.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"react-dom": ">=17.0.1"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
+
"@rkmodules/stringtemplate": "^0.1.3",
|
|
44
45
|
"@rkmodules/use-inner": "^1.0.3",
|
|
45
46
|
"@xyflow/react": "^12.8.3",
|
|
46
47
|
"classnames": "^2.5.1",
|
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,158 @@ We get back to function definitions later
|
|
|
53
94
|
|
|
54
95
|
`useFunction`
|
|
55
96
|
|
|
56
|
-
|
|
97
|
+
# custom styling
|
|
57
98
|
|
|
58
|
-
|
|
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
|
-
```
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
101
|
+
```ts
|
|
102
|
+
import "@rkmodules/rules/index.css";
|
|
103
|
+
```
|
|
66
104
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
+
|
|
145
|
+
# custom nodes
|
|
146
|
+
|
|
147
|
+
alternatively, the entire node can be customized. There are the following standard nodes `Default`, `Calc`, and
|
|
148
|
+
|
|
149
|
+
- `Default`: the default node
|
|
150
|
+
- `Calc`: specialized node for the Calc function that renders the expression and creates input ports based on variables in the expression
|
|
151
|
+
- `DynamicInput`: creates additional input ports, useful for allowing a dynamic number of inputs
|
|
152
|
+
- `DynamicOutput`: creates output ports on the fly based on the function result
|
|
153
|
+
- `NamedInput`: allows adding and renaming input ports by the user
|
|
154
|
+
- `Input` and `Output`: used for rule input and output
|
|
155
|
+
|
|
156
|
+
# Components / functions reference
|
|
157
|
+
|
|
158
|
+
## List
|
|
159
|
+
|
|
160
|
+
- List Input: creates a list of strings or numbers based on textfield input
|
|
161
|
+
- List Item: selects items from a list based on their indices
|
|
162
|
+
- List Length: returns the length of a list
|
|
163
|
+
- Relative Item
|
|
164
|
+
- Relative Items
|
|
165
|
+
- Unique Items: removes duplicates from a list
|
|
166
|
+
|
|
167
|
+
## Logic
|
|
168
|
+
|
|
169
|
+
- And: returns true if both inputs are true
|
|
170
|
+
- Or: returns true if one or both of the inputs are true
|
|
171
|
+
- Not: negates all elements in the list
|
|
172
|
+
- Group And: returns true if all elements in the list are true
|
|
173
|
+
- Group Or: returns true if some elements in the list are true
|
|
174
|
+
- Group stats: returns min, max, avg, std, sum and count of a list of numbers
|
|
175
|
+
|
|
176
|
+
## Math
|
|
177
|
+
|
|
178
|
+
- Add
|
|
179
|
+
- Subtract
|
|
180
|
+
- Multiply
|
|
181
|
+
- Divide
|
|
182
|
+
- Modulo
|
|
183
|
+
- Pow
|
|
184
|
+
- Sqrt
|
|
185
|
+
- Round
|
|
186
|
+
- Floor
|
|
187
|
+
- Ceil
|
|
188
|
+
- Sin
|
|
189
|
+
- Cos
|
|
190
|
+
- Tan
|
|
191
|
+
- Sum
|
|
192
|
+
- Less Than
|
|
193
|
+
- Greater Than
|
|
194
|
+
|
|
195
|
+
## String
|
|
196
|
+
|
|
197
|
+
- Join Strings
|
|
198
|
+
- String Equal To
|
|
199
|
+
- String Template
|
|
200
|
+
- To String
|
|
201
|
+
|
|
202
|
+
## Date
|
|
203
|
+
|
|
204
|
+
- Duration
|
|
205
|
+
- Format Date
|
|
206
|
+
- Iso Date
|
|
207
|
+
- Parse Date
|
|
208
|
+
- Today
|
|
209
|
+
|
|
210
|
+
## Util
|
|
211
|
+
|
|
212
|
+
- Get Type
|
|
213
|
+
- Get Value
|
|
214
|
+
- Log
|
|
215
|
+
- Value
|
|
216
|
+
|
|
217
|
+
## Sequence
|
|
218
|
+
|
|
219
|
+
- Series
|
|
220
|
+
|
|
221
|
+
## JSON
|
|
222
|
+
|
|
223
|
+
- Array To List
|
|
224
|
+
- Destructure Object
|
|
225
|
+
- Explode Object
|
|
226
|
+
- List To Array
|
|
227
|
+
- Merge Object
|
|
228
|
+
- Object
|
|
229
|
+
- Entries
|
|
230
|
+
- Set Field
|
|
231
|
+
|
|
232
|
+
## Group
|
|
233
|
+
|
|
234
|
+
- Cartesian Groups
|
|
235
|
+
- Filter Tree
|
|
236
|
+
- Group All
|
|
237
|
+
- Merge Group
|
|
238
|
+
- Merge Tree
|
|
239
|
+
- Normalize Tree
|
|
240
|
+
- SimplifyTree
|
|
241
|
+
- Split Group
|
|
242
|
+
- Tree Item
|
|
243
|
+
|
|
244
|
+
## IO
|
|
245
|
+
|
|
246
|
+
- Input
|
|
247
|
+
- Output
|
|
248
|
+
|
|
85
249
|
TODO:
|
|
86
250
|
|
|
87
251
|
- [ ] filtering of lists
|
|
@@ -93,20 +257,6 @@ TODO:
|
|
|
93
257
|
- running flag
|
|
94
258
|
- intermediate results
|
|
95
259
|
|
|
96
|
-
Components / functions
|
|
97
|
-
|
|
98
|
-
List
|
|
99
|
-
|
|
100
|
-
- [x] listItem
|
|
101
|
-
- [x] listLength
|
|
102
|
-
- [x] graftTree
|
|
103
|
-
- [x] trimTree
|
|
104
|
-
|
|
105
|
-
Math
|
|
106
|
-
|
|
107
|
-
- [x] lessThan
|
|
108
|
-
- [x] greaterThan
|
|
109
|
-
|
|
110
260
|
Text
|
|
111
261
|
|
|
112
262
|
- formatting
|