@linkurious/ogma-linkurious-parser 3.1.11 → 4.0.0

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.
@@ -8,94 +8,51 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
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;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
11
  Object.defineProperty(exports, "__esModule", { value: true });
39
- var __1 = require("../..");
40
- var tools_1 = require("../../tools/tools");
41
- var CaptionsViz = /** @class */ (function () {
42
- function CaptionsViz(ogma, _nodeMaxTextLength, _edgeMaxTextLength) {
12
+ const __1 = require("../..");
13
+ const tools_1 = require("../../tools/tools");
14
+ class CaptionsViz {
15
+ constructor(ogma, _nodeMaxTextLength, _edgeMaxTextLength) {
43
16
  this._nodeMaxTextLength = _nodeMaxTextLength;
44
17
  this._edgeMaxTextLength = _edgeMaxTextLength;
45
18
  this._captionSchema = { node: {}, edge: {} };
46
19
  this._graphSchema = { node: [], edge: [] };
47
20
  this._ogma = ogma;
48
21
  }
49
- Object.defineProperty(CaptionsViz.prototype, "graphSchema", {
50
- set: function (graphSchema) {
51
- this._graphSchema = graphSchema;
52
- },
53
- enumerable: true,
54
- configurable: true
55
- });
22
+ set graphSchema(graphSchema) {
23
+ this._graphSchema = graphSchema;
24
+ }
56
25
  /**
57
26
  * Refresh the schema
58
27
  */
59
- CaptionsViz.prototype.refreshSchema = function (schema) {
28
+ refreshSchema(schema) {
60
29
  this._captionSchema = schema;
61
- };
30
+ }
62
31
  /**
63
32
  * Refresh visualization captions rules
64
33
  */
65
- CaptionsViz.prototype.initVizCaptions = function (schema) {
66
- return __awaiter(this, void 0, void 0, function () {
67
- return __generator(this, function (_a) {
68
- switch (_a.label) {
69
- case 0:
70
- if (!this._ogma.LKCaptions.nodesCaptionsRule) return [3 /*break*/, 2];
71
- this._ogma.LKCaptions.refreshSchema(schema);
72
- return [4 /*yield*/, this._ogma.LKCaptions.updateNodeCaptions()];
73
- case 1:
74
- _a.sent();
75
- return [3 /*break*/, 3];
76
- case 2:
77
- this._ogma.LKCaptions.updateNodeCaptions(schema.node);
78
- _a.label = 3;
79
- case 3:
80
- if (!this._ogma.LKCaptions.edgesCaptionsRule) return [3 /*break*/, 5];
81
- this._ogma.LKCaptions.refreshSchema(schema);
82
- return [4 /*yield*/, this._ogma.LKCaptions.updateEdgeCaptions()];
83
- case 4:
84
- _a.sent();
85
- return [3 /*break*/, 6];
86
- case 5:
87
- this._ogma.LKCaptions.updateEdgeCaptions(schema.edge);
88
- _a.label = 6;
89
- case 6: return [2 /*return*/];
90
- }
91
- });
34
+ initVizCaptions(schema) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ if (this._ogma.LKCaptions.nodesCaptionsRule) {
37
+ this._ogma.LKCaptions.refreshSchema(schema);
38
+ yield this._ogma.LKCaptions.updateNodeCaptions();
39
+ }
40
+ else {
41
+ this._ogma.LKCaptions.updateNodeCaptions(schema.node);
42
+ }
43
+ if (this._ogma.LKCaptions.edgesCaptionsRule) {
44
+ this._ogma.LKCaptions.refreshSchema(schema);
45
+ yield this._ogma.LKCaptions.updateEdgeCaptions();
46
+ }
47
+ else {
48
+ this._ogma.LKCaptions.updateEdgeCaptions(schema.edge);
49
+ }
92
50
  });
93
- };
51
+ }
94
52
  /**
95
53
  * Create or update nodeCaptionRule
96
54
  */
97
- CaptionsViz.prototype.updateNodeCaptions = function (schema) {
98
- var _this = this;
55
+ updateNodeCaptions(schema) {
99
56
  if (schema) {
100
57
  this._captionSchema.node = schema;
101
58
  }
@@ -103,13 +60,13 @@ var CaptionsViz = /** @class */ (function () {
103
60
  this.nodesCaptionsRule = this._ogma.styles.addRule({
104
61
  nodeAttributes: {
105
62
  text: {
106
- content: function (node) {
63
+ content: (node) => {
107
64
  if (node === undefined) {
108
- return "";
65
+ return ``;
109
66
  }
110
- var value = __1.Captions.getText(node.getData(), _this._captionSchema.node, _this._graphSchema.node);
111
- return tools_1.Tools.isDefined(_this._nodeMaxTextLength)
112
- ? tools_1.Tools.truncate(value, 'middle', _this._nodeMaxTextLength)
67
+ const value = __1.Captions.getText(node.getData(), this._captionSchema.node, this._graphSchema.node);
68
+ return tools_1.Tools.isDefined(this._nodeMaxTextLength)
69
+ ? tools_1.Tools.truncate(value, 'middle', this._nodeMaxTextLength)
113
70
  : value;
114
71
  }
115
72
  }
@@ -120,12 +77,11 @@ var CaptionsViz = /** @class */ (function () {
120
77
  else {
121
78
  return this.nodesCaptionsRule.refresh();
122
79
  }
123
- };
80
+ }
124
81
  /**
125
82
  * Create or update edgeCaptionRule
126
83
  */
127
- CaptionsViz.prototype.updateEdgeCaptions = function (schema) {
128
- var _this = this;
84
+ updateEdgeCaptions(schema) {
129
85
  if (schema) {
130
86
  this._captionSchema.edge = schema;
131
87
  }
@@ -133,18 +89,18 @@ var CaptionsViz = /** @class */ (function () {
133
89
  this.edgesCaptionsRule = this._ogma.styles.addRule({
134
90
  edgeAttributes: {
135
91
  text: {
136
- content: function (edge) {
92
+ content: (edge) => {
137
93
  if (edge === undefined || edge.getData() === undefined) {
138
- return "";
94
+ return ``;
139
95
  }
140
- var value = __1.Captions.getText(edge.getData(), _this._captionSchema.edge, _this._graphSchema.edge);
141
- return tools_1.Tools.isDefined(_this._edgeMaxTextLength)
142
- ? tools_1.Tools.truncate(value, 'middle', _this._edgeMaxTextLength)
96
+ const value = __1.Captions.getText(edge.getData(), this._captionSchema.edge, this._graphSchema.edge);
97
+ return tools_1.Tools.isDefined(this._edgeMaxTextLength)
98
+ ? tools_1.Tools.truncate(value, 'middle', this._edgeMaxTextLength)
143
99
  : value;
144
100
  }
145
101
  }
146
102
  },
147
- edgeSelector: function (edge) { return !edge.isVirtual() && edge.isVisible(); },
103
+ edgeSelector: (edge) => !edge.isVirtual() && edge.isVisible(),
148
104
  // ogma will trigger the rendering if data change or the shape change (to trigger the rendering when edges are grouped)
149
105
  edgeDependencies: { self: { data: true, attributes: ['shape.style'] } }
150
106
  });
@@ -152,8 +108,7 @@ var CaptionsViz = /** @class */ (function () {
152
108
  else {
153
109
  return this.edgesCaptionsRule.refresh();
154
110
  }
155
- };
156
- return CaptionsViz;
157
- }());
111
+ }
112
+ }
158
113
  exports.CaptionsViz = CaptionsViz;
159
114
  //# sourceMappingURL=captions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"captions.js","sourceRoot":"","sources":["../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chemaTypeWithAccess, ItemFieldsCaptions} from '@linkurious/rest-client';\n\nimport {Captions, LKOgma} from '../..';\nimport {Tools} from '../../tools/tools';\n\nexport interface CaptionState {\n node: ItemFieldsCaptions;\n edge: ItemFieldsCaptions;\n}\n\nexport class CaptionsViz {\n public nodesCaptionsRule!: Ogma.StyleRule;\n public edgesCaptionsRule!: Ogma.StyleRule;\n private _ogma: LKOgma;\n private _captionSchema: CaptionState = {node: {}, edge: {}};\n private _graphSchema: {\n node: Array<GraphSchemaTypeWithAccess>;\n edge: Array<GraphSchemaTypeWithAccess>;\n } = {node: [], edge: []};\n\n constructor(\n ogma: LKOgma,\n private _nodeMaxTextLength: number | undefined,\n private _edgeMaxTextLength: number | undefined\n ) {\n this._ogma = ogma;\n }\n\n public set graphSchema(graphSchema: {\n node: Array<GraphSchemaTypeWithAccess>;\n edge: Array<GraphSchemaTypeWithAccess>;\n }) {\n this._graphSchema = graphSchema;\n }\n\n /**\n * Refresh the schema\n */\n public refreshSchema(schema: CaptionState): void {\n this._captionSchema = schema;\n }\n\n /**\n * Refresh visualization captions rules\n */\n public async initVizCaptions(schema: CaptionState): Promise<void> {\n if (this._ogma.LKCaptions.nodesCaptionsRule) {\n this._ogma.LKCaptions.refreshSchema(schema);\n await this._ogma.LKCaptions.updateNodeCaptions();\n } else {\n this._ogma.LKCaptions.updateNodeCaptions(schema.node);\n }\n if (this._ogma.LKCaptions.edgesCaptionsRule) {\n this._ogma.LKCaptions.refreshSchema(schema);\n await this._ogma.LKCaptions.updateEdgeCaptions();\n } else {\n this._ogma.LKCaptions.updateEdgeCaptions(schema.edge);\n }\n }\n\n /**\n * Create or update nodeCaptionRule\n */\n public updateNodeCaptions(schema?: ItemFieldsCaptions): Promise<void> | void {\n if (schema) {\n this._captionSchema.node = schema;\n }\n if (!Tools.isDefined(this.nodesCaptionsRule)) {\n this.nodesCaptionsRule = this._ogma.styles.addRule({\n nodeAttributes: {\n text: {\n content: (node: Ogma.Node | undefined) => {\n if (node === undefined) {\n return ``;\n }\n const value = Captions.getText(\n node.getData(),\n this._captionSchema.node,\n this._graphSchema.node\n );\n return Tools.isDefined(this._nodeMaxTextLength)\n ? Tools.truncate(value, 'middle', this._nodeMaxTextLength)\n : value;\n }\n }\n },\n nodeDependencies: {self: {data: true}}\n });\n } else {\n return this.nodesCaptionsRule.refresh();\n }\n }\n\n /**\n * Create or update edgeCaptionRule\n */\n public updateEdgeCaptions(schema?: ItemFieldsCaptions): Promise<void> | void {\n if (schema) {\n this._captionSchema.edge = schema;\n }\n if (!Tools.isDefined(this.edgesCaptionsRule)) {\n this.edgesCaptionsRule = this._ogma.styles.addRule({\n edgeAttributes: {\n text: {\n content: (edge: Ogma.Edge | undefined) => {\n if (edge === undefined || edge.getData() === undefined) {\n return ``;\n }\n const value = Captions.getText(\n edge.getData(),\n this._captionSchema.edge,\n this._graphSchema.edge\n );\n return Tools.isDefined(this._edgeMaxTextLength)\n ? Tools.truncate(value, 'middle', this._edgeMaxTextLength)\n : value;\n }\n }\n },\n edgeSelector: (edge) => !edge.isVirtual() && edge.isVisible(),\n // ogma will trigger the rendering if data change or the shape change (to trigger the rendering when edges are grouped)\n edgeDependencies: {self: {data: true, attributes: ['shape.style']}}\n });\n } else {\n return this.edgesCaptionsRule.refresh();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"captions.js","sourceRoot":"","sources":["../../../src/ogma/features/captions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;AAKb,6BAAuC;AACvC,6CAAwC;AAOxC,MAAa,WAAW;IAUtB,YACE,IAAY,EACJ,kBAAsC,EACtC,kBAAsC;QADtC,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,uBAAkB,GAAlB,kBAAkB,CAAoB;QATxC,mBAAc,GAAiB,EAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC,CAAC;QACpD,iBAAY,GAGhB,EAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC,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CAAC,IAAI,EACxB,IAAI,CAAC,YAAY,CAAC,IAAI,CACvB,CAAC;4BACF,OAAO,aAAK,CAAC,SAAS,CAAC,IAAI,CAAC,kBAAkB,CAAC;gCAC7C,CAAC,CAAC,aAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,kBAAkB,CAAC;gCAC1D,CAAC,CAAC,KAAK,CAAC;wBACZ,CAAC;qBACF;iBACF;gBACD,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,IAAI,CAAC,SAAS,EAAE;gBAC7D,uHAAuH;gBACvH,gBAAgB,EAAE,EAAC,IAAI,EAAE,EAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,aAAa,CAAC,EAAC,EAAC;aACpE,CAAC,CAAC;SACJ;aAAM;YACL,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC;SACzC;IACH,CAAC;CACF;AArHD,kCAqHC","sourcesContent":["'use strict';\n\nimport * as Ogma from '@linkurious/ogma';\nimport {GraphSchemaTypeWithAccess, ItemFieldsCaptions} from '@linkurious/rest-client';\n\nimport {Captions, LKOgma} from '../..';\nimport {Tools} from '../../tools/tools';\n\nexport interface CaptionState {\n node: ItemFieldsCaptions;\n edge: ItemFieldsCaptions;\n}\n\nexport class CaptionsViz {\n public nodesCaptionsRule!: Ogma.StyleRule;\n public edgesCaptionsRule!: Ogma.StyleRule;\n private _ogma: LKOgma;\n private _captionSchema: CaptionState = {node: {}, edge: {}};\n private _graphSchema: {\n node: Array<GraphSchemaTypeWithAccess>;\n edge: Array<GraphSchemaTypeWithAccess>;\n } = {node: [], edge: []};\n\n constructor(\n ogma: LKOgma,\n private _nodeMaxTextLength: number | undefined,\n private _edgeMaxTextLength: number | undefined\n ) {\n this._ogma = ogma;\n }\n\n public set graphSchema(graphSchema: {\n node: Array<GraphSchemaTypeWithAccess>;\n edge: Array<GraphSchemaTypeWithAccess>;\n }) {\n this._graphSchema = graphSchema;\n }\n\n /**\n * Refresh the schema\n */\n public refreshSchema(schema: CaptionState): void {\n this._captionSchema = schema;\n }\n\n /**\n * Refresh visualization captions rules\n */\n public async initVizCaptions(schema: CaptionState): Promise<void> {\n if (this._ogma.LKCaptions.nodesCaptionsRule) {\n this._ogma.LKCaptions.refreshSchema(schema);\n await this._ogma.LKCaptions.updateNodeCaptions();\n } else {\n this._ogma.LKCaptions.updateNodeCaptions(schema.node);\n }\n if (this._ogma.LKCaptions.edgesCaptionsRule) {\n this._ogma.LKCaptions.refreshSchema(schema);\n await this._ogma.LKCaptions.updateEdgeCaptions();\n } else {\n this._ogma.LKCaptions.updateEdgeCaptions(schema.edge);\n }\n }\n\n /**\n * Create or update nodeCaptionRule\n */\n public updateNodeCaptions(schema?: ItemFieldsCaptions): Promise<void> | void {\n if (schema) {\n this._captionSchema.node = schema;\n }\n if (!Tools.isDefined(this.nodesCaptionsRule)) {\n this.nodesCaptionsRule = this._ogma.styles.addRule({\n nodeAttributes: {\n text: {\n content: (node: Ogma.Node | undefined) => {\n if (node === undefined) {\n return ``;\n }\n const value = Captions.getText(\n node.getData(),\n this._captionSchema.node,\n this._graphSchema.node\n );\n return Tools.isDefined(this._nodeMaxTextLength)\n ? Tools.truncate(value, 'middle', this._nodeMaxTextLength)\n : value;\n }\n }\n },\n nodeDependencies: {self: {data: true}}\n });\n } else {\n return this.nodesCaptionsRule.refresh();\n }\n }\n\n /**\n * Create or update edgeCaptionRule\n */\n public updateEdgeCaptions(schema?: ItemFieldsCaptions): Promise<void> | void {\n if (schema) {\n this._captionSchema.edge = schema;\n }\n if (!Tools.isDefined(this.edgesCaptionsRule)) {\n this.edgesCaptionsRule = this._ogma.styles.addRule({\n edgeAttributes: {\n text: {\n content: (edge: Ogma.Edge | undefined) => {\n if (edge === undefined || edge.getData() === undefined) {\n return ``;\n }\n const value = Captions.getText(\n edge.getData(),\n this._captionSchema.edge,\n this._graphSchema.edge\n );\n return Tools.isDefined(this._edgeMaxTextLength)\n ? Tools.truncate(value, 'middle', this._edgeMaxTextLength)\n : value;\n }\n }\n },\n edgeSelector: (edge) => !edge.isVirtual() && edge.isVisible(),\n // ogma will trigger the rendering if data change or the shape change (to trigger the rendering when edges are grouped)\n edgeDependencies: {self: {data: true, attributes: ['shape.style']}}\n });\n } else {\n return this.edgesCaptionsRule.refresh();\n }\n }\n}\n"]}
@@ -1,20 +1,9 @@
1
1
  'use strict';
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
- var index_1 = require("../index");
15
- var OgmaStore_1 = require("./OgmaStore");
16
- var RxViz = /** @class */ (function () {
17
- function RxViz(ogma) {
3
+ const index_1 = require("../index");
4
+ const OgmaStore_1 = require("./OgmaStore");
5
+ class RxViz {
6
+ constructor(ogma) {
18
7
  this._store = new OgmaStore_1.OgmaStore({
19
8
  selection: new DummyNodeList(),
20
9
  items: { node: [], edge: [] },
@@ -24,112 +13,105 @@ var RxViz = /** @class */ (function () {
24
13
  this._ogma = ogma;
25
14
  this.listenToSelectionEvents();
26
15
  }
27
- Object.defineProperty(RxViz.prototype, "store", {
28
- get: function () {
29
- return this._store;
30
- },
31
- enumerable: true,
32
- configurable: true
33
- });
16
+ get store() {
17
+ return this._store;
18
+ }
34
19
  /**
35
20
  * Listen to ogma events and update the state
36
21
  */
37
- RxViz.prototype.listenToSelectionEvents = function () {
38
- var _this = this;
39
- var count = 0;
40
- this._ogma.events.on('animate', function (e) {
41
- var animationEnd = ++count;
42
- _this._store.dispatch(function (state) { return (__assign(__assign({}, state), { animation: true })); });
43
- clearTimeout(_this._animationThrottle);
44
- _this._animationThrottle = setTimeout(function () {
22
+ listenToSelectionEvents() {
23
+ let count = 0;
24
+ this._ogma.events.on('animate', (e) => {
25
+ const animationEnd = ++count;
26
+ this._store.dispatch((state) => (Object.assign(Object.assign({}, state), { animation: true })));
27
+ clearTimeout(this._animationThrottle);
28
+ this._animationThrottle = setTimeout(() => {
45
29
  if (count === animationEnd) {
46
- _this._store.dispatch(function (state) { return (__assign(__assign({}, state), { animation: false })); });
30
+ this._store.dispatch((state) => (Object.assign(Object.assign({}, state), { animation: false })));
47
31
  }
48
32
  }, e.duration + index_1.ANIMATION_DURATION + 100);
49
33
  });
50
- this._ogma.events.on('dragStart', function () {
51
- _this._store.dispatch(function (state) { return (__assign(__assign({}, state), { animation: true })); });
34
+ this._ogma.events.on('dragStart', () => {
35
+ this._store.dispatch((state) => (Object.assign(Object.assign({}, state), { animation: true })));
52
36
  });
53
- this._ogma.events.on('dragEnd', function () {
54
- _this._store.dispatch(function (state) { return (__assign(__assign({}, state), { animation: false })); });
37
+ this._ogma.events.on('dragEnd', () => {
38
+ this._store.dispatch((state) => (Object.assign(Object.assign({}, state), { animation: false })));
55
39
  });
56
- this._ogma.events.on('addNodes', function () {
57
- _this._store.dispatch(_this.storeItems.bind(_this));
40
+ this._ogma.events.on('addNodes', () => {
41
+ this._store.dispatch(this.storeItems.bind(this));
58
42
  });
59
- this._ogma.events.on('removeNodes', function () {
60
- _this._store.dispatch(_this.storeItems.bind(_this));
43
+ this._ogma.events.on('removeNodes', () => {
44
+ this._store.dispatch(this.storeItems.bind(this));
61
45
  });
62
- this._ogma.events.on('addEdges', function () {
63
- _this._store.dispatch(_this.storeItems.bind(_this));
46
+ this._ogma.events.on('addEdges', () => {
47
+ this._store.dispatch(this.storeItems.bind(this));
64
48
  });
65
- this._ogma.events.on('removeEdges', function () {
66
- _this._store.dispatch(_this.storeItems.bind(_this));
49
+ this._ogma.events.on('removeEdges', () => {
50
+ this._store.dispatch(this.storeItems.bind(this));
67
51
  });
68
- this._ogma.events.on('nodesSelected', function () {
69
- _this._store.dispatch(_this.storeNodeSelection.bind(_this));
52
+ this._ogma.events.on('nodesSelected', () => {
53
+ this._store.dispatch(this.storeNodeSelection.bind(this));
70
54
  });
71
- this._ogma.events.on('edgesSelected', function () {
72
- _this._store.dispatch(_this.storeEdgeSelection.bind(_this));
55
+ this._ogma.events.on('edgesSelected', () => {
56
+ this._store.dispatch(this.storeEdgeSelection.bind(this));
73
57
  });
74
- this._ogma.events.on('nodesUnselected', function () {
75
- _this._store.dispatch(_this.storeNodeSelection.bind(_this));
58
+ this._ogma.events.on('nodesUnselected', () => {
59
+ this._store.dispatch(this.storeNodeSelection.bind(this));
76
60
  });
77
- this._ogma.events.on('edgesUnselected', function () {
78
- _this._store.dispatch(_this.storeEdgeSelection.bind(_this));
61
+ this._ogma.events.on('edgesUnselected', () => {
62
+ this._store.dispatch(this.storeEdgeSelection.bind(this));
79
63
  });
80
- this._ogma.events.on('updateNodeData', function (evt) {
64
+ this._ogma.events.on('updateNodeData', (evt) => {
81
65
  if (evt !== undefined) {
82
- evt.changes.forEach(function (change) {
83
- _this._store.dispatch(function (state) { return (__assign(__assign({}, state), { changes: {
66
+ evt.changes.forEach((change) => {
67
+ this._store.dispatch((state) => (Object.assign(Object.assign({}, state), { changes: {
84
68
  entityType: 'node',
85
69
  input: change.property,
86
70
  value: change.newValues[0]
87
- } })); });
71
+ } })));
88
72
  });
89
73
  }
90
74
  });
91
- this._ogma.events.on('updateEdgeData', function (evt) {
75
+ this._ogma.events.on('updateEdgeData', (evt) => {
92
76
  if (evt !== undefined) {
93
- evt.changes.forEach(function (change) {
94
- _this._store.dispatch(function (state) { return (__assign(__assign({}, state), { changes: {
77
+ evt.changes.forEach((change) => {
78
+ this._store.dispatch((state) => (Object.assign(Object.assign({}, state), { changes: {
95
79
  entityType: 'edge',
96
80
  input: change.property,
97
81
  value: change.newValues[0]
98
- } })); });
82
+ } })));
99
83
  });
100
84
  }
101
85
  });
102
- };
86
+ }
103
87
  /**
104
88
  * Store new items in state
105
89
  */
106
- RxViz.prototype.storeItems = function (state) {
107
- return __assign(__assign({}, state), { items: {
90
+ storeItems(state) {
91
+ return Object.assign(Object.assign({}, state), { items: {
108
92
  node: this._ogma.getNodes().getId(),
109
93
  edge: this._ogma.getEdges().getId()
110
94
  } });
111
- };
95
+ }
112
96
  /**
113
97
  * Store new node selection in state
114
98
  */
115
- RxViz.prototype.storeNodeSelection = function (state) {
116
- return __assign(__assign({}, state), { selection: this._ogma.getSelectedNodes() });
117
- };
99
+ storeNodeSelection(state) {
100
+ return Object.assign(Object.assign({}, state), { selection: this._ogma.getSelectedNodes() });
101
+ }
118
102
  /**
119
103
  * store new edge selection in state
120
104
  */
121
- RxViz.prototype.storeEdgeSelection = function (state) {
122
- return __assign(__assign({}, state), { selection: this._ogma.getSelectedEdges() });
123
- };
124
- return RxViz;
125
- }());
105
+ storeEdgeSelection(state) {
106
+ return Object.assign(Object.assign({}, state), { selection: this._ogma.getSelectedEdges() });
107
+ }
108
+ }
126
109
  exports.RxViz = RxViz;
127
- var DummyNodeList = /** @class */ (function () {
128
- function DummyNodeList() {
110
+ class DummyNodeList {
111
+ constructor() {
129
112
  this.size = 0;
130
113
  this.isNode = true;
131
114
  }
132
- return DummyNodeList;
133
- }());
115
+ }
134
116
  exports.DummyNodeList = DummyNodeList;
135
117
  //# sourceMappingURL=reactive.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reactive.js","sourceRoot":"","sources":["../../../src/ogma/features/reactive.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;AAKb,kCAAoD;AAEpD,yCAAsC;AAStC;IAUE,eAAY,IAAY;QARhB,WAAM,GAAc,IAAI,qBAAS,CAAC;YACxC,SAAS,EAAE,IAAI,aAAa,EAAS;YACrC,KAAK,EAAE,EAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC;YAC3B,OAAO,EAAE,SAAS;YAClB,SAAS,EAAE,KAAK;SACjB,CAAC,CAAC;QAID,IA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B,KAAK,EAAE,MAAM,CAAC,QAAQ;4BACtB,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;yBAC3B,IACD,EAP8B,CAO9B,CAAC,CAAC;gBACN,CAAC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACK,0BAAU,GAAlB,UAAmB,KAAgB;QACjC,6BACK,KAAK,KACR,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE;gBACnC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE;aACpC,IACD;IACJ,CAAC;IAED;;OAEG;IACK,kCAAkB,GAA1B,UAA2B,KAAgB;QACzC,6BACK,KAAK,KACR,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,IACxC;IACJ,CAAC;IAED;;OAEG;IACK,kCAAkB,GAA1B,UAA2B,KAAgB;QACzC,6BACK,KAAK,KACR,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,IACxC;IACJ,CAAC;IACH,YAAC;AAAD,CAAC,AAvID,IAuIC;AAvIY,sBAAK;AAyIlB;IAAA;QACS,SAAI,GAAG,CAAC,CAAC;QACT,WAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAAD,oBAAC;AAAD,CAAC,AAHD,IAGC;AAHY,sCAAa","sourcesContent":["'use strict';\n\nimport Ogma, {NodeList, EdgeList} from '@linkurious/ogma';\nimport {LkEdgeData, LkNodeData} from '@linkurious/rest-client';\n\nimport {ANIMATION_DURATION, LKOgma} from '../index';\n\nimport {OgmaStore} from './OgmaStore';\n\nexport interface OgmaState {\n selection: NodeList<LkNodeData, LkEdgeData> | EdgeList<LkEdgeData, LkNodeData>;\n items: {node: Array<string | number>; edge: Array<string | number>};\n changes: {entityType: 'node' | 'edge'; input: string | string[] | null; value: any} | undefined;\n animation: boolean;\n}\n\nexport class RxViz {\n private _ogma: Ogma;\n private _store: OgmaStore = new OgmaStore({\n selection: new DummyNodeList() as any,\n items: {node: [], edge: []},\n changes: undefined,\n animation: false\n });\n private _animationThrottle: any;\n\n constructor(ogma: LKOgma) {\n this._ogma = ogma;\n this.listenToSelectionEvents();\n }\n\n public get store(): OgmaStore {\n return this._store;\n }\n\n /**\n * Listen to ogma events and update the state\n */\n public listenToSelectionEvents(): void {\n let count = 0;\n this._ogma.events.on('animate', (e: {duration: number}) => {\n const animationEnd = ++count;\n this._store.dispatch((state) => ({...state, animation: true}));\n clearTimeout(this._animationThrottle);\n this._animationThrottle = setTimeout(() => {\n if (count === animationEnd) {\n this._store.dispatch((state) => ({...state, animation: false}));\n }\n }, e.duration + ANIMATION_DURATION + 100);\n });\n\n this._ogma.events.on('dragStart', () => {\n this._store.dispatch((state) => ({...state, animation: true}));\n });\n\n this._ogma.events.on('dragEnd', () => {\n this._store.dispatch((state) => ({...state, animation: false}));\n });\n\n this._ogma.events.on('addNodes', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n this._ogma.events.on('removeNodes', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n this._ogma.events.on('addEdges', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n this._ogma.events.on('removeEdges', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n\n this._ogma.events.on('nodesSelected', () => {\n this._store.dispatch(this.storeNodeSelection.bind(this));\n });\n\n this._ogma.events.on('edgesSelected', () => {\n this._store.dispatch(this.storeEdgeSelection.bind(this));\n });\n\n this._ogma.events.on('nodesUnselected', () => {\n this._store.dispatch(this.storeNodeSelection.bind(this));\n });\n\n this._ogma.events.on('edgesUnselected', () => {\n this._store.dispatch(this.storeEdgeSelection.bind(this));\n });\n\n this._ogma.events.on('updateNodeData', (evt) => {\n if (evt !== undefined) {\n evt.changes.forEach((change) => {\n this._store.dispatch((state) => ({\n ...state,\n changes: {\n entityType: 'node',\n input: change.property,\n value: change.newValues[0]\n }\n }));\n });\n }\n });\n\n this._ogma.events.on('updateEdgeData', (evt) => {\n if (evt !== undefined) {\n evt.changes.forEach((change) => {\n this._store.dispatch((state) => ({\n ...state,\n changes: {\n entityType: 'edge',\n input: change.property,\n value: change.newValues[0]\n }\n }));\n });\n }\n });\n }\n\n /**\n * Store new items in state\n */\n private storeItems(state: OgmaState): OgmaState {\n return {\n ...state,\n items: {\n node: this._ogma.getNodes().getId(),\n edge: this._ogma.getEdges().getId()\n }\n };\n }\n\n /**\n * Store new node selection in state\n */\n private storeNodeSelection(state: OgmaState): OgmaState {\n return {\n ...state,\n selection: this._ogma.getSelectedNodes()\n };\n }\n\n /**\n * store new edge selection in state\n */\n private storeEdgeSelection(state: OgmaState): OgmaState {\n return {\n ...state,\n selection: this._ogma.getSelectedEdges()\n };\n }\n}\n\nexport class DummyNodeList {\n public size = 0;\n public isNode = true;\n}\n"]}
1
+ {"version":3,"file":"reactive.js","sourceRoot":"","sources":["../../../src/ogma/features/reactive.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAKb,oCAAoD;AAEpD,2CAAsC;AAStC,MAAa,KAAK;IAUhB,YAAY,IAAY;QARhB,WAAM,GAAc,IAAI,qBAAS,CAAC;YACxC,SAAS,EAAE,IAAI,aAAa,EAAS;YACrC,KAAK,EAAE,EAAC,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAC;YAC3B,OAAO,EAAE,SAAS;YAClB,SAAS,EAAE,KAAK;SACjB,CAAC,CAAC;QAID,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;OAEG;IACI,uBAAuB;QAC5B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,CAAqB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IACL,CAAC;IAED;;OAEG;IACK,UAAU,CAAC,KAAgB;QACjC,uCACK,KAAK,KACR,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE;gBACnC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE;aACpC,IACD;IACJ,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,KAAgB;QACzC,uCACK,KAAK,KACR,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,IACxC;IACJ,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,KAAgB;QACzC,uCACK,KAAK,KACR,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,IACxC;IACJ,CAAC;CACF;AAvID,sBAuIC;AAED,MAAa,aAAa;IAA1B;QACS,SAAI,GAAG,CAAC,CAAC;QACT,WAAM,GAAG,IAAI,CAAC;IACvB,CAAC;CAAA;AAHD,sCAGC","sourcesContent":["'use strict';\n\nimport Ogma, {NodeList, EdgeList} from '@linkurious/ogma';\nimport {LkEdgeData, LkNodeData} from '@linkurious/rest-client';\n\nimport {ANIMATION_DURATION, LKOgma} from '../index';\n\nimport {OgmaStore} from './OgmaStore';\n\nexport interface OgmaState {\n selection: NodeList<LkNodeData, LkEdgeData> | EdgeList<LkEdgeData, LkNodeData>;\n items: {node: Array<string | number>; edge: Array<string | number>};\n changes: {entityType: 'node' | 'edge'; input: string | string[] | null; value: any} | undefined;\n animation: boolean;\n}\n\nexport class RxViz {\n private _ogma: Ogma;\n private _store: OgmaStore = new OgmaStore({\n selection: new DummyNodeList() as any,\n items: {node: [], edge: []},\n changes: undefined,\n animation: false\n });\n private _animationThrottle: any;\n\n constructor(ogma: LKOgma) {\n this._ogma = ogma;\n this.listenToSelectionEvents();\n }\n\n public get store(): OgmaStore {\n return this._store;\n }\n\n /**\n * Listen to ogma events and update the state\n */\n public listenToSelectionEvents(): void {\n let count = 0;\n this._ogma.events.on('animate', (e: {duration: number}) => {\n const animationEnd = ++count;\n this._store.dispatch((state) => ({...state, animation: true}));\n clearTimeout(this._animationThrottle);\n this._animationThrottle = setTimeout(() => {\n if (count === animationEnd) {\n this._store.dispatch((state) => ({...state, animation: false}));\n }\n }, e.duration + ANIMATION_DURATION + 100);\n });\n\n this._ogma.events.on('dragStart', () => {\n this._store.dispatch((state) => ({...state, animation: true}));\n });\n\n this._ogma.events.on('dragEnd', () => {\n this._store.dispatch((state) => ({...state, animation: false}));\n });\n\n this._ogma.events.on('addNodes', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n this._ogma.events.on('removeNodes', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n this._ogma.events.on('addEdges', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n this._ogma.events.on('removeEdges', () => {\n this._store.dispatch(this.storeItems.bind(this));\n });\n\n this._ogma.events.on('nodesSelected', () => {\n this._store.dispatch(this.storeNodeSelection.bind(this));\n });\n\n this._ogma.events.on('edgesSelected', () => {\n this._store.dispatch(this.storeEdgeSelection.bind(this));\n });\n\n this._ogma.events.on('nodesUnselected', () => {\n this._store.dispatch(this.storeNodeSelection.bind(this));\n });\n\n this._ogma.events.on('edgesUnselected', () => {\n this._store.dispatch(this.storeEdgeSelection.bind(this));\n });\n\n this._ogma.events.on('updateNodeData', (evt) => {\n if (evt !== undefined) {\n evt.changes.forEach((change) => {\n this._store.dispatch((state) => ({\n ...state,\n changes: {\n entityType: 'node',\n input: change.property,\n value: change.newValues[0]\n }\n }));\n });\n }\n });\n\n this._ogma.events.on('updateEdgeData', (evt) => {\n if (evt !== undefined) {\n evt.changes.forEach((change) => {\n this._store.dispatch((state) => ({\n ...state,\n changes: {\n entityType: 'edge',\n input: change.property,\n value: change.newValues[0]\n }\n }));\n });\n }\n });\n }\n\n /**\n * Store new items in state\n */\n private storeItems(state: OgmaState): OgmaState {\n return {\n ...state,\n items: {\n node: this._ogma.getNodes().getId(),\n edge: this._ogma.getEdges().getId()\n }\n };\n }\n\n /**\n * Store new node selection in state\n */\n private storeNodeSelection(state: OgmaState): OgmaState {\n return {\n ...state,\n selection: this._ogma.getSelectedNodes()\n };\n }\n\n /**\n * store new edge selection in state\n */\n private storeEdgeSelection(state: OgmaState): OgmaState {\n return {\n ...state,\n selection: this._ogma.getSelectedEdges()\n };\n }\n}\n\nexport class DummyNodeList {\n public size = 0;\n public isNode = true;\n}\n"]}
@@ -1,16 +1,16 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var rest_client_1 = require("@linkurious/rest-client");
3
+ const rest_client_1 = require("@linkurious/rest-client");
4
4
  /**
5
5
  * Return the current size of the selection
6
6
  */
7
- exports.getSelectionSize = function (state) {
7
+ exports.getSelectionSize = (state) => {
8
8
  return state.selection.size;
9
9
  };
10
10
  /**
11
11
  * Return the current state of the selection
12
12
  */
13
- exports.getSelectionState = function (state) {
13
+ exports.getSelectionState = (state) => {
14
14
  switch (state.selection.size) {
15
15
  case 1:
16
16
  return 'selection';
@@ -23,7 +23,7 @@ exports.getSelectionState = function (state) {
23
23
  /**
24
24
  * Get the entityType of the current selection
25
25
  */
26
- exports.getSelectionEntity = function (state) {
26
+ exports.getSelectionEntity = (state) => {
27
27
  if (state.selection.size === 0) {
28
28
  return undefined;
29
29
  }
@@ -32,14 +32,14 @@ exports.getSelectionEntity = function (state) {
32
32
  /**
33
33
  * Return the item selection if there's only one item selected
34
34
  */
35
- exports.getUniqSelection = function (state) {
35
+ exports.getUniqSelection = (state) => {
36
36
  return state.selection.size === 1 ? state.selection.get(0) : undefined;
37
37
  };
38
38
  /**
39
39
  * Return the types of the current selection (if only one item is selected)
40
40
  */
41
- exports.getUniqSelectionTypes = function (state) {
42
- var uniqSelection = exports.getUniqSelection(state);
41
+ exports.getUniqSelectionTypes = (state) => {
42
+ const uniqSelection = exports.getUniqSelection(state);
43
43
  if (uniqSelection === undefined) {
44
44
  return undefined;
45
45
  }
@@ -53,8 +53,8 @@ exports.getUniqSelectionTypes = function (state) {
53
53
  /**
54
54
  * Return the entityType of the current selection if there's only one item selected
55
55
  */
56
- exports.getUniqSelectionEntity = function (state) {
57
- var uniqSelection = exports.getUniqSelection(state);
56
+ exports.getUniqSelectionEntity = (state) => {
57
+ const uniqSelection = exports.getUniqSelection(state);
58
58
  if (uniqSelection === undefined) {
59
59
  return undefined;
60
60
  }
@@ -66,14 +66,14 @@ exports.getUniqSelectionEntity = function (state) {
66
66
  /**
67
67
  * Return the properties of the current selection if there's only one item selected
68
68
  */
69
- exports.getSelectionProperties = function (state) {
70
- var uniqSelection = exports.getUniqSelection(state);
69
+ exports.getSelectionProperties = (state) => {
70
+ const uniqSelection = exports.getUniqSelection(state);
71
71
  if (uniqSelection !== undefined) {
72
- var properties_1 = uniqSelection.getData().properties;
73
- return Object.keys(properties_1).map(function (propKey) {
72
+ const properties = uniqSelection.getData().properties;
73
+ return Object.keys(properties).map((propKey) => {
74
74
  return {
75
75
  key: propKey,
76
- value: properties_1[propKey]
76
+ value: properties[propKey]
77
77
  };
78
78
  });
79
79
  }
@@ -82,7 +82,7 @@ exports.getSelectionProperties = function (state) {
82
82
  /**
83
83
  * Return true if the current selection has properties
84
84
  */
85
- exports.hasSelectionProperties = function (state) {
85
+ exports.hasSelectionProperties = (state) => {
86
86
  return exports.getSelectionProperties(state).length > 0;
87
87
  };
88
88
  //# sourceMappingURL=selectors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"selectors.js","sourceRoot":"","sources":["../../../src/ogma/features/selectors.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,uDAA2E;AAO3E;;GAEG;AACU,QAAA,gBAAgB,GAAG,UAAC,KAAgB;IAC/C,OAAQ,KAAK,CAAC,SAAkC,CAAC,IAAI,CAAC;AACxD,CAAC,CAAC;AAEF;;GAEG;AACU,QAAA,iBAAiB,GAAG,UAAC,KAAgB;IAChD,QAAS,KAAK,CAAC,SAAkC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AC,MAAM,EAAE;QACxB,OAAO,MAAM,CAAC;KACf;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF;;GAEG;AACU,QAAA,sBAAsB,GAAG,UAAC,KAAgB;IACrD,IAAM,aAAa,GAAG,wBAAgB,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,aAAa,KAAK,SAAS,EAAE;QAC/B,IAAM,YAAU,GAAG,aAAa,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC;QACtD,OAAO,MAAM,CAAC,IAAI,CAAC,YAAU,CAAC,CAAC,GAAG,CAAC,UAAC,OAAO;YACzC,OAAO;gBACL,GAAG,EAAE,OAAO;gBACZ,KAAK,EAAE,YAAU,CAAC,OAAO,CAAC;aAC3B,CAAC;QACJ,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF;;GAEG;AACU,QAAA,sBAAsB,GAAG,UAAC,KAAgB;IACrD,OAAO,8BAAsB,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAClD,CAAC,CAAC","sourcesContent":["'use strict';\n\nimport {EntityType, LkEdgeData, LkNodeData} from '@linkurious/rest-client';\nimport {Edge, ItemList, Node} from '@linkurious/ogma';\n\nimport {OgmaState} from './reactive';\n\nexport type SelectionState = 'selection' | 'multiSelection' | 'noSelection';\n\n/**\n * Return the current size of the selection\n */\nexport const getSelectionSize = (state: OgmaState): number => {\n return (state.selection as ItemList<LkNodeData>).size;\n};\n\n/**\n * Return the current state of the selection\n */\nexport const getSelectionState = (state: OgmaState): SelectionState => {\n switch ((state.selection as ItemList<LkNodeData>).size) {\n case 1:\n return 'selection';\n\n case 0:\n return 'noSelection';\n\n default:\n return 'multiSelection';\n }\n};\n\n/**\n * Get the entityType of the current selection\n */\nexport const getSelectionEntity = (state: OgmaState): EntityType | undefined => {\n if (state.selection.size === 0) {\n return undefined;\n }\n return (state.selection as ItemList<LkNodeData>).isNode ? EntityType.NODE : EntityType.EDGE;\n};\n\n/**\n * Return the item selection if there's only one item selected\n */\nexport const getUniqSelection = (\n state: OgmaState\n): Node<LkNodeData, LkEdgeData> | Edge<LkEdgeData, LkNodeData> | undefined => {\n return state.selection.size === 1 ? state.selection.get(0) : undefined;\n};\n\n/**\n * Return the types of the current selection (if only one item is selected)\n */\nexport const getUniqSelectionTypes = (state: OgmaState): Array<string> | undefined => {\n const uniqSelection = getUniqSelection(state);\n if (uniqSelection === undefined) {\n return undefined;\n }\n if (uniqSelection.isNode) {\n return uniqSelection.getData('categories');\n } else {\n return [uniqSelection.getData('type')];\n }\n};\n\n/**\n * Return the entityType of the current selection if there's only one item selected\n */\nexport const getUniqSelectionEntity = (state: OgmaState): 'node' | 'edge' | undefined => {\n const uniqSelection = getUniqSelection(state);\n if (uniqSelection === undefined) {\n return undefined;\n }\n if (uniqSelection.isNode) {\n return 'node';\n }\n return 'edge';\n};\n\n/**\n * Return the properties of the current selection if there's only one item selected\n */\nexport const getSelectionProperties = (state: OgmaState): Array<{key: string; value: any}> => {\n const uniqSelection = getUniqSelection(state);\n if (uniqSelection !== undefined) {\n const properties = uniqSelection.getData().properties;\n return Object.keys(properties).map((propKey) => {\n return {\n key: propKey,\n value: properties[propKey]\n };\n });\n }\n return [];\n};\n\n/**\n * Return true if the current selection has properties\n */\nexport const hasSelectionProperties = (state: OgmaState): boolean => {\n return getSelectionProperties(state).length > 0;\n};\n"]}
1
+ {"version":3,"file":"selectors.js","sourceRoot":"","sources":["../../../src/ogma/features/selectors.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,yDAA2E;AAO3E;;GAEG;AACU,QAAA,gBAAgB,GAAG,CAAC,KAAgB,EAAU,EAAE;IAC3D,OAAQ,KAAK,CAAC,SAAkC,CAAC,IAAI,CAAC;AACxD,CAAC,CAAC;AAEF;;GAEG;AACU,QAAA,iBAAiB,GAAG,CAAC,KAAgB,EAAkB,EAAE;IACpE,QAAS,KAAK,CAAC,SAAkC,CAAC,IAAI,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O,SAAS,CAAC;KAClB;IACD,IAAI,aAAa,CAAC,MAAM,EAAE;QACxB,OAAO,MAAM,CAAC;KACf;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF;;GAEG;AACU,QAAA,sBAAsB,GAAG,CAAC,KAAgB,EAAoC,EAAE;IAC3F,MAAM,aAAa,GAAG,wBAAgB,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,aAAa,KAAK,SAAS,EAAE;QAC/B,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC;QACtD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7C,OAAO;gBACL,GAAG,EAAE,OAAO;gBACZ,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC;aAC3B,CAAC;QACJ,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AAEF;;GAEG;AACU,QAAA,sBAAsB,GAAG,CAAC,KAAgB,EAAW,EAAE;IAClE,OAAO,8BAAsB,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAClD,CAAC,CAAC","sourcesContent":["'use strict';\n\nimport {EntityType, LkEdgeData, LkNodeData} from '@linkurious/rest-client';\nimport {Edge, ItemList, Node} from '@linkurious/ogma';\n\nimport {OgmaState} from './reactive';\n\nexport type SelectionState = 'selection' | 'multiSelection' | 'noSelection';\n\n/**\n * Return the current size of the selection\n */\nexport const getSelectionSize = (state: OgmaState): number => {\n return (state.selection as ItemList<LkNodeData>).size;\n};\n\n/**\n * Return the current state of the selection\n */\nexport const getSelectionState = (state: OgmaState): SelectionState => {\n switch ((state.selection as ItemList<LkNodeData>).size) {\n case 1:\n return 'selection';\n\n case 0:\n return 'noSelection';\n\n default:\n return 'multiSelection';\n }\n};\n\n/**\n * Get the entityType of the current selection\n */\nexport const getSelectionEntity = (state: OgmaState): EntityType | undefined => {\n if (state.selection.size === 0) {\n return undefined;\n }\n return (state.selection as ItemList<LkNodeData>).isNode ? EntityType.NODE : EntityType.EDGE;\n};\n\n/**\n * Return the item selection if there's only one item selected\n */\nexport const getUniqSelection = (\n state: OgmaState\n): Node<LkNodeData, LkEdgeData> | Edge<LkEdgeData, LkNodeData> | undefined => {\n return state.selection.size === 1 ? state.selection.get(0) : undefined;\n};\n\n/**\n * Return the types of the current selection (if only one item is selected)\n */\nexport const getUniqSelectionTypes = (state: OgmaState): Array<string> | undefined => {\n const uniqSelection = getUniqSelection(state);\n if (uniqSelection === undefined) {\n return undefined;\n }\n if (uniqSelection.isNode) {\n return uniqSelection.getData('categories');\n } else {\n return [uniqSelection.getData('type')];\n }\n};\n\n/**\n * Return the entityType of the current selection if there's only one item selected\n */\nexport const getUniqSelectionEntity = (state: OgmaState): 'node' | 'edge' | undefined => {\n const uniqSelection = getUniqSelection(state);\n if (uniqSelection === undefined) {\n return undefined;\n }\n if (uniqSelection.isNode) {\n return 'node';\n }\n return 'edge';\n};\n\n/**\n * Return the properties of the current selection if there's only one item selected\n */\nexport const getSelectionProperties = (state: OgmaState): Array<{key: string; value: any}> => {\n const uniqSelection = getUniqSelection(state);\n if (uniqSelection !== undefined) {\n const properties = uniqSelection.getData().properties;\n return Object.keys(properties).map((propKey) => {\n return {\n key: propKey,\n value: properties[propKey]\n };\n });\n }\n return [];\n};\n\n/**\n * Return true if the current selection has properties\n */\nexport const hasSelectionProperties = (state: OgmaState): boolean => {\n return getSelectionProperties(state).length > 0;\n};\n"]}