@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.
@@ -114,8 +114,9 @@
114
114
  --ln: var(--node-line);
115
115
  --bg: var(--node-background);
116
116
  border: 1px solid var(--ln);
117
- border-radius: 4px;
118
- background-color: var(--bg);
117
+ border-radius: var(--node-radius, 4px);
118
+ background: var(--bg);
119
+ box-shadow: var(--node-shadow);
119
120
  min-width: 200px;
120
121
  cursor: default;
121
122
  }
package/dist/index.cjs.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var mathjs = require('mathjs');
4
+ var stringtemplate = require('@rkmodules/stringtemplate');
4
5
  var React = require('react');
5
6
  var react = require('@xyflow/react');
6
7
  var katex = require('katex');
@@ -1492,29 +1493,38 @@ var stringEqualTo = {
1492
1493
  var stringTemplate = {
1493
1494
  name: "stringTemplate",
1494
1495
  label: "String Template",
1495
- description: "Assembles a string from inputs",
1496
- nodeType: "DynamicInput",
1496
+ description: "Assembles a string from inputs, use ${...} to interpolate inputs",
1497
+ nodeType: { name: "NamedInput", props: { fixed: ["template"] } },
1497
1498
  inputs: {
1498
1499
  template: { type: "string", default: "" },
1499
1500
  },
1501
+ params: {
1502
+ fillout: { type: "boolean", default: false },
1503
+ },
1500
1504
  outputs: {
1501
1505
  tree: { type: "string", label: "string" },
1502
1506
  },
1503
- impl: function (_a, params) { return __awaiter(void 0, void 0, void 0, function () {
1504
- var trees;
1505
- var _b = _a.template, template = _b === void 0 ? {} : _b, inputs = __rest(_a, ["template"]);
1506
- return __generator(this, function (_c) {
1507
- trees = __spreadArray([template], __read(Object.values(inputs)), false);
1508
- return [2 /*return*/, {
1509
- tree: nAryOnTree(trees, function (_a) {
1510
- var _b = __read(_a), template = _b[0], values = _b.slice(1);
1511
- return template.replace(/{D(\d+)}/g, function (match, number) {
1512
- return typeof values[number - 1] !== "undefined"
1513
- ? values[number - 1]
1514
- : match;
1515
- });
1516
- }, true),
1517
- }];
1507
+ impl: function (_a, params, engine, context, name) { return __awaiter(void 0, void 0, void 0, function () {
1508
+ var inputKeys, inputDefs, labels, inputTrees, value;
1509
+ var _b;
1510
+ var _c = _a.template, template = _c === void 0 ? {} : _c, inputs = __rest(_a, ["template"]);
1511
+ return __generator(this, function (_d) {
1512
+ inputKeys = Object.keys(inputs);
1513
+ inputDefs = ((_b = context === null || context === void 0 ? void 0 : context.calls[name]) === null || _b === void 0 ? void 0 : _b.inputDefs) || {};
1514
+ labels = inputKeys.map(function (key) { var _a; return ((_a = normalizeVarDef(inputDefs[key])) === null || _a === void 0 ? void 0 : _a.label) || key; });
1515
+ inputTrees = Object.values(inputs);
1516
+ if (!inputTrees.length) {
1517
+ inputTrees = [{ 0: [""] }];
1518
+ }
1519
+ __spreadArray([template], __read(Object.values(inputs)), false);
1520
+ value = nAryOnTree(__spreadArray([template], __read(inputTrees), false), function (_a) {
1521
+ var _b = __read(_a), template = _b[0], values = _b.slice(1);
1522
+ if (!template)
1523
+ return DISCARD;
1524
+ var context = Object.fromEntries(values.map(function (value, index) { return [labels[index], value]; }));
1525
+ return stringtemplate.interpolate(template, context);
1526
+ }, params.fillout || false);
1527
+ return [2 /*return*/, { tree: value }];
1518
1528
  });
1519
1529
  }); },
1520
1530
  };
@@ -2938,6 +2948,7 @@ var duration = {
2938
2948
  label: "Duration",
2939
2949
  description: "Creates a duration",
2940
2950
  inputs: {
2951
+ weeks: { type: "number", default: 0 },
2941
2952
  days: { type: "number", default: 0 },
2942
2953
  hours: { type: "number", default: 0 },
2943
2954
  minutes: { type: "number", default: 0 },
@@ -2951,14 +2962,16 @@ var duration = {
2951
2962
  return __generator(this, function (_a) {
2952
2963
  return [2 /*return*/, {
2953
2964
  duration: nAryOnTree([
2965
+ inputs.weeks || {},
2954
2966
  inputs.days || {},
2955
2967
  inputs.hours || {},
2956
2968
  inputs.minutes || {},
2957
2969
  inputs.seconds || {},
2958
2970
  inputs.milliseconds || {},
2959
2971
  ], function (_a) {
2960
- var _b = __read(_a, 5), _c = _b[0], days = _c === void 0 ? 0 : _c, _d = _b[1], hours = _d === void 0 ? 0 : _d, _e = _b[2], minutes = _e === void 0 ? 0 : _e, _f = _b[3], seconds = _f === void 0 ? 0 : _f, _g = _b[4], milliseconds = _g === void 0 ? 0 : _g;
2961
- var totalMilliseconds = days * 24 * 60 * 60 * 1000 +
2972
+ 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;
2973
+ var totalMilliseconds = weeks * 7 * 24 * 60 * 60 * 1000 +
2974
+ days * 24 * 60 * 60 * 1000 +
2962
2975
  hours * 60 * 60 * 1000 +
2963
2976
  minutes * 60 * 1000 +
2964
2977
  seconds * 1000 +
@@ -7065,18 +7078,19 @@ DynamicOutput.displayName = "DynamicOutputNode";
7065
7078
 
7066
7079
  var NamedInput = function (_a) {
7067
7080
  var _b;
7068
- var _c;
7081
+ var _c, _d;
7069
7082
  var id = _a.id, data = _a.data, selected = _a.selected;
7070
7083
  var engine = useEngine();
7071
7084
  // let fn = useGraphedFunction();
7072
7085
  var prompt = usePrompts().prompt;
7086
+ var fixedInputs = new Set(((_c = data.nodeProps) === null || _c === void 0 ? void 0 : _c.fixed) || []);
7073
7087
  var inputEntries = Object.entries(data.inputDefs || {});
7074
7088
  var outputEntries = Object.entries(data.outputDefs || {});
7075
7089
  var paramEntries = Object.entries(data.paramDefs || {});
7076
- var _d = __read(React.useState({}), 2), result = _d[0], setResult = _d[1];
7077
- var _e = __read(React.useState(null), 2), duration = _e[0], setDuration = _e[1];
7078
- var _f = __read(useInner.useInner(((_c = outputEntries[0]) === null || _c === void 0 ? void 0 : _c[0]) || null, [data.outputDefs]), 2), focus = _f[0], setFocus = _f[1];
7079
- var _g = __read(React.useState(false), 2), showPreview = _g[0], setShowPreview = _g[1];
7090
+ var _e = __read(React.useState({}), 2), result = _e[0], setResult = _e[1];
7091
+ var _f = __read(React.useState(null), 2), duration = _f[0], setDuration = _f[1];
7092
+ var _g = __read(useInner.useInner(((_d = outputEntries[0]) === null || _d === void 0 ? void 0 : _d[0]) || null, [data.outputDefs]), 2), focus = _g[0], setFocus = _g[1];
7093
+ var _h = __read(React.useState(false), 2), showPreview = _h[0], setShowPreview = _h[1];
7080
7094
  var previewValue = focus ? result[focus] : Object.values(result)[0];
7081
7095
  React.useEffect(function () {
7082
7096
  return engine.subscribe("functionResult", function (event) {
@@ -7135,7 +7149,8 @@ var NamedInput = function (_a) {
7135
7149
  }),
7136
7150
  inputEntries.map(function (_a, index) {
7137
7151
  var _b = __read(_a, 2), name = _b[0], varDef = _b[1];
7138
- return (React.createElement(Input, { key: "".concat(name, "_").concat(index), name: name, varDef: varDef, id: id, data: data, onRename: onRename, onDelete: onDelete }));
7152
+ var menu = !fixedInputs.has(name);
7153
+ 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 }));
7139
7154
  }),
7140
7155
  React.createElement("div", { className: styles.Body },
7141
7156
  React.createElement("button", { onClick: function () { return onAdd(); } }, "+")),
@@ -7260,6 +7275,17 @@ function deRefEdgeHandle(handle) {
7260
7275
  function createNode(engine, id, fncall, options) {
7261
7276
  var _a, _b;
7262
7277
  var calledFn = engine.getFunction(fncall.name);
7278
+ var nodeType = "Default";
7279
+ var nodeProps = {};
7280
+ if (calledFn === null || calledFn === void 0 ? void 0 : calledFn.nodeType) {
7281
+ if (typeof calledFn.nodeType === "string") {
7282
+ nodeType = calledFn.nodeType;
7283
+ }
7284
+ else {
7285
+ nodeType = calledFn.nodeType.name;
7286
+ nodeProps = calledFn.nodeType.props || {};
7287
+ }
7288
+ }
7263
7289
  // create a node for each function call
7264
7290
  return {
7265
7291
  id: id,
@@ -7274,10 +7300,11 @@ function createNode(engine, id, fncall, options) {
7274
7300
  outputDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.outputs) || {},
7275
7301
  onChange: ((_a = options.onDataChange) === null || _a === void 0 ? void 0 : _a.call(options, id)) || (function () { }),
7276
7302
  onIOChange: options.onIOChange || (function (fn) { return fn; }),
7303
+ nodeProps: nodeProps,
7277
7304
  },
7278
7305
  position: ((_b = options.positions) === null || _b === void 0 ? void 0 : _b[id]) || { x: 0, y: 0 },
7279
7306
  dragHandle: options.dragHandle,
7280
- type: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.nodeType) || "Default",
7307
+ type: nodeType,
7281
7308
  };
7282
7309
  }
7283
7310
  function createEdge(nodeId, ref) {
@@ -7464,7 +7491,7 @@ var ConnectionLine = (function (_a) {
7464
7491
  */
7465
7492
  var emptyObject = {};
7466
7493
  function FlowInner(_a) {
7467
- 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, onSelect = _a.onSelect, onInit = _a.onInit;
7494
+ 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;
7468
7495
  var _e = __read(React.useState(null), 2), instance = _e[0], setInstance = _e[1];
7469
7496
  var handleInit = function (instance) {
7470
7497
  setInstance(instance);
@@ -7576,6 +7603,15 @@ function FlowInner(_a) {
7576
7603
  onClick === null || onClick === void 0 ? void 0 : onClick(e, position);
7577
7604
  }
7578
7605
  };
7606
+ var handleContextMenu = function (e) {
7607
+ if (instance) {
7608
+ var position = instance.screenToFlowPosition({
7609
+ x: e.clientX,
7610
+ y: e.clientY,
7611
+ });
7612
+ onContextMenu === null || onContextMenu === void 0 ? void 0 : onContextMenu(e, position);
7613
+ }
7614
+ };
7579
7615
  var onNodesChange = React.useCallback(function (changes) {
7580
7616
  changes = changes.filter(function (change) {
7581
7617
  if (change.id === "output" && change.type === "remove")
@@ -7596,7 +7632,7 @@ function FlowInner(_a) {
7596
7632
  return react.applyEdgeChanges(changes, edgesSnapshot);
7597
7633
  });
7598
7634
  }, []);
7599
- return (React.createElement(react.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, fitView: center || fitView, fitViewOptions: {
7635
+ return (React.createElement(react.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: {
7600
7636
  minZoom: fitView ? undefined : 1,
7601
7637
  maxZoom: fitView ? undefined : 1,
7602
7638
  },