@rkmodules/rules 0.0.161 → 0.0.163
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.js +68 -32
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +68 -32
- 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 +104 -14
package/dist/index.esm.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { create, all } from 'mathjs';
|
|
2
|
+
import { interpolate as interpolate$1 } from '@rkmodules/stringtemplate';
|
|
2
3
|
import React, { createContext, memo, useEffect, useLayoutEffect, useState, useCallback, useMemo, isValidElement, cloneElement, useContext } from 'react';
|
|
3
4
|
import { Handle, Position, useReactFlow, useConnection, getSimpleBezierPath, ReactFlowProvider, useOnSelectionChange, applyNodeChanges, applyEdgeChanges, ReactFlow, Background, BackgroundVariant, Controls } from '@xyflow/react';
|
|
4
5
|
import katex from 'katex';
|
|
@@ -1490,29 +1491,38 @@ var stringEqualTo = {
|
|
|
1490
1491
|
var stringTemplate = {
|
|
1491
1492
|
name: "stringTemplate",
|
|
1492
1493
|
label: "String Template",
|
|
1493
|
-
description: "Assembles a string from inputs",
|
|
1494
|
-
nodeType: "
|
|
1494
|
+
description: "Assembles a string from inputs, use ${...} to interpolate inputs",
|
|
1495
|
+
nodeType: { name: "NamedInput", props: { fixed: ["template"] } },
|
|
1495
1496
|
inputs: {
|
|
1496
1497
|
template: { type: "string", default: "" },
|
|
1497
1498
|
},
|
|
1499
|
+
params: {
|
|
1500
|
+
fillout: { type: "boolean", default: false },
|
|
1501
|
+
},
|
|
1498
1502
|
outputs: {
|
|
1499
1503
|
tree: { type: "string", label: "string" },
|
|
1500
1504
|
},
|
|
1501
|
-
impl: function (_a, params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1502
|
-
var
|
|
1503
|
-
var _b
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1505
|
+
impl: function (_a, params, engine, context, name) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1506
|
+
var inputKeys, inputDefs, labels, inputTrees, value;
|
|
1507
|
+
var _b;
|
|
1508
|
+
var _c = _a.template, template = _c === void 0 ? {} : _c, inputs = __rest(_a, ["template"]);
|
|
1509
|
+
return __generator(this, function (_d) {
|
|
1510
|
+
inputKeys = Object.keys(inputs);
|
|
1511
|
+
inputDefs = ((_b = context === null || context === void 0 ? void 0 : context.calls[name]) === null || _b === void 0 ? void 0 : _b.inputDefs) || {};
|
|
1512
|
+
labels = inputKeys.map(function (key) { var _a; return ((_a = normalizeVarDef(inputDefs[key])) === null || _a === void 0 ? void 0 : _a.label) || key; });
|
|
1513
|
+
inputTrees = Object.values(inputs);
|
|
1514
|
+
if (!inputTrees.length) {
|
|
1515
|
+
inputTrees = [{ 0: [""] }];
|
|
1516
|
+
}
|
|
1517
|
+
__spreadArray([template], __read(Object.values(inputs)), false);
|
|
1518
|
+
value = nAryOnTree(__spreadArray([template], __read(inputTrees), false), function (_a) {
|
|
1519
|
+
var _b = __read(_a), template = _b[0], values = _b.slice(1);
|
|
1520
|
+
if (!template)
|
|
1521
|
+
return DISCARD;
|
|
1522
|
+
var context = Object.fromEntries(values.map(function (value, index) { return [labels[index], value]; }));
|
|
1523
|
+
return interpolate$1(template, context);
|
|
1524
|
+
}, params.fillout || false);
|
|
1525
|
+
return [2 /*return*/, { tree: value }];
|
|
1516
1526
|
});
|
|
1517
1527
|
}); },
|
|
1518
1528
|
};
|
|
@@ -2936,6 +2946,7 @@ var duration = {
|
|
|
2936
2946
|
label: "Duration",
|
|
2937
2947
|
description: "Creates a duration",
|
|
2938
2948
|
inputs: {
|
|
2949
|
+
weeks: { type: "number", default: 0 },
|
|
2939
2950
|
days: { type: "number", default: 0 },
|
|
2940
2951
|
hours: { type: "number", default: 0 },
|
|
2941
2952
|
minutes: { type: "number", default: 0 },
|
|
@@ -2949,14 +2960,16 @@ var duration = {
|
|
|
2949
2960
|
return __generator(this, function (_a) {
|
|
2950
2961
|
return [2 /*return*/, {
|
|
2951
2962
|
duration: nAryOnTree([
|
|
2963
|
+
inputs.weeks || {},
|
|
2952
2964
|
inputs.days || {},
|
|
2953
2965
|
inputs.hours || {},
|
|
2954
2966
|
inputs.minutes || {},
|
|
2955
2967
|
inputs.seconds || {},
|
|
2956
2968
|
inputs.milliseconds || {},
|
|
2957
2969
|
], function (_a) {
|
|
2958
|
-
var _b = __read(_a,
|
|
2959
|
-
var totalMilliseconds =
|
|
2970
|
+
var _b = __read(_a, 6), _c = _b[0], weeks = _c === void 0 ? 0 : _c, _d = _b[1], days = _d === void 0 ? 0 : _d, _e = _b[2], hours = _e === void 0 ? 0 : _e, _f = _b[3], minutes = _f === void 0 ? 0 : _f, _g = _b[4], seconds = _g === void 0 ? 0 : _g, _h = _b[5], milliseconds = _h === void 0 ? 0 : _h;
|
|
2971
|
+
var totalMilliseconds = weeks * 7 * 24 * 60 * 60 * 1000 +
|
|
2972
|
+
days * 24 * 60 * 60 * 1000 +
|
|
2960
2973
|
hours * 60 * 60 * 1000 +
|
|
2961
2974
|
minutes * 60 * 1000 +
|
|
2962
2975
|
seconds * 1000 +
|
|
@@ -7063,18 +7076,19 @@ DynamicOutput.displayName = "DynamicOutputNode";
|
|
|
7063
7076
|
|
|
7064
7077
|
var NamedInput = function (_a) {
|
|
7065
7078
|
var _b;
|
|
7066
|
-
var _c;
|
|
7079
|
+
var _c, _d;
|
|
7067
7080
|
var id = _a.id, data = _a.data, selected = _a.selected;
|
|
7068
7081
|
var engine = useEngine();
|
|
7069
7082
|
// let fn = useGraphedFunction();
|
|
7070
7083
|
var prompt = usePrompts().prompt;
|
|
7084
|
+
var fixedInputs = new Set(((_c = data.nodeProps) === null || _c === void 0 ? void 0 : _c.fixed) || []);
|
|
7071
7085
|
var inputEntries = Object.entries(data.inputDefs || {});
|
|
7072
7086
|
var outputEntries = Object.entries(data.outputDefs || {});
|
|
7073
7087
|
var paramEntries = Object.entries(data.paramDefs || {});
|
|
7074
|
-
var
|
|
7075
|
-
var
|
|
7076
|
-
var
|
|
7077
|
-
var
|
|
7088
|
+
var _e = __read(React.useState({}), 2), result = _e[0], setResult = _e[1];
|
|
7089
|
+
var _f = __read(React.useState(null), 2), duration = _f[0], setDuration = _f[1];
|
|
7090
|
+
var _g = __read(useInner(((_d = outputEntries[0]) === null || _d === void 0 ? void 0 : _d[0]) || null, [data.outputDefs]), 2), focus = _g[0], setFocus = _g[1];
|
|
7091
|
+
var _h = __read(React.useState(false), 2), showPreview = _h[0], setShowPreview = _h[1];
|
|
7078
7092
|
var previewValue = focus ? result[focus] : Object.values(result)[0];
|
|
7079
7093
|
React.useEffect(function () {
|
|
7080
7094
|
return engine.subscribe("functionResult", function (event) {
|
|
@@ -7133,7 +7147,8 @@ var NamedInput = function (_a) {
|
|
|
7133
7147
|
}),
|
|
7134
7148
|
inputEntries.map(function (_a, index) {
|
|
7135
7149
|
var _b = __read(_a, 2), name = _b[0], varDef = _b[1];
|
|
7136
|
-
|
|
7150
|
+
var menu = !fixedInputs.has(name);
|
|
7151
|
+
return (React.createElement(Input, { key: "".concat(name, "_").concat(index), name: name, varDef: varDef, id: id, data: data, onRename: menu ? onRename : undefined, onDelete: menu ? onDelete : undefined }));
|
|
7137
7152
|
}),
|
|
7138
7153
|
React.createElement("div", { className: styles.Body },
|
|
7139
7154
|
React.createElement("button", { onClick: function () { return onAdd(); } }, "+")),
|
|
@@ -7258,6 +7273,17 @@ function deRefEdgeHandle(handle) {
|
|
|
7258
7273
|
function createNode(engine, id, fncall, options) {
|
|
7259
7274
|
var _a, _b;
|
|
7260
7275
|
var calledFn = engine.getFunction(fncall.name);
|
|
7276
|
+
var nodeType = "Default";
|
|
7277
|
+
var nodeProps = {};
|
|
7278
|
+
if (calledFn === null || calledFn === void 0 ? void 0 : calledFn.nodeType) {
|
|
7279
|
+
if (typeof calledFn.nodeType === "string") {
|
|
7280
|
+
nodeType = calledFn.nodeType;
|
|
7281
|
+
}
|
|
7282
|
+
else {
|
|
7283
|
+
nodeType = calledFn.nodeType.name;
|
|
7284
|
+
nodeProps = calledFn.nodeType.props || {};
|
|
7285
|
+
}
|
|
7286
|
+
}
|
|
7261
7287
|
// create a node for each function call
|
|
7262
7288
|
return {
|
|
7263
7289
|
id: id,
|
|
@@ -7272,10 +7298,11 @@ function createNode(engine, id, fncall, options) {
|
|
|
7272
7298
|
outputDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.outputs) || {},
|
|
7273
7299
|
onChange: ((_a = options.onDataChange) === null || _a === void 0 ? void 0 : _a.call(options, id)) || (function () { }),
|
|
7274
7300
|
onIOChange: options.onIOChange || (function (fn) { return fn; }),
|
|
7301
|
+
nodeProps: nodeProps,
|
|
7275
7302
|
},
|
|
7276
7303
|
position: ((_b = options.positions) === null || _b === void 0 ? void 0 : _b[id]) || { x: 0, y: 0 },
|
|
7277
7304
|
dragHandle: options.dragHandle,
|
|
7278
|
-
type:
|
|
7305
|
+
type: nodeType,
|
|
7279
7306
|
};
|
|
7280
7307
|
}
|
|
7281
7308
|
function createEdge(nodeId, ref) {
|
|
@@ -7462,7 +7489,7 @@ var ConnectionLine = (function (_a) {
|
|
|
7462
7489
|
*/
|
|
7463
7490
|
var emptyObject = {};
|
|
7464
7491
|
function FlowInner(_a) {
|
|
7465
|
-
var fn = _a.function, _b = _a.positions, defaultPositions = _b === void 0 ? emptyObject : _b, engine = _a.engine, _c = _a.center, center = _c === void 0 ? true : _c, fitView = _a.fitView, _d = _a.customNodes, customNodes = _d === void 0 ? {} : _d, onChange = _a.onChange, onClick = _a.onClick, onContextMenu = _a.onContextMenu, onSelect = _a.onSelect, onInit = _a.onInit;
|
|
7492
|
+
var fn = _a.function, _b = _a.positions, defaultPositions = _b === void 0 ? emptyObject : _b, engine = _a.engine, _c = _a.center, center = _c === void 0 ? true : _c, fitView = _a.fitView, _d = _a.customNodes, customNodes = _d === void 0 ? {} : _d, onChange = _a.onChange, onClick = _a.onClick, onContextMenu = _a.onContextMenu, onMouseMove = _a.onMouseMove, onSelect = _a.onSelect, onInit = _a.onInit;
|
|
7466
7493
|
var _e = __read(React.useState(null), 2), instance = _e[0], setInstance = _e[1];
|
|
7467
7494
|
var handleInit = function (instance) {
|
|
7468
7495
|
setInstance(instance);
|
|
@@ -7566,21 +7593,30 @@ function FlowInner(_a) {
|
|
|
7566
7593
|
}, [onChange, fn]);
|
|
7567
7594
|
// handle canvas clicks to be able to place nodes
|
|
7568
7595
|
var handleClick = function (e) {
|
|
7569
|
-
if (instance) {
|
|
7596
|
+
if (instance && onClick) {
|
|
7570
7597
|
var position = instance.screenToFlowPosition({
|
|
7571
7598
|
x: e.clientX,
|
|
7572
7599
|
y: e.clientY,
|
|
7573
7600
|
});
|
|
7574
|
-
onClick
|
|
7601
|
+
onClick(e, position);
|
|
7575
7602
|
}
|
|
7576
7603
|
};
|
|
7577
7604
|
var handleContextMenu = function (e) {
|
|
7578
|
-
if (instance) {
|
|
7605
|
+
if (instance && onContextMenu) {
|
|
7606
|
+
var position = instance.screenToFlowPosition({
|
|
7607
|
+
x: e.clientX,
|
|
7608
|
+
y: e.clientY,
|
|
7609
|
+
});
|
|
7610
|
+
onContextMenu(e, position);
|
|
7611
|
+
}
|
|
7612
|
+
};
|
|
7613
|
+
var handleMouseMove = function (e) {
|
|
7614
|
+
if (instance && onMouseMove) {
|
|
7579
7615
|
var position = instance.screenToFlowPosition({
|
|
7580
7616
|
x: e.clientX,
|
|
7581
7617
|
y: e.clientY,
|
|
7582
7618
|
});
|
|
7583
|
-
|
|
7619
|
+
onMouseMove(e, position);
|
|
7584
7620
|
}
|
|
7585
7621
|
};
|
|
7586
7622
|
var onNodesChange = React.useCallback(function (changes) {
|
|
@@ -7603,7 +7639,7 @@ function FlowInner(_a) {
|
|
|
7603
7639
|
return applyEdgeChanges(changes, edgesSnapshot);
|
|
7604
7640
|
});
|
|
7605
7641
|
}, []);
|
|
7606
|
-
return (React.createElement(ReactFlow, { ref: drop, nodes: nodes, edges: edges, nodeTypes: __assign(__assign({}, nodeTypes), customNodes), onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onNodesDelete: onNodesDelete, onEdgesDelete: onEdgesDelete, onNodeDragStop: function (e, n) { return updatePosition(n.id, n.position); }, onConnect: onConnect, onInit: handleInit, onPaneClick: handleClick, onPaneContextMenu: handleContextMenu, fitView: center || fitView, fitViewOptions: {
|
|
7642
|
+
return (React.createElement(ReactFlow, { ref: drop, nodes: nodes, edges: edges, nodeTypes: __assign(__assign({}, nodeTypes), customNodes), onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onNodesDelete: onNodesDelete, onEdgesDelete: onEdgesDelete, onNodeDragStop: function (e, n) { return updatePosition(n.id, n.position); }, onConnect: onConnect, onInit: handleInit, onPaneClick: handleClick, onPaneContextMenu: handleContextMenu, onPaneMouseMove: handleMouseMove, fitView: center || fitView, fitViewOptions: {
|
|
7607
7643
|
minZoom: fitView ? undefined : 1,
|
|
7608
7644
|
maxZoom: fitView ? undefined : 1,
|
|
7609
7645
|
},
|