@rkmodules/rules 0.0.1
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/app/editor/calcTestFunction.d.ts +2 -0
- package/dist/app/editor/page.d.ts +2 -0
- package/dist/app/finance/entriesTestFunction.d.ts +2 -0
- package/dist/app/finance/page.d.ts +2 -0
- package/dist/app/finance/testEntries.d.ts +40 -0
- package/dist/app/layout.d.ts +9 -0
- package/dist/app/page.d.ts +2 -0
- package/dist/app/supalipu/page.d.ts +13 -0
- package/dist/index.css +81 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1635 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/DataTree/index.d.ts +100 -0
- package/dist/lib/DataTree/monad.d.ts +35 -0
- package/dist/lib/DataTree/types.d.ts +2 -0
- package/dist/lib/DataTree/util.d.ts +31 -0
- package/dist/lib/Engine/Rule.d.ts +2 -0
- package/dist/lib/Engine/index.d.ts +54 -0
- package/dist/lib/Engine/types.d.ts +55 -0
- package/dist/lib/Engine/util.d.ts +7 -0
- package/dist/lib/Flow/Components/Control.d.ts +9 -0
- package/dist/lib/Flow/Components/GenericNode.d.ts +15 -0
- package/dist/lib/Flow/Components/Input.d.ts +8 -0
- package/dist/lib/Flow/Components/NodeContainer.d.ts +10 -0
- package/dist/lib/Flow/Components/Output.d.ts +6 -0
- package/dist/lib/Flow/Components/Param.d.ts +8 -0
- package/dist/lib/Flow/Context.d.ts +6 -0
- package/dist/lib/Flow/Nodes/Calc.d.ts +11 -0
- package/dist/lib/Flow/Nodes/Default.d.ts +4 -0
- package/dist/lib/Flow/Nodes/Log.d.ts +4 -0
- package/dist/lib/Flow/Nodes/index.d.ts +5 -0
- package/dist/lib/Flow/index.d.ts +21 -0
- package/dist/lib/Flow/types.d.ts +8 -0
- package/dist/lib/Primitives/List/filterList.d.ts +2 -0
- package/dist/lib/Primitives/List/graftTree.d.ts +2 -0
- package/dist/lib/Primitives/List/index.d.ts +3 -0
- package/dist/lib/Primitives/List/listItem.d.ts +2 -0
- package/dist/lib/Primitives/List/listLength.d.ts +2 -0
- package/dist/lib/Primitives/List/trimTree.d.ts +2 -0
- package/dist/lib/Primitives/Math/calc.d.ts +12 -0
- package/dist/lib/Primitives/Math/greaterThan.d.ts +2 -0
- package/dist/lib/Primitives/Math/index.d.ts +3 -0
- package/dist/lib/Primitives/Math/lessThan.d.ts +2 -0
- package/dist/lib/Primitives/Util/getValue.d.ts +5 -0
- package/dist/lib/Primitives/Util/index.d.ts +3 -0
- package/dist/lib/Primitives/Util/log.d.ts +2 -0
- package/dist/lib/Primitives/Util/value.d.ts +5 -0
- package/dist/lib/Primitives/index.d.ts +2 -0
- package/dist/lib/hooks/useFunction.d.ts +18 -0
- package/dist/lib/hooks/useVariable.d.ts +6 -0
- package/package.json +56 -0
- package/readme.md +66 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Tree } from "../DataTree";
|
|
2
|
+
/**
|
|
3
|
+
* type definition of rule inputs and outputs
|
|
4
|
+
*/
|
|
5
|
+
export type NormalizedVarDef = {
|
|
6
|
+
type: string;
|
|
7
|
+
default?: any;
|
|
8
|
+
description?: string;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
options?: string[];
|
|
11
|
+
};
|
|
12
|
+
export type VarDef = string | NormalizedVarDef;
|
|
13
|
+
/**
|
|
14
|
+
* a reference to the output of an previous function call or a primitive value
|
|
15
|
+
*/
|
|
16
|
+
export type VarRefValue = string | number | boolean | Object;
|
|
17
|
+
export type VarRef = Record<string, VarRefValue | VarRefValue[]>;
|
|
18
|
+
export type RecOfTrees = Record<string, Tree<any>>;
|
|
19
|
+
/**
|
|
20
|
+
* primitive node, with input and output definitions and an implementation
|
|
21
|
+
* this is similar to native functions
|
|
22
|
+
*/
|
|
23
|
+
export type PrimitiveFunction = {
|
|
24
|
+
name: string;
|
|
25
|
+
label?: string;
|
|
26
|
+
nodeType?: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
params?: Record<string, VarDef>;
|
|
29
|
+
inputs?: Record<string, VarDef>;
|
|
30
|
+
outputs?: Record<string, VarDef>;
|
|
31
|
+
impl: (inputs: RecOfTrees, params: Record<string, any>) => Promise<RecOfTrees>;
|
|
32
|
+
mount?: (trigger: () => void) => (() => void) | void;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* reference to another function, which can be seen as a function call
|
|
36
|
+
*/
|
|
37
|
+
export type FunctionCall = {
|
|
38
|
+
name: string;
|
|
39
|
+
inputs?: VarRef;
|
|
40
|
+
params?: VarRef;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* a node that contains other nodes, with input and output definitions and references to other nodes
|
|
44
|
+
* this is similar to a function definition that only calls other functions
|
|
45
|
+
*/
|
|
46
|
+
export type GraphedFunction = {
|
|
47
|
+
name: string;
|
|
48
|
+
label?: string;
|
|
49
|
+
description?: string;
|
|
50
|
+
params?: Record<string, VarDef>;
|
|
51
|
+
inputs?: Record<string, VarDef>;
|
|
52
|
+
outputs?: VarRef;
|
|
53
|
+
body: Record<string, FunctionCall>;
|
|
54
|
+
};
|
|
55
|
+
export type AnyFunction = PrimitiveFunction | GraphedFunction;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Tree } from "../DataTree";
|
|
2
|
+
import { VarRef } from "./types";
|
|
3
|
+
export declare function isReference(value: any): value is string;
|
|
4
|
+
export declare function parseReference(ref: string): string;
|
|
5
|
+
export declare function uid(): string;
|
|
6
|
+
export declare function getValue(obj: Record<string, any>, path: string): any;
|
|
7
|
+
export declare function interpolate(inputs: VarRef, scope: Record<string, Record<string, Tree<any>>>): Record<string, Tree<any>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FunctionNode } from "../types";
|
|
3
|
+
import { GraphedFunction, VarDef } from "../../Engine";
|
|
4
|
+
interface GenericNodeProps {
|
|
5
|
+
id: string;
|
|
6
|
+
data: FunctionNode["data"];
|
|
7
|
+
selected: boolean;
|
|
8
|
+
inputs?: Record<string, VarDef>;
|
|
9
|
+
outputs?: Record<string, VarDef>;
|
|
10
|
+
params?: Record<string, VarDef>;
|
|
11
|
+
children?: React.ReactNode;
|
|
12
|
+
onChange: (fn: GraphedFunction) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function GenericNode({ id, data, selected, inputs, outputs, params, children, onChange, }: GenericNodeProps): React.JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface NodeContainerProps {
|
|
3
|
+
id?: string;
|
|
4
|
+
label: string;
|
|
5
|
+
className?: string;
|
|
6
|
+
selected?: boolean;
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare function NodeContainer({ id, label, className, selected, children, }: NodeContainerProps): React.JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Engine, GraphedFunction } from "../Engine";
|
|
3
|
+
export declare const EngineContext: React.Context<Engine>;
|
|
4
|
+
export declare const useEngine: () => Engine;
|
|
5
|
+
export declare const ChangeContext: React.Context<(fn: GraphedFunction) => void>;
|
|
6
|
+
export declare const useChange: () => (fn: GraphedFunction) => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { NodeProps } from "@xyflow/react";
|
|
3
|
+
import { FunctionNode } from "../types";
|
|
4
|
+
import "katex/dist/katex.min.css";
|
|
5
|
+
type MathProps = {
|
|
6
|
+
expr: string;
|
|
7
|
+
displayMode?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function MathView({ expr, displayMode }: MathProps): React.JSX.Element;
|
|
10
|
+
export declare const Calc: React.MemoExoticComponent<({ id, data, selected }: NodeProps<FunctionNode>) => React.JSX.Element>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const nodeTypes: {
|
|
2
|
+
Default: import("react").MemoExoticComponent<({ id, data, selected }: import("@xyflow/react").NodeProps<import("..").FunctionNode>) => import("react").JSX.Element>;
|
|
3
|
+
Calc: import("react").MemoExoticComponent<({ id, data, selected }: import("@xyflow/react").NodeProps<import("..").FunctionNode>) => import("react").JSX.Element>;
|
|
4
|
+
Log: import("react").MemoExoticComponent<({ id, data, selected }: import("@xyflow/react").NodeProps<import("..").FunctionNode>) => import("react").JSX.Element>;
|
|
5
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Edge } from "@xyflow/react";
|
|
2
|
+
import { GraphedFunction } from "../Engine/types";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { Engine } from "../Engine";
|
|
5
|
+
import { FunctionNode } from "./types";
|
|
6
|
+
import "@xyflow/react/dist/style.css";
|
|
7
|
+
export * from "./types";
|
|
8
|
+
export type PositionData = Record<string, {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
}>;
|
|
12
|
+
export declare function createGraph(fn: GraphedFunction, engine: Engine, positions?: PositionData): {
|
|
13
|
+
nodes: FunctionNode[];
|
|
14
|
+
edges: Edge[];
|
|
15
|
+
};
|
|
16
|
+
interface FlowProps {
|
|
17
|
+
function: GraphedFunction;
|
|
18
|
+
engine: Engine;
|
|
19
|
+
onChange?: (fn: GraphedFunction) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare function Flow({ function: fn, engine, onChange }: FlowProps): React.JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PrimitiveFunction } from "../../Engine";
|
|
2
|
+
/**
|
|
3
|
+
* TODO: need rank polymorhism on the tree item sizes
|
|
4
|
+
*/
|
|
5
|
+
export declare const calc: PrimitiveFunction;
|
|
6
|
+
/**
|
|
7
|
+
* Return a sorted list of unbound symbol names in a MathJS expression.
|
|
8
|
+
* @param expr The expression string, e.g. "x + y"
|
|
9
|
+
* @param scope Names already defined/known (e.g. from your evaluation scope)
|
|
10
|
+
* @param extraBound Extra names to treat as bound (e.g. UI reserved words)
|
|
11
|
+
*/
|
|
12
|
+
export declare function getUnboundSymbols(expr: string, scope?: Record<string, unknown>, extraBound?: string[]): string[];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Engine, GraphedFunction } from "../Engine";
|
|
2
|
+
/**
|
|
3
|
+
* using functions
|
|
4
|
+
*
|
|
5
|
+
* in React context
|
|
6
|
+
* - use useFunction. This will build the function, mount it if needed and provides a run function.
|
|
7
|
+
*
|
|
8
|
+
*
|
|
9
|
+
* in Vanilla context
|
|
10
|
+
* - use engine.build(fn) to build the function
|
|
11
|
+
* - use engine.mount(fn) to mount the function (if it has a mount function)
|
|
12
|
+
* - use await engine.run(fn, inputs) to run the function and get the result
|
|
13
|
+
*/
|
|
14
|
+
export declare function useFunction(engine: Engine, fn: GraphedFunction, mount?: boolean): {
|
|
15
|
+
fn: import("../Engine").PrimitiveFunction;
|
|
16
|
+
run: (inputs?: Record<string, any>) => Promise<any>;
|
|
17
|
+
result: any;
|
|
18
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rkmodules/rules",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.js",
|
|
11
|
+
"./styles.css": "./dist/index.css"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "jest",
|
|
15
|
+
"test:watch": "jest --watch",
|
|
16
|
+
"watch": "tsc -w --project tsconfig-pack.json",
|
|
17
|
+
"build:ts": "tsc --project tsconfig-pack.json",
|
|
18
|
+
"build": "npm run rollup",
|
|
19
|
+
"rollup": "rm -rf dist && rollup -c",
|
|
20
|
+
"prepare": "npm run rollup",
|
|
21
|
+
"dev": "next dev"
|
|
22
|
+
},
|
|
23
|
+
"author": "rikkert@rikkertkoppes.com",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"description": "",
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"next": ">=14.2.3",
|
|
28
|
+
"react": ">=19.1.1",
|
|
29
|
+
"react-dom": ">=19.1.1"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@rkmodules/use-inner": "^1.0.3",
|
|
33
|
+
"@xyflow/react": "^12.8.3",
|
|
34
|
+
"classnames": "^2.5.1",
|
|
35
|
+
"katex": "^0.16.22",
|
|
36
|
+
"mathjs": "^14.6.0",
|
|
37
|
+
"zustand": "^5.0.7"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@rkmodules/use-selection": "^0.10.0",
|
|
41
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
42
|
+
"@rollup/plugin-typescript": "^12.1.4",
|
|
43
|
+
"@types/jest": "^30.0.0",
|
|
44
|
+
"@types/node": "24.3.0",
|
|
45
|
+
"@types/react": "^19.1.1",
|
|
46
|
+
"jest": "^30.0.5",
|
|
47
|
+
"next": "^15.4.7",
|
|
48
|
+
"react": "^19.1.1",
|
|
49
|
+
"react-dom": "^19.1.1",
|
|
50
|
+
"rollup": "^4.46.3",
|
|
51
|
+
"rollup-plugin-exclude-dependencies-from-bundle": "^1.1.24",
|
|
52
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
53
|
+
"ts-jest": "^29.4.1",
|
|
54
|
+
"typescript": "^5.9.2"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
TODO:
|
|
2
|
+
|
|
3
|
+
- [ ] filtering of lists
|
|
4
|
+
- document grasshopper nodes
|
|
5
|
+
- build them
|
|
6
|
+
- [ ] set value
|
|
7
|
+
- [ ] inspection
|
|
8
|
+
- run time
|
|
9
|
+
- running flag
|
|
10
|
+
- intermediate results
|
|
11
|
+
|
|
12
|
+
Components / functions
|
|
13
|
+
|
|
14
|
+
List
|
|
15
|
+
|
|
16
|
+
- [x] listItem
|
|
17
|
+
- [x] listLength
|
|
18
|
+
- [x] graftTree
|
|
19
|
+
- [x] trimTree
|
|
20
|
+
|
|
21
|
+
Math
|
|
22
|
+
|
|
23
|
+
- [x] lessThan
|
|
24
|
+
- [x] greaterThan
|
|
25
|
+
|
|
26
|
+
Text
|
|
27
|
+
|
|
28
|
+
- formatting
|
|
29
|
+
- text replacement
|
|
30
|
+
|
|
31
|
+
grasshopper investigation
|
|
32
|
+
|
|
33
|
+
value
|
|
34
|
+
|
|
35
|
+
# using functions
|
|
36
|
+
|
|
37
|
+
in React context
|
|
38
|
+
|
|
39
|
+
- use useFunction. This will build the function, mount it if needed and provides a run function.
|
|
40
|
+
|
|
41
|
+
in Vanilla context
|
|
42
|
+
|
|
43
|
+
- use engine.build(fn) to build the function
|
|
44
|
+
- use engine.mount(fn) to mount the function (if it has a mount function)
|
|
45
|
+
- use engine.run(fn, inputs) to run the function
|
|
46
|
+
|
|
47
|
+
# considerations
|
|
48
|
+
|
|
49
|
+
For Supa Lipu we have quite a lot of functions that need to be called on various events
|
|
50
|
+
|
|
51
|
+
- when propobjects are updated / created / deleted.
|
|
52
|
+
|
|
53
|
+
- currently, each propobject has its own engine and 1 single rule. This is fired when the object is mutated
|
|
54
|
+
- all functions need to be propobjects as well, then referenced in various places
|
|
55
|
+
- the engine needs to be global, so that functions can reference each other
|
|
56
|
+
- for these references, we need propobject refs, to that dependency functions are loaded
|
|
57
|
+
- in useObjectMutation, we fire an event such that mounted eventlisteners can react
|
|
58
|
+
|
|
59
|
+
- we need deep references. On change, oldProps and changedProps are passed in as an object. So we need
|
|
60
|
+
- primitives to getValue and setValue
|
|
61
|
+
- [x] reference strings that can directly reference deeper objects to eliminate the need for getValue
|
|
62
|
+
- [x] also need to think about data tree handling for outputs
|
|
63
|
+
|
|
64
|
+
# Entries
|
|
65
|
+
|
|
66
|
+
- in finance I had filterLine(on, match) function that filters return a boolean if any of the lines match. This is a hardcoded solition, which is ok for finance. But we might come up with something more generic
|