@rkmodules/rules 0.0.105 → 0.0.107

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.esm.js CHANGED
@@ -2048,6 +2048,14 @@ function topSort(fn) {
2048
2048
  var orderedBody = Object.fromEntries(ordered.map(function (id) { return [id, fn.body[id]]; }));
2049
2049
  return __assign(__assign({}, fn), { body: orderedBody });
2050
2050
  }
2051
+ function getDefault(varDef, inputs) {
2052
+ if (inputs === void 0) { inputs = {}; }
2053
+ var normDef = normalizeVarDef(varDef);
2054
+ if (typeof normDef.default === "function") {
2055
+ return normDef.default(inputs);
2056
+ }
2057
+ return normDef.default;
2058
+ }
2051
2059
  var Engine = /** @class */ (function () {
2052
2060
  function Engine(morePrimitives, env) {
2053
2061
  if (morePrimitives === void 0) { morePrimitives = {}; }
@@ -2078,8 +2086,8 @@ var Engine = /** @class */ (function () {
2078
2086
  Object.entries(node.inputs || {}).forEach(function (_a) {
2079
2087
  var _b = __read(_a, 2), name = _b[0], def = _b[1];
2080
2088
  var normDef = normalizeVarDef(def);
2081
- if (!inputs[name] && normDef.default !== undefined) {
2082
- inputs[name] = normDef.default;
2089
+ if (inputs[name] === undefined && normDef.default !== undefined) {
2090
+ inputs[name] = getDefault(normDef, inputs);
2083
2091
  }
2084
2092
  });
2085
2093
  context = {
@@ -2375,7 +2383,7 @@ var Engine = /** @class */ (function () {
2375
2383
  if ((_a = fn.inputs) === null || _a === void 0 ? void 0 : _a[toField]) {
2376
2384
  var normDef = normalizeVarDef(fn.inputs[toField]);
2377
2385
  if (normDef.default !== undefined) {
2378
- to.inputs[toField] = normDef.default;
2386
+ to.inputs[toField] = getDefault(normDef, to.inputs);
2379
2387
  }
2380
2388
  }
2381
2389
  }
@@ -2406,7 +2414,7 @@ var Engine = /** @class */ (function () {
2406
2414
  var _b = __read(_a, 2), key = _b[0], def = _b[1];
2407
2415
  var normDef = normalizeVarDef(def);
2408
2416
  if (normDef.default !== undefined) {
2409
- inputs[key] = normDef.default;
2417
+ inputs[key] = getDefault(normDef, inputs);
2410
2418
  }
2411
2419
  });
2412
2420
  // get params defaults
@@ -2415,7 +2423,7 @@ var Engine = /** @class */ (function () {
2415
2423
  var _b = __read(_a, 2), key = _b[0], def = _b[1];
2416
2424
  var normDef = normalizeVarDef(def);
2417
2425
  if (normDef.default !== undefined) {
2418
- params[key] = normDef.default;
2426
+ params[key] = getDefault(normDef, params);
2419
2427
  }
2420
2428
  });
2421
2429
  var newCall = {
@@ -6163,10 +6171,14 @@ var ConnectionLine = (function (_a) {
6163
6171
  */
6164
6172
  var emptyObject = {};
6165
6173
  function FlowInner(_a) {
6166
- 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, onChange = _a.onChange, onClick = _a.onClick, onSelect = _a.onSelect;
6174
+ 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, onChange = _a.onChange, onClick = _a.onClick, onSelect = _a.onSelect, onInit = _a.onInit;
6167
6175
  var _d = __read(React.useState(null), 2), instance = _d[0], setInstance = _d[1];
6176
+ var handleInit = function (instance) {
6177
+ setInstance(instance);
6178
+ onInit === null || onInit === void 0 ? void 0 : onInit(instance);
6179
+ };
6168
6180
  var updatePosition = useUpdatePositions(fn);
6169
- var _e = __read(usePositions(fn), 1), positions = _e[0];
6181
+ var _e = __read(usePositions(fn), 2), positions = _e[0], setPositions = _e[1];
6170
6182
  var options = React.useMemo(function () {
6171
6183
  var handleDataChange = function (id) { return function (newData) {
6172
6184
  onChange === null || onChange === void 0 ? void 0 : onChange(function (fn) {
@@ -6193,6 +6205,9 @@ function FlowInner(_a) {
6193
6205
  onIOChange: handleIOChange,
6194
6206
  };
6195
6207
  }, [fn, onChange, defaultPositions]);
6208
+ React.useEffect(function () {
6209
+ setPositions(__assign(__assign({}, positions), defaultPositions));
6210
+ }, [defaultPositions]);
6196
6211
  var _f = useFlow(fn, engine, options), nodes = _f.nodes, edges = _f.edges, setNodes = _f.setNodes, setEdges = _f.setEdges;
6197
6212
  // node selection handler
6198
6213
  var handleSelect = React.useCallback(function (_a) {
@@ -6290,7 +6305,7 @@ function FlowInner(_a) {
6290
6305
  return applyEdgeChanges(changes, edgesSnapshot);
6291
6306
  });
6292
6307
  }, []);
6293
- return (React.createElement(ReactFlow, { ref: drop, nodes: nodes, edges: edges, nodeTypes: nodeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onNodesDelete: onNodesDelete, onEdgesDelete: onEdgesDelete, onNodeDragStop: function (e, n) { return updatePosition(n.id, n.position); }, onConnect: onConnect, onInit: setInstance, onPaneClick: handleClick, fitView: center || fitView, fitViewOptions: {
6308
+ return (React.createElement(ReactFlow, { ref: drop, nodes: nodes, edges: edges, nodeTypes: nodeTypes, 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: {
6294
6309
  minZoom: fitView ? undefined : 1,
6295
6310
  maxZoom: fitView ? undefined : 1,
6296
6311
  },