@rkmodules/rules 0.0.175 → 0.0.177

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 CHANGED
@@ -11,6 +11,7 @@ var rcin = require('rc-input-number');
11
11
  var useLongPress = require('use-long-press');
12
12
  var zustand = require('zustand');
13
13
  var middleware = require('zustand/middleware');
14
+ var vanilla = require('zustand/vanilla');
14
15
  var jsxRuntime = require('react/jsx-runtime');
15
16
 
16
17
  /******************************************************************************
@@ -2553,7 +2554,7 @@ var combineTrees = {
2553
2554
  return [[values]];
2554
2555
  }, true);
2555
2556
  result = mapTreeBranch(graftTree(lists), function (items) {
2556
- return items.flat();
2557
+ return items.flat(Infinity);
2557
2558
  });
2558
2559
  return [2 /*return*/, { result: result }];
2559
2560
  });
@@ -3869,6 +3870,7 @@ var Engine = /** @class */ (function () {
3869
3870
  // register the primitive
3870
3871
  this.fnIndex[primitive.name] = primitive;
3871
3872
  this.graphDefinitions.set(primitive, node);
3873
+ this.fireEvent("functionBuilt", { name: primitive.name, fn: primitive });
3872
3874
  return primitive;
3873
3875
  };
3874
3876
  Engine.prototype.mount = function (node, inputs, options) {
@@ -8007,7 +8009,7 @@ function addOutputToNode(nodes, ref, targetId) {
8007
8009
  * flow state stores nodes and edges for the flow graph these can be updated when the function changes
8008
8010
  * using setFn
8009
8011
  */
8010
- var useFlowState = zustand.create(function (set, get) { return ({
8012
+ var createFlowStore = function () { return vanilla.createStore(function (set, get) { return ({
8011
8013
  engine: null,
8012
8014
  fn: null,
8013
8015
  options: {},
@@ -8123,25 +8125,48 @@ var useFlowState = zustand.create(function (set, get) { return ({
8123
8125
  });
8124
8126
  // console.log("final graph", nodes, edges);
8125
8127
  // update the function, nodes and edges
8126
- set({ fn: fn, nodes: nodes, edges: edges });
8128
+ set({ fn: fn, nodes: nodes, edges: edges, options: options });
8129
+ },
8130
+ refreshFunctions: function (name) {
8131
+ var _a = get(), fn = _a.fn, engine = _a.engine, options = _a.options, nodes = _a.nodes;
8132
+ if (!fn || !engine)
8133
+ return;
8134
+ var matching = Object.entries(fn.body || {}).filter(function (_a) {
8135
+ var _b = __read(_a, 2), id = _b[0], call = _b[1];
8136
+ return nodes[id] && (name === undefined || call.name === name);
8137
+ });
8138
+ if (!matching.length)
8139
+ return;
8140
+ var nextNodes = __assign({}, nodes);
8141
+ matching.forEach(function (_a) {
8142
+ var _b = __read(_a, 2), id = _b[0], call = _b[1];
8143
+ var node = nodes[id];
8144
+ var refreshed = createNode(engine, id, call, options);
8145
+ nextNodes[id] = __assign(__assign({}, node), { type: refreshed.type, dragHandle: refreshed.dragHandle, data: __assign(__assign({}, refreshed.data), { outputs: node.data.outputs }) });
8146
+ });
8147
+ set({ nodes: nextNodes });
8127
8148
  },
8128
8149
  init: function (fn, engine, options) {
8129
8150
  // console.log("initing");
8130
8151
  set({ engine: engine, options: options });
8131
8152
  get().setFn(fn, options);
8153
+ // Reconcile builds that happened before the effect subscribed.
8154
+ get().refreshFunctions();
8132
8155
  },
8133
- }); });
8134
- /**
8135
- * creates a flow state and provides handlers to update nodes and edges
8136
- */
8156
+ }); }); };
8157
+
8158
+ /** Creates isolated editor state and observes definitions used by its nodes. */
8137
8159
  function useFlow(fn, engine, options) {
8138
- var state = useFlowState();
8160
+ var store = React.useMemo(function () { return createFlowStore(); }, [engine]);
8161
+ var state = zustand.useStore(store);
8139
8162
  React.useEffect(function () {
8140
- state.init(fn, engine, options);
8141
- }, [engine]);
8142
- React.useEffect(function () {
8143
- state.setFn(fn, options);
8144
- }, [fn, options]);
8163
+ var unsubscribe = engine.subscribe("functionBuilt", function (_a) {
8164
+ var name = _a.name;
8165
+ store.getState().refreshFunctions(name);
8166
+ });
8167
+ store.getState().init(fn, engine, options);
8168
+ return unsubscribe;
8169
+ }, [store, engine, fn, options]);
8145
8170
  return React.useMemo(function () { return ({
8146
8171
  nodes: Object.values(state.nodes),
8147
8172
  edges: state.edges,