@esfaenza/es-diagrams 12.2.8 → 12.2.12

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.
@@ -543,7 +543,8 @@ const Loc = {
543
543
  "is loaded and managed directly by this library. You don't need to import it or use it directly, just be sure to set the relative options": { "en-US": "is loaded and managed directly by this library. You don't need to import it or use it directly, just be sure to set the relative options", "it-IT": "viene caricato e gestito nativamente dalla libreria. Non c'è bisogno di reimportarlo, né di configurarlo (usare le opzioni specifiche)" },
544
544
  "If you don't specify a source and a target for an edge you have to write its id in the format {source}-{target}": { "en-US": "If you don't specify a source and a target for an edge you have to write its id in the format {source}-{target}", "it-IT": "Se non è specificata una sorgente e una destinazione per il collegamento è opportuno scriverne l'id nel formato {sorgente}-{destinazione}" },
545
545
  "Elements have been changed after diagram initialization": { "en-US": "Elements have been changed after diagram initialization", "it-IT": "Rilevato un cambio di Elementi dopo l'inizializzazione del Diagramma" },
546
- "Layout have been changed after diagram initialization": { "en-US": "Layout have been changed after diagram initialization", "it-IT": "Rilevato un cambio di Layout dopo l'inizializzazione del Diagramma" }
546
+ "Layout have been changed after diagram initialization": { "en-US": "Layout have been changed after diagram initialization", "it-IT": "Rilevato un cambio di Layout dopo l'inizializzazione del Diagramma" },
547
+ "Cannot update NodeHTMLTemplates as they don't seem to be used": { "en-US": "Cannot update NodeHTMLTemplates as they don't seem to be used", "it-IT": "Impossibile aggiornare i NodeHTMLTemplates dato che non sembra siano utilizzati" }
547
548
  };
548
549
 
549
550
  /** @ignore */ const cytoscape$1 = cy_;
@@ -581,7 +582,7 @@ class EsDiagramService {
581
582
  switch (moduleId) {
582
583
  case "cytoscape-cxtmenu": return import('cytoscape-cxtmenu').then((module) => this.modulesCache[moduleId] = module.default).catch(err => this.handleError(moduleId, err));
583
584
  case "cytoscape-expand-collapse": return import('cytoscape-expand-collapse').then((module) => this.modulesCache[moduleId] = module.default).catch(err => this.handleError(moduleId, err));
584
- case "cytoscape-html-node": return import('cytoscape-html-node').then((module) => this.modulesCache[moduleId] = module.register).catch(err => this.handleError(moduleId, err));
585
+ case "cytoscape-html-node": return import('@esfaenza/cytoscape-html-node').then((module) => this.modulesCache[moduleId] = module.register).catch(err => this.handleError(moduleId, err));
585
586
  case "cytoscape-dagre":
586
587
  yield import('dagre').catch(err => this.handleError("dagre", err));
587
588
  return import('cytoscape-dagre').then((module) => this.modulesCache[moduleId] = module.default).catch(err => this.handleError(moduleId, err));
@@ -880,6 +881,27 @@ class EsDiagramComponent {
880
881
  * Funziona solamente se il **Layout** corrente del diagramma supporta le animazioni
881
882
  */
882
883
  this.AnimateLayoutChanges = true;
884
+ /**
885
+ * Attiva una modalità di selezione "smart"... o perlomeno "smarter" del default di Cytoscape.
886
+ *
887
+ * - Il click di un elemento non selezionato lo seleziona
888
+ * - Il click di un elemento selezionato lo deseleziona
889
+ * - Lo stato di selezione viene persistito sull'oggetto originale invece di rimanere in un internal
890
+ * - All'assegnazione di oggetti selezionati, questi vengono marcati correttamente con l'overlay di selezione
891
+ *
892
+ * N.B: la chiamata all'evento **onNodeClick** avviene **DOPO** la gestione della selezione
893
+ */
894
+ this.SmartSelection = false;
895
+ /**
896
+ * CSS per la graficazione della selezione dei nodi. Quando un nodo verrà selezionato avrà sopra di se un overlay che 'sborda' di **overlay-padding** pixel,
897
+ * di colore **overlay-color** e con un opacità **overlay-opacity**
898
+ *
899
+ * Assegnando "{}" a questo input, la Smart selection viene gestita ma la gestione grafica è affidata all'utente,
900
+ * ad esempio usando dei **NodeHTMLTemplates** che definiscano selettori su nodi ":selected"
901
+ *
902
+ * @default {'overlay-color':'blue','overlay-opacity':0.5,'overlay-padding':7}
903
+ */
904
+ this.SmartSelectionStyles = null;
883
905
  /**
884
906
  * Periodo di throttle da quando viene effettuato un resize a quando ricalcolare le dimensioni del diagramma.
885
907
  *
@@ -926,6 +948,14 @@ class EsDiagramComponent {
926
948
  * Evento lanciato al click di un nodo, contiene l'oggetto **data** del nodo in questione
927
949
  */
928
950
  this.onNodeClick = new EventEmitter();
951
+ /**
952
+ * Evento lanciato alla selezione o deselezione di un nodo, contiene l'oggetto **data** del nodo in questione e informazioni sul suo stato di selezione
953
+ */
954
+ this.onNodeSelection = new EventEmitter();
955
+ /**
956
+ * Evento lanciato al termine del Layouting. Se si vuole eseguire codice dopo che il Layout è fatto e completamente graficato, questo è il punto
957
+ */
958
+ this.onLayoutDone = new EventEmitter();
929
959
  /**
930
960
  * Evento lanciato al termine del caricamento del diagramma
931
961
  */
@@ -938,6 +968,10 @@ class EsDiagramComponent {
938
968
  * Api dell'estensione expand-collapse per permettere di effettuare operazioni dall'esterno del diagramma. Vengono valorizzate se **UseExpandCollapse** è **true**
939
969
  */
940
970
  this.ExpandCollapseApi = null;
971
+ /**
972
+ * Api dell'estensione html-node per permettere di effettuare operazioni dall'esterno del diagramma. Vengono valorizzate se sono impostati dei **NodeHTMLTemplates**
973
+ */
974
+ this.HtmlNodeApi = null;
941
975
  }
942
976
  /**
943
977
  * @ignore
@@ -991,6 +1025,8 @@ class EsDiagramComponent {
991
1025
  if (elements && elements.length && elements.length > 0) {
992
1026
  this.reviewCytoscapeElements(elements, previous_elements);
993
1027
  this.cy.add(elements);
1028
+ if (this.SmartSelection)
1029
+ this.setupElementsSelectionIfNeeded();
994
1030
  // Se solo gli elementi cambiano, riapplico il Layout precedente
995
1031
  if (!layoutChanges && this.LastLayout) {
996
1032
  // Se devo animare le modifche al layout forzo il parametro relativo
@@ -1029,9 +1065,39 @@ class EsDiagramComponent {
1029
1065
  // Se devo aggiornare in automatico in base alla dimensione del contenitore collego il ResizeObserver
1030
1066
  if (this.AutoupdateSize)
1031
1067
  this.listenOnChanges();
1068
+ if (this.SmartSelection) {
1069
+ this.setupSelectionStyles();
1070
+ this.setupElementsSelectionIfNeeded();
1071
+ }
1032
1072
  this.onLoaded.emit();
1033
1073
  });
1034
1074
  }
1075
+ /**
1076
+ * Prende tutti gli elementi appena assegnati, e se qualcuno era selezionato la situazione viene persistita su cytoscape
1077
+ */
1078
+ setupElementsSelectionIfNeeded() {
1079
+ for (let i = 0; i < this.Elements.length; i++) {
1080
+ let eldata = this.Elements[i].data;
1081
+ if (eldata.__selected) {
1082
+ let el = this.cy.$id(eldata.id);
1083
+ el.select();
1084
+ }
1085
+ }
1086
+ }
1087
+ /**
1088
+ * Carica gli stili per mostrare carina la selezione dei nodi
1089
+ */
1090
+ setupSelectionStyles() {
1091
+ let cssItem = this.SmartSelectionStyles || {
1092
+ 'overlay-color': 'blue',
1093
+ 'overlay-opacity': 0.5,
1094
+ 'overlay-padding': 7
1095
+ };
1096
+ // Backdoor per poter assegnare "{}" a SmartSelectionStyles in modo di utilizzare la smart selection ma senza che nessuno stile venga applicato
1097
+ // ad esempio qualora si volesse utilizzare l'htmlnode per gestire la grafica degli elementi selezionati
1098
+ if (cssItem['overlay-color'] && cssItem['overlay-opacity'] && cssItem['overlay-padding'])
1099
+ this.cy.style().selector('node:selected').css(cssItem);
1100
+ }
1035
1101
  /**
1036
1102
  * Registra l'ascolto al contenitore del grafico e in caso di modifiche alla dimensione, al massimo una volta ogni 500 millisecondi, lo ridisegna
1037
1103
  */
@@ -1053,7 +1119,32 @@ class EsDiagramComponent {
1053
1119
  */
1054
1120
  bindCytoscapeEvents() {
1055
1121
  this.cy.bind('click', 'node', (event) => {
1056
- this.onNodeClick.emit({ data: event.target.data() });
1122
+ let targetData = event.target.data();
1123
+ if (this.SmartSelection) {
1124
+ let id = targetData.id;
1125
+ let el = this.cy.$id(id);
1126
+ let selected = el.selected();
1127
+ el.selectify();
1128
+ if (selected)
1129
+ el.unselect();
1130
+ else
1131
+ el.select();
1132
+ el.unselectify();
1133
+ // Questo va anche nella lista degli elementi originali (this.Elements) dato che cytoscape li prende per riferimento (bbbbbravo cyto-chan)
1134
+ el.data("__selected", !selected);
1135
+ }
1136
+ this.onNodeClick.emit({ data: targetData });
1137
+ });
1138
+ this.cy.bind('select', 'node', (event) => {
1139
+ let targetData = event.target.data();
1140
+ this.onNodeSelection.emit({ data: targetData, selected: true });
1141
+ });
1142
+ this.cy.bind('layoutstop', (event) => {
1143
+ this.onLayoutDone.emit();
1144
+ });
1145
+ this.cy.bind('unselect', 'node', (event) => {
1146
+ let targetData = event.target.data();
1147
+ this.onNodeSelection.emit({ data: targetData, selected: false });
1057
1148
  });
1058
1149
  // Altri eventi...
1059
1150
  }
@@ -1098,8 +1189,8 @@ class EsDiagramComponent {
1098
1189
  }
1099
1190
  // Utilizzo dell'HTML node
1100
1191
  if (this.NodeHTMLTemplates && this.NodeHTMLTemplates.length > 0) {
1101
- let htmlnode = anyCy.htmlnode();
1102
- htmlnode.createHtmlNode(cytoscape, this.cy, this.NodeHTMLTemplates);
1192
+ this.HtmlNodeApi = anyCy.htmlnode();
1193
+ this.HtmlNodeApi.createHtmlNode(cytoscape, this.cy, this.NodeHTMLTemplates);
1103
1194
  }
1104
1195
  // Utilizzo del Context Menu
1105
1196
  if (this.UseContextMenu)
@@ -1111,6 +1202,13 @@ class EsDiagramComponent {
1111
1202
  if (this.ExtensionModulesApplyer)
1112
1203
  this.ExtensionModulesApplyer(this.cy);
1113
1204
  }
1205
+ updateCardData() {
1206
+ if (!this.HtmlNodeApi) {
1207
+ this.service.log("E", "Cannot update NodeHTMLTemplates as they don't seem to be used");
1208
+ return;
1209
+ }
1210
+ this.HtmlNodeApi.update();
1211
+ }
1114
1212
  /**
1115
1213
  * Metodo interno per il caricamento dei moduli di estensione
1116
1214
  *
@@ -1218,12 +1316,16 @@ EsDiagramComponent.propDecorators = {
1218
1316
  AutoupdateSize: [{ type: Input }],
1219
1317
  PreserveElementsPosition: [{ type: Input }],
1220
1318
  AnimateLayoutChanges: [{ type: Input }],
1319
+ SmartSelection: [{ type: Input }],
1320
+ SmartSelectionStyles: [{ type: Input }],
1221
1321
  ResizeThrottleTime: [{ type: Input }],
1222
1322
  Layout: [{ type: Input }],
1223
1323
  NodeHTMLTemplates: [{ type: Input }],
1224
1324
  ExtensionModulesImporter: [{ type: Input }],
1225
1325
  ExtensionModulesApplyer: [{ type: Input }],
1226
1326
  onNodeClick: [{ type: Output }],
1327
+ onNodeSelection: [{ type: Output }],
1328
+ onLayoutDone: [{ type: Output }],
1227
1329
  onLoaded: [{ type: Output }]
1228
1330
  };
1229
1331