@receptron/graphai_vue_cytoscape 0.0.4 → 0.0.6

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,7 +1,10 @@
1
1
  import { Ref, ComputedRef } from "vue";
2
2
  import { GraphData, NodeState } from "graphai";
3
+ import { DataSource } from "graphai/lib/type";
4
+ export declare const inputs2dataSources: (inputs: any) => string[];
5
+ export declare const dataSourceNodeIds: (sources: DataSource[]) => string[];
3
6
  export declare const useCytoscape: (selectedGraph: ComputedRef<GraphData> | Ref<GraphData>) => {
4
- cytoscapeRef: Ref<any>;
7
+ cytoscapeRef: Ref<any, any>;
5
8
  updateCytoscape: (nodeId: string, state: NodeState) => Promise<void>;
6
9
  resetCytoscape: () => void;
7
10
  };
package/lib/cytoscape.js CHANGED
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -40,7 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
40
40
  };
41
41
  var _a;
42
42
  Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.useCytoscape = void 0;
43
+ exports.useCytoscape = exports.dataSourceNodeIds = exports.inputs2dataSources = void 0;
44
44
  var vue_1 = require("vue");
45
45
  var graphai_1 = require("graphai");
46
46
  var cytoscape_1 = __importDefault(require("cytoscape"));
@@ -114,11 +114,34 @@ var colorMap = (_a = {},
114
114
  _a);
115
115
  var parseInput = function (input) {
116
116
  // WARNING: Assuming the first character is always ":"
117
+ console.log(input);
117
118
  var ids = input.slice(1).split(".");
118
119
  var source = ids.shift() || "";
119
120
  var label = ids.length ? ids.join(".") : undefined;
120
121
  return { source: source, label: label };
121
122
  };
123
+ var inputs2dataSources = function (inputs) {
124
+ if (Array.isArray(inputs)) {
125
+ return inputs.map(function (inp) { return (0, exports.inputs2dataSources)(inp); }).flat();
126
+ }
127
+ if ((0, graphai_1.isObject)(inputs)) {
128
+ return Object.values(inputs)
129
+ .map(function (input) { return (0, exports.inputs2dataSources)(input); })
130
+ .flat();
131
+ }
132
+ if (typeof inputs === "string") {
133
+ var templateMatch = Array.from(inputs.matchAll(/\${(:[^}]+)}/g)).map(function (m) { return m[1]; });
134
+ if (templateMatch.length > 0) {
135
+ return (0, exports.inputs2dataSources)(templateMatch);
136
+ }
137
+ }
138
+ return inputs;
139
+ };
140
+ exports.inputs2dataSources = inputs2dataSources;
141
+ var dataSourceNodeIds = function (sources) {
142
+ return sources.filter(function (source) { return source.nodeId; }).map(function (source) { return source.nodeId; });
143
+ };
144
+ exports.dataSourceNodeIds = dataSourceNodeIds;
122
145
  var cytoscapeFromGraph = function (graph_data) {
123
146
  var elements = Object.keys(graph_data.nodes || {}).reduce(function (tmp, nodeId) {
124
147
  var node = graph_data.nodes[nodeId];
@@ -134,8 +157,7 @@ var cytoscapeFromGraph = function (graph_data) {
134
157
  tmp.map[nodeId] = cyNode;
135
158
  if ("inputs" in node) {
136
159
  // computed node
137
- var inputs = Array.isArray(node.inputs) ? node.inputs : Object.values(node.inputs || {});
138
- (inputs !== null && inputs !== void 0 ? inputs : []).forEach(function (input) {
160
+ (0, exports.inputs2dataSources)(node.inputs).forEach(function (input) {
139
161
  var _a = parseInput(input), source = _a.source, label = _a.label;
140
162
  tmp.edges.push({
141
163
  data: {
@@ -173,7 +195,7 @@ var useCytoscape = function (selectedGraph) {
173
195
  return __generator(this, function (_d) {
174
196
  switch (_d.label) {
175
197
  case 0:
176
- if (!(state === graphai_1.NodeState.Completed || state === graphai_1.NodeState.Waiting)) return [3 /*break*/, 2];
198
+ if (![graphai_1.NodeState.Completed, graphai_1.NodeState.Waiting].includes(state)) return [3 /*break*/, 2];
177
199
  return [4 /*yield*/, (0, graphai_1.sleep)(100)];
178
200
  case 1:
179
201
  _d.sent();
@@ -187,11 +209,9 @@ var useCytoscape = function (selectedGraph) {
187
209
  // computed node
188
210
  elements.map[nodeId].data.color = colorPriority;
189
211
  }
190
- else {
191
- if ("value" in nodeData && state === graphai_1.NodeState.Waiting) {
192
- // static node
193
- elements.map[nodeId].data.color = colorStatic;
194
- }
212
+ else if ("value" in nodeData && state === graphai_1.NodeState.Waiting) {
213
+ // static node
214
+ elements.map[nodeId].data.color = colorStatic;
195
215
  }
196
216
  cytoscapeData.value = { elements: elements };
197
217
  if (!(state === graphai_1.NodeState.Injected)) return [3 /*break*/, 4];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@receptron/graphai_vue_cytoscape",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "main": "lib/cytoscape.js",
5
5
  "files": [
6
6
  "./lib"
@@ -12,7 +12,8 @@
12
12
  "preview": "vite preview",
13
13
  "build-only": "vite build",
14
14
  "type-check": "vue-tsc --build --force",
15
- "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
15
+ "test": "echo nothing",
16
+ "eslint": "eslint src",
16
17
  "format": "prettier --write src/"
17
18
  },
18
19
  "repository": {
@@ -26,31 +27,22 @@
26
27
  },
27
28
  "homepage": "https://github.com/receptron/graphai_utils/tree/main/packages/vue-cytoscape#readme",
28
29
  "dependencies": {
29
- "cytoscape": "^3.29.2",
30
+ "cytoscape": "^3.30.3",
30
31
  "cytoscape-klay": "^3.1.4"
31
32
  },
32
33
  "devDependencies": {
33
- "graphai": "^0.5.1",
34
- "vue": "^3.4.21",
35
- "@graphai/vanilla": "^0.0.3",
36
- "@babel/types": "^7.24.7",
34
+ "@babel/types": "^7.26.0",
37
35
  "@rushstack/eslint-patch": "^1.8.0",
38
36
  "@tsconfig/node20": "^20.1.4",
39
- "@types/node": "^20.12.5",
40
- "@vitejs/plugin-vue": "^5.0.4",
41
- "@vue/eslint-config-prettier": "^9.0.0",
42
- "@vue/eslint-config-typescript": "^13.0.0",
37
+ "@vitejs/plugin-vue": "^5.1.4",
43
38
  "@vue/tsconfig": "^0.5.1",
44
39
  "autoprefixer": "^10.4.19",
45
- "eslint": "^8.57.0",
46
- "eslint-plugin-vue": "^9.23.0",
47
- "npm-run-all2": "^6.1.2",
48
- "postcss": "^8.4.38",
49
- "prettier": "^3.2.5",
50
- "tailwindcss": "^3.4.4",
51
- "typescript": "~5.4.0",
52
- "vite": "^5.2.13",
53
- "vue-tsc": "^2.0.11"
40
+ "npm-run-all2": "^7.0.1",
41
+ "postcss": "^8.4.47",
42
+ "tailwindcss": "^3.4.13",
43
+ "vite": "^5.4.10",
44
+ "vue": "^3.5.12",
45
+ "vue-tsc": "^2.1.10"
54
46
  },
55
47
  "types": "./lib/cytoscape.d.ts",
56
48
  "directories": {