@rkmodules/rules 0.0.176 → 0.0.178

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.
@@ -98,6 +98,7 @@
98
98
  top: 100%;
99
99
  right: 0;
100
100
  background-color: var(--bg);
101
+ z-index: 9999;
101
102
  }
102
103
  .MenuItem_UWLzD {
103
104
  padding: 4px 8px;
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
  /******************************************************************************
@@ -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) {
@@ -7062,6 +7064,19 @@ function Menu(_a) {
7062
7064
  var handleClose = function () {
7063
7065
  setOpen(false);
7064
7066
  };
7067
+ React.useEffect(function () {
7068
+ if (!open)
7069
+ return;
7070
+ var handleClickOutside = function (event) {
7071
+ if (!event.target.closest(".".concat(styles$2.MenuCanvas))) {
7072
+ setOpen(false);
7073
+ }
7074
+ };
7075
+ document.addEventListener("click", handleClickOutside);
7076
+ return function () {
7077
+ document.removeEventListener("click", handleClickOutside);
7078
+ };
7079
+ }, [open]);
7065
7080
  return (React.createElement("div", { className: styles$2.Menu },
7066
7081
  React.createElement("div", { onClick: handleOpen }, handle),
7067
7082
  open && (React.createElement("div", { className: styles$2.MenuCanvas, onClick: handleClose }, children))));
@@ -8007,7 +8022,7 @@ function addOutputToNode(nodes, ref, targetId) {
8007
8022
  * flow state stores nodes and edges for the flow graph these can be updated when the function changes
8008
8023
  * using setFn
8009
8024
  */
8010
- var useFlowState = zustand.create(function (set, get) { return ({
8025
+ var createFlowStore = function () { return vanilla.createStore(function (set, get) { return ({
8011
8026
  engine: null,
8012
8027
  fn: null,
8013
8028
  options: {},
@@ -8123,25 +8138,48 @@ var useFlowState = zustand.create(function (set, get) { return ({
8123
8138
  });
8124
8139
  // console.log("final graph", nodes, edges);
8125
8140
  // update the function, nodes and edges
8126
- set({ fn: fn, nodes: nodes, edges: edges });
8141
+ set({ fn: fn, nodes: nodes, edges: edges, options: options });
8142
+ },
8143
+ refreshFunctions: function (name) {
8144
+ var _a = get(), fn = _a.fn, engine = _a.engine, options = _a.options, nodes = _a.nodes;
8145
+ if (!fn || !engine)
8146
+ return;
8147
+ var matching = Object.entries(fn.body || {}).filter(function (_a) {
8148
+ var _b = __read(_a, 2), id = _b[0], call = _b[1];
8149
+ return nodes[id] && (name === undefined || call.name === name);
8150
+ });
8151
+ if (!matching.length)
8152
+ return;
8153
+ var nextNodes = __assign({}, nodes);
8154
+ matching.forEach(function (_a) {
8155
+ var _b = __read(_a, 2), id = _b[0], call = _b[1];
8156
+ var node = nodes[id];
8157
+ var refreshed = createNode(engine, id, call, options);
8158
+ nextNodes[id] = __assign(__assign({}, node), { type: refreshed.type, dragHandle: refreshed.dragHandle, data: __assign(__assign({}, refreshed.data), { outputs: node.data.outputs }) });
8159
+ });
8160
+ set({ nodes: nextNodes });
8127
8161
  },
8128
8162
  init: function (fn, engine, options) {
8129
8163
  // console.log("initing");
8130
8164
  set({ engine: engine, options: options });
8131
8165
  get().setFn(fn, options);
8166
+ // Reconcile builds that happened before the effect subscribed.
8167
+ get().refreshFunctions();
8132
8168
  },
8133
- }); });
8134
- /**
8135
- * creates a flow state and provides handlers to update nodes and edges
8136
- */
8169
+ }); }); };
8170
+
8171
+ /** Creates isolated editor state and observes definitions used by its nodes. */
8137
8172
  function useFlow(fn, engine, options) {
8138
- var state = useFlowState();
8173
+ var store = React.useMemo(function () { return createFlowStore(); }, [engine]);
8174
+ var state = zustand.useStore(store);
8139
8175
  React.useEffect(function () {
8140
- state.init(fn, engine, options);
8141
- }, [engine]);
8142
- React.useEffect(function () {
8143
- state.setFn(fn, options);
8144
- }, [fn, options]);
8176
+ var unsubscribe = engine.subscribe("functionBuilt", function (_a) {
8177
+ var name = _a.name;
8178
+ store.getState().refreshFunctions(name);
8179
+ });
8180
+ store.getState().init(fn, engine, options);
8181
+ return unsubscribe;
8182
+ }, [store, engine, fn, options]);
8145
8183
  return React.useMemo(function () { return ({
8146
8184
  nodes: Object.values(state.nodes),
8147
8185
  edges: state.edges,