@processmaker/modeler 1.39.20 → 1.39.21

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@processmaker/modeler",
3
- "version": "1.39.20",
3
+ "version": "1.39.21",
4
4
  "scripts": {
5
5
  "serve": "vue-cli-service serve --mode development",
6
6
  "test:unit": "vue-cli-service test:unit",
@@ -952,7 +952,25 @@ export default {
952
952
  },
953
953
  async createNodeAsync(type, definition, diagram) {
954
954
  const node = this.createNode(type, definition, diagram);
955
+ if (!this.isMultiplayer) {
956
+ store.commit('addNode', node);
957
+ }
958
+ else {
959
+ this.loadNodeForMultiplayer(node);
960
+ }
961
+ },
962
+ async loadNodeForMultiplayer(node) {
963
+ if (node.type === 'processmaker-modeler-lane') {
964
+ await this.addNode(node, node.definition.id, true);
965
+ this.nodeIdGenerator.updateCounters();
966
+ await this.$nextTick();
967
+ await this.paperManager.awaitScheduledUpdates();
968
+ window.ProcessMaker.EventBus.$emit('multiplayer-addLanes', [node]);
969
+ return;
970
+ }
971
+ this.multiplayerHook(node, false);
955
972
  store.commit('addNode', node);
973
+ this.poolTarget = null;
956
974
  },
957
975
  createNode(type, definition, diagram) {
958
976
  if (Node.isTimerType(type)) {
@@ -1112,7 +1130,7 @@ export default {
1112
1130
  const view = newNodeComponent.shapeView;
1113
1131
  await this.$refs.selector.selectElement(view);
1114
1132
  },
1115
- multiplayerHook(node, fromClient) {
1133
+ multiplayerHook(node, fromClient, isProcessRequested = false) {
1116
1134
  const blackList = [
1117
1135
  'processmaker-modeler-lane',
1118
1136
  'processmaker-modeler-generic-flow',
@@ -1141,6 +1159,11 @@ export default {
1141
1159
  if (node?.pool?.component) {
1142
1160
  defaultData['poolId'] = node.pool.component.id;
1143
1161
  }
1162
+
1163
+ if (isProcessRequested) {
1164
+ return defaultData;
1165
+ }
1166
+
1144
1167
  window.ProcessMaker.EventBus.$emit('multiplayer-addNode', defaultData);
1145
1168
  }
1146
1169
  if (this.flowTypes.includes(node.type)) {
@@ -1149,17 +1172,23 @@ export default {
1149
1172
 
1150
1173
  if (node.type === 'processmaker-modeler-data-input-association') {
1151
1174
  sourceRefId = Array.isArray(node.definition.sourceRef) && node.definition.sourceRef[0]?.id;
1152
- targetRefId = node.definition.targetRef?.$parent?.$parent.get('id');
1175
+ targetRefId = node.definition.targetRef?.$parent?.$parent?.get('id');
1153
1176
  }
1154
1177
 
1155
1178
  if (sourceRefId && targetRefId) {
1156
- window.ProcessMaker.EventBus.$emit('multiplayer-addFlow', {
1179
+ const flowData = {
1157
1180
  id: node.definition.id,
1158
1181
  type: node.type,
1159
1182
  sourceRefId,
1160
1183
  targetRefId,
1161
1184
  waypoint: node.diagram.waypoint,
1162
- });
1185
+ };
1186
+
1187
+ if (isProcessRequested) {
1188
+ return flowData;
1189
+ }
1190
+
1191
+ window.ProcessMaker.EventBus.$emit('multiplayer-addFlow', flowData);
1163
1192
  }
1164
1193
  }
1165
1194
  }
@@ -1282,36 +1311,34 @@ export default {
1282
1311
  nodeThatWillBeReplaced: node,
1283
1312
  };
1284
1313
 
1285
- if (this.isMultiplayer) {
1286
- // Get all node types
1287
- const nodeTypes = nodeTypesStore.getters.getNodeTypes;
1288
- // Get the new control
1289
- const newControl = nodeTypes.flatMap(nodeType => {
1290
- return nodeType.items?.filter(item => item.type === typeToReplaceWith);
1291
- }).filter(Boolean);
1292
- // If the new control is found, emit event to server to replace node
1293
- if (newControl.length === 1) {
1294
- window.ProcessMaker.EventBus.$emit('multiplayer-replaceNode', { nodeData, newControl: newControl[0].type });
1295
- }
1296
- } else {
1297
- await this.replaceNodeProcedure(nodeData, true);
1298
- }
1314
+ await this.replaceNodeProcedure(nodeData);
1299
1315
  });
1300
1316
  });
1301
1317
  },
1302
1318
  async replaceNodeProcedure(data, isReplaced = false) {
1303
- if (isReplaced) {
1304
- // Get the clientX and clientY from the node that will be replaced
1305
- const { x: clientX, y: clientY } = this.paper.localToClientPoint(data.nodeThatWillBeReplaced.diagram.bounds);
1306
- data.clientX = clientX;
1307
- data.clientY = clientY;
1308
- }
1319
+ // Get the clientX and clientY from the node that will be replaced
1320
+ const { x: clientX, y: clientY } = this.paper.localToClientPoint(data.nodeThatWillBeReplaced.diagram.bounds);
1321
+ data.clientX = clientX;
1322
+ data.clientY = clientY;
1309
1323
 
1310
1324
  const newNode = await this.handleDrop(data);
1311
1325
 
1312
1326
  await this.removeNode(data.nodeThatWillBeReplaced, { removeRelationships: false, isReplaced });
1313
1327
  this.highlightNode(newNode);
1314
1328
  this.selectNewNode(newNode);
1329
+
1330
+ if (this.isMultiplayer && !isReplaced) {
1331
+ // Get all node types
1332
+ const nodeTypes = nodeTypesStore.getters.getNodeTypes;
1333
+ // Get the new control
1334
+ const newControl = nodeTypes.flatMap(nodeType => {
1335
+ return nodeType.items?.filter(item => item.type === data.typeToReplaceWith);
1336
+ }).filter(Boolean);
1337
+ // If the new control is found, emit event to server to replace node
1338
+ if (newControl.length === 1) {
1339
+ window.ProcessMaker.EventBus.$emit('multiplayer-replaceNode', { data, newControl: newControl[0].type });
1340
+ }
1341
+ }
1315
1342
  },
1316
1343
  replaceAiNode({ node, typeToReplaceWith, assetId, assetName, redirectTo }) {
1317
1344
  this.performSingleUndoRedoTransaction(async() => {
@@ -1728,6 +1755,7 @@ export default {
1728
1755
  try {
1729
1756
  const multiplayer = new Multiplayer(this);
1730
1757
  multiplayer.init();
1758
+ this.multiplayer = multiplayer;
1731
1759
  } catch (error) {
1732
1760
  console.warn('Could not initialize multiplayer', error);
1733
1761
  }
@@ -66,6 +66,26 @@ export default class Multiplayer {
66
66
  this.modeler.enableMultiplayer(payload.isMultiplayer);
67
67
  });
68
68
 
69
+ this.clientIO.on('requestProcess', (payload) => {
70
+ const { firstClient, clientId } = payload;
71
+
72
+ // Check if the current client is the first client
73
+ if (firstClient.id === this.clientIO.id) {
74
+ // Get the process definition
75
+ const nodes = this.modeler.nodes.map((node) => this.modeler.multiplayerHook(node, false, true));
76
+
77
+ nodes.forEach((node) => {
78
+ const yMapNested = new Y.Map();
79
+ this.doTransact(yMapNested, node);
80
+ this.yArray.push([yMapNested]);
81
+ // Encode the state as an update and send it to the server
82
+ const stateUpdate = Y.encodeStateAsUpdate(this.yDoc);
83
+ // Send the update to the web socket server
84
+ this.clientIO.emit('createElement', { updateDoc: stateUpdate, clientId });
85
+ });
86
+ }
87
+ });
88
+
69
89
  // Listen for updates when a new element is added
70
90
  this.clientIO.on('createElement', async(payload) => {
71
91
  // Create the new element in the process
@@ -74,6 +94,16 @@ export default class Multiplayer {
74
94
  Y.applyUpdate(this.yDoc, new Uint8Array(payload.updateDoc));
75
95
  });
76
96
 
97
+ // Listen for updates when a new element is requested
98
+ this.clientIO.on('createRequestedElement', async(payload) => {
99
+ if (payload.clientId === this.clientIO.id) {
100
+ // Create the new element in the process
101
+ await this.createRemoteShape(payload.changes);
102
+ // Add the new element to the shared array
103
+ Y.applyUpdate(this.yDoc, new Uint8Array(payload.updateDoc));
104
+ }
105
+ });
106
+
77
107
  // Listen for updates when an element is removed
78
108
  this.clientIO.on('removeElement', (payload) => {
79
109
  payload.deletedNodes.forEach(nodeId => {
@@ -135,7 +165,7 @@ export default class Multiplayer {
135
165
  // Encode the state as an update and send it to the server
136
166
  const stateUpdate = Y.encodeStateAsUpdate(this.yDoc);
137
167
  // Send the update to the web socket server
138
- this.clientIO.emit('createElement', stateUpdate);
168
+ this.clientIO.emit('createElement', { updateDoc: stateUpdate });
139
169
  }
140
170
  createShape(value){
141
171
  if (this.modeler.nodeRegistry[value.type] && this.modeler.nodeRegistry[value.type].multiplayerClient) {
@@ -315,7 +345,7 @@ export default class Multiplayer {
315
345
  // Encode the state as an update and send it to the server
316
346
  const stateUpdate = Y.encodeStateAsUpdate(this.yDoc);
317
347
  // Send the update to the web socket server
318
- this.clientIO.emit('createElement', stateUpdate);
348
+ this.clientIO.emit('createElement', { updateDoc: stateUpdate });
319
349
  this.#nodeIdGenerator.updateCounters();
320
350
  }
321
351
 
@@ -338,7 +368,7 @@ export default class Multiplayer {
338
368
  this.doTransact(yMapNested, data);
339
369
  this.yArray.push([yMapNested]);
340
370
  const stateUpdate = Y.encodeStateAsUpdate(this.yDoc);
341
- this.clientIO.emit('createElement', stateUpdate);
371
+ this.clientIO.emit('createElement', { updateDoc: stateUpdate });
342
372
  });
343
373
  });
344
374
  }