@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.
@@ -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: "DynamicInput",
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 trees;
1503
- var _b = _a.template, template = _b === void 0 ? {} : _b, inputs = __rest(_a, ["template"]);
1504
- return __generator(this, function (_c) {
1505
- trees = __spreadArray([template], __read(Object.values(inputs)), false);
1506
- return [2 /*return*/, {
1507
- tree: nAryOnTree(trees, function (_a) {
1508
- var _b = __read(_a), template = _b[0], values = _b.slice(1);
1509
- return template.replace(/{D(\d+)}/g, function (match, number) {
1510
- return typeof values[number - 1] !== "undefined"
1511
- ? values[number - 1]
1512
- : match;
1513
- });
1514
- }, true),
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, 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;
2959
- var totalMilliseconds = days * 24 * 60 * 60 * 1000 +
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 _d = __read(React.useState({}), 2), result = _d[0], setResult = _d[1];
7075
- var _e = __read(React.useState(null), 2), duration = _e[0], setDuration = _e[1];
7076
- var _f = __read(useInner(((_c = outputEntries[0]) === null || _c === void 0 ? void 0 : _c[0]) || null, [data.outputDefs]), 2), focus = _f[0], setFocus = _f[1];
7077
- var _g = __read(React.useState(false), 2), showPreview = _g[0], setShowPreview = _g[1];
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
- return (React.createElement(Input, { key: "".concat(name, "_").concat(index), name: name, varDef: varDef, id: id, data: data, onRename: onRename, onDelete: onDelete }));
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: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.nodeType) || "Default",
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 === null || onClick === void 0 ? void 0 : onClick(e, position);
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
- onContextMenu === null || onContextMenu === void 0 ? void 0 : onContextMenu(e, position);
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
  },