@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;
@@ -7,8 +7,9 @@ import classNames from 'classnames';
7
7
  import { useInner } from '@rkmodules/use-inner';
8
8
  import rcin from 'rc-input-number';
9
9
  import { useLongPress } from 'use-long-press';
10
- import { create as create$1 } from 'zustand';
10
+ import { create as create$1, useStore } from 'zustand';
11
11
  import { persist } from 'zustand/middleware';
12
+ import { createStore as createStore$1 } from 'zustand/vanilla';
12
13
  import { jsx } from 'react/jsx-runtime';
13
14
 
14
15
  /******************************************************************************
@@ -3867,6 +3868,7 @@ var Engine = /** @class */ (function () {
3867
3868
  // register the primitive
3868
3869
  this.fnIndex[primitive.name] = primitive;
3869
3870
  this.graphDefinitions.set(primitive, node);
3871
+ this.fireEvent("functionBuilt", { name: primitive.name, fn: primitive });
3870
3872
  return primitive;
3871
3873
  };
3872
3874
  Engine.prototype.mount = function (node, inputs, options) {
@@ -7060,6 +7062,19 @@ function Menu(_a) {
7060
7062
  var handleClose = function () {
7061
7063
  setOpen(false);
7062
7064
  };
7065
+ React.useEffect(function () {
7066
+ if (!open)
7067
+ return;
7068
+ var handleClickOutside = function (event) {
7069
+ if (!event.target.closest(".".concat(styles$2.MenuCanvas))) {
7070
+ setOpen(false);
7071
+ }
7072
+ };
7073
+ document.addEventListener("click", handleClickOutside);
7074
+ return function () {
7075
+ document.removeEventListener("click", handleClickOutside);
7076
+ };
7077
+ }, [open]);
7063
7078
  return (React.createElement("div", { className: styles$2.Menu },
7064
7079
  React.createElement("div", { onClick: handleOpen }, handle),
7065
7080
  open && (React.createElement("div", { className: styles$2.MenuCanvas, onClick: handleClose }, children))));
@@ -8005,7 +8020,7 @@ function addOutputToNode(nodes, ref, targetId) {
8005
8020
  * flow state stores nodes and edges for the flow graph these can be updated when the function changes
8006
8021
  * using setFn
8007
8022
  */
8008
- var useFlowState = create$1(function (set, get) { return ({
8023
+ var createFlowStore = function () { return createStore$1(function (set, get) { return ({
8009
8024
  engine: null,
8010
8025
  fn: null,
8011
8026
  options: {},
@@ -8121,25 +8136,48 @@ var useFlowState = create$1(function (set, get) { return ({
8121
8136
  });
8122
8137
  // console.log("final graph", nodes, edges);
8123
8138
  // update the function, nodes and edges
8124
- set({ fn: fn, nodes: nodes, edges: edges });
8139
+ set({ fn: fn, nodes: nodes, edges: edges, options: options });
8140
+ },
8141
+ refreshFunctions: function (name) {
8142
+ var _a = get(), fn = _a.fn, engine = _a.engine, options = _a.options, nodes = _a.nodes;
8143
+ if (!fn || !engine)
8144
+ return;
8145
+ var matching = Object.entries(fn.body || {}).filter(function (_a) {
8146
+ var _b = __read(_a, 2), id = _b[0], call = _b[1];
8147
+ return nodes[id] && (name === undefined || call.name === name);
8148
+ });
8149
+ if (!matching.length)
8150
+ return;
8151
+ var nextNodes = __assign({}, nodes);
8152
+ matching.forEach(function (_a) {
8153
+ var _b = __read(_a, 2), id = _b[0], call = _b[1];
8154
+ var node = nodes[id];
8155
+ var refreshed = createNode(engine, id, call, options);
8156
+ nextNodes[id] = __assign(__assign({}, node), { type: refreshed.type, dragHandle: refreshed.dragHandle, data: __assign(__assign({}, refreshed.data), { outputs: node.data.outputs }) });
8157
+ });
8158
+ set({ nodes: nextNodes });
8125
8159
  },
8126
8160
  init: function (fn, engine, options) {
8127
8161
  // console.log("initing");
8128
8162
  set({ engine: engine, options: options });
8129
8163
  get().setFn(fn, options);
8164
+ // Reconcile builds that happened before the effect subscribed.
8165
+ get().refreshFunctions();
8130
8166
  },
8131
- }); });
8132
- /**
8133
- * creates a flow state and provides handlers to update nodes and edges
8134
- */
8167
+ }); }); };
8168
+
8169
+ /** Creates isolated editor state and observes definitions used by its nodes. */
8135
8170
  function useFlow(fn, engine, options) {
8136
- var state = useFlowState();
8171
+ var store = React.useMemo(function () { return createFlowStore(); }, [engine]);
8172
+ var state = useStore(store);
8137
8173
  React.useEffect(function () {
8138
- state.init(fn, engine, options);
8139
- }, [engine]);
8140
- React.useEffect(function () {
8141
- state.setFn(fn, options);
8142
- }, [fn, options]);
8174
+ var unsubscribe = engine.subscribe("functionBuilt", function (_a) {
8175
+ var name = _a.name;
8176
+ store.getState().refreshFunctions(name);
8177
+ });
8178
+ store.getState().init(fn, engine, options);
8179
+ return unsubscribe;
8180
+ }, [store, engine, fn, options]);
8143
8181
  return React.useMemo(function () { return ({
8144
8182
  nodes: Object.values(state.nodes),
8145
8183
  edges: state.edges,