@processmaker/modeler 1.42.1 → 1.43.1

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,7 @@
1
1
  <template>
2
2
  <span
3
3
  class="b-avatar rounded-circle"
4
- :style="{'backgroundColor': generateColorHsl(userName, saturationRange, lightnessRange)}"
4
+ :style="{'backgroundColor': backgroundColor}"
5
5
  >
6
6
  <span v-if="imgSrc" class="b-avatar-img" :id="id">
7
7
  <img :src="imgSrc" :alt="userName">
@@ -46,16 +46,9 @@ export default {
46
46
  saturation: 50,
47
47
  lightness: 50,
48
48
  range: 10,
49
+ backgroundColor: '#104A75',
49
50
  };
50
51
  },
51
- computed: {
52
- saturationRange() {
53
- return this.getRange(this.saturation, this.range);
54
- },
55
- lightnessRange() {
56
- return this.getRange(this.lightness, this.range);
57
- },
58
- },
59
52
  methods: {
60
53
  /**
61
54
  * Get the initials from a given name.
@@ -69,73 +62,6 @@ export default {
69
62
  const lastNameIn = nameArray[nameArray.length - 1].charAt(0).toUpperCase();
70
63
  return `${firstNameIn}${lastNameIn}`;
71
64
  },
72
- /**
73
- * Calculates a hash value for a given string.
74
- *
75
- * @param {string} str - The input string for which the hash needs to be calculated.
76
- * @returns {number} The calculated hash value for the input string.
77
- */
78
- getHashOfString(str){
79
- let hash = 0;
80
- for (let i = 0; i < str.length; i++) {
81
- hash = str.charCodeAt(i) + ((hash << 5) - hash);
82
- }
83
- hash = Math.abs(hash);
84
- return hash;
85
- },
86
- /**
87
- * Calculates a range around a given value.
88
- *
89
- * @param {number} value - The central value.
90
- * @param {number} range - The range value.
91
- * @returns {number[]} An array containing the lower and upper bounds of the range.
92
- */
93
- getRange(value, range) {
94
- return [Math.max(0, value-range), Math.min(value + range, 100)];
95
- },
96
- /**
97
- * Get the hash number to within our range
98
- *
99
- * @param {Number} hash
100
- * @param {Number} min
101
- * @param {Number} max
102
- * @returns {Number}
103
- */
104
- normalizeHash(hash, min, max){
105
- return Math.floor((hash % (max - min)) + min);
106
- },
107
- /**
108
- *Generate Unique Color, create a string using our h,s,l values.
109
- * @param {String} name
110
- * @param {Array} saturationRange
111
- * @param {Array} lightnessRange
112
- * @returns {Number}
113
- */
114
- generateHSL(name, saturationRange, lightnessRange) {
115
- const hash = this.getHashOfString(name);
116
- const h = this.normalizeHash(hash, 0, 360);
117
- const s = this.normalizeHash(hash, saturationRange[0], saturationRange[1]);
118
- const l = this.normalizeHash(hash, lightnessRange[0], lightnessRange[1]);
119
- return [h, s, l];
120
- },
121
- /**
122
- * Convert HSL array to string
123
- * @param {Array} hsl
124
- * @returns {String}
125
- */
126
- HSLtoString(hsl) {
127
- return `hsl(${hsl[0]}, ${hsl[1]}%, ${hsl[2]}%)`;
128
- },
129
- /**
130
- * Generate a unique hsl value.
131
- * @param {String} name
132
- * @param {Array} saturationRange
133
- * @param {Array} lightnessRange
134
- * @returns {String}
135
- */
136
- generateColorHsl(id, saturationRange, lightnessRange) {
137
- return this.HSLtoString(this.generateHSL(id, saturationRange, lightnessRange));
138
- },
139
65
  },
140
66
  };
141
67
 
@@ -2,5 +2,4 @@
2
2
  text-align: center;
3
3
  line-height: 2.4rem;
4
4
  color: #ffffff;
5
- font-weight: bold;
6
5
  }
@@ -148,7 +148,7 @@ export default {
148
148
  },
149
149
  };
150
150
  </script>
151
- <style>
151
+ <style scoped>
152
152
  .message {
153
153
  color: #5f666d;
154
154
  font-style: italic;
@@ -187,11 +187,6 @@ export default {
187
187
  border-color: #0872C2;
188
188
  }
189
189
 
190
- .ai-icon {
191
- width: 22px;
192
- height: 22px;
193
- }
194
-
195
190
  .ai-icon {
196
191
  width: 22px;
197
192
  height: 22px;
@@ -86,6 +86,9 @@ export default {
86
86
  tempGhost.src = control.icon;
87
87
  } else {
88
88
  tempGhost.setAttribute('class', control.icon);
89
+ tempGhost.style.fontSize = '42px';
90
+ tempGhost.style.width = '42px';
91
+ tempGhost.style.height = '42px';
89
92
  }
90
93
 
91
94
  document.body.appendChild(tempGhost);
@@ -6,7 +6,7 @@ import Room from './room';
6
6
  import store from '@/store';
7
7
  import { getBoundaryEventData } from '@/components/nodes/boundaryEvent/boundaryEventUtils';
8
8
  import { InspectorUtils } from './inspector.utils';
9
-
9
+ import ColorUtil from '../colorUtil';
10
10
  export default class Multiplayer {
11
11
  clientIO = null;
12
12
  yDoc = null;
@@ -16,7 +16,7 @@ export default class Multiplayer {
16
16
  room = null;
17
17
  inspector = null;
18
18
  deletedItem = null;
19
-
19
+ colorUtil = null;
20
20
  constructor(modeler) {
21
21
  // define document
22
22
  this.yDoc = new Y.Doc();
@@ -42,33 +42,28 @@ export default class Multiplayer {
42
42
  } else {
43
43
  this.clientIO.disconnect();
44
44
  }
45
+ this.colorUtil = new ColorUtil(50, 50, 10);
45
46
  }
47
+
46
48
  webSocketEvents() {
47
49
  this.clientIO.on('connect', () => {
48
50
  // Join the room
51
+ this.modeler.emptyPlayers();
49
52
  this.clientIO.emit('joinRoom', {
50
53
  roomName: this.room.getRoom(),
51
54
  clientName: window.ProcessMaker.user?.fullName,
52
55
  clientAvatar: window.ProcessMaker.user?.avatar,
56
+ clientColor: window.ProcessMaker.user?.color || this.colorUtil.randomColor(window.ProcessMaker.user?.fullName),
57
+ clientCursor: {
58
+ top: 300,
59
+ left: 300,
60
+ },
53
61
  });
54
62
  });
55
63
 
56
64
  this.clientIO.on('clientJoined', (payload) => {
57
65
  this.modeler.enableMultiplayer(payload.isMultiplayer);
58
-
59
- if (payload.isMultiplayer) {
60
- payload.clients.map(client => {
61
- const newPlayer = {
62
- id: client.id,
63
- name: client.name,
64
- color: client.color,
65
- avatar: client.avatar || null,
66
- top: 90,
67
- left: 80,
68
- };
69
- this.modeler.addPlayer(newPlayer);
70
- });
71
- }
66
+ this.addPlayers(payload);
72
67
  });
73
68
 
74
69
  this.clientIO.on('clientLeft', (payload) => {
@@ -85,6 +80,10 @@ export default class Multiplayer {
85
80
  this.syncLocalNodes(clientId);
86
81
  }
87
82
  });
83
+
84
+ this.clientIO.on('updateUserCursor', async(payload) => {
85
+ this.updateClientCursor(payload);
86
+ });
88
87
 
89
88
  // Listen for updates when a new element is added
90
89
  this.clientIO.on('createElement', async(payload) => {
@@ -198,6 +197,49 @@ export default class Multiplayer {
198
197
  this.updateFlows(data);
199
198
  }
200
199
  });
200
+ window.ProcessMaker.EventBus.$on('multiplayer-updateMousePosition', ( data ) => {
201
+ if (this.modeler.isMultiplayer) {
202
+ this.updateMousePosition(data);
203
+ }
204
+ });
205
+ }
206
+ /**
207
+ * Add a Player
208
+ * @param {Object} payload
209
+ */
210
+ addPlayers(payload) {
211
+ if (payload.isMultiplayer) {
212
+ payload.clients.map(client => {
213
+ const newPlayer = {
214
+ id: client.id,
215
+ name: client.name,
216
+ color: client.color,
217
+ avatar: client.avatar,
218
+ cursor: client.cursor,
219
+ };
220
+ this.modeler.addPlayer(newPlayer);
221
+ });
222
+ }
223
+ }
224
+ /**
225
+ * Updates the mouse position
226
+ * @param {Object} data
227
+ */
228
+ updateMousePosition(data) {
229
+ this.clientIO.emit('cursorTrackingUpdate', {
230
+ roomName: this.room.getRoom(),
231
+ clientId: this.clientIO.id,
232
+ clientCursor: data,
233
+ });
234
+ }
235
+ /**
236
+ * Update Client cursor handler
237
+ * @param {Object} payload
238
+ */
239
+ updateClientCursor(payload){
240
+ payload.clients.map(client => {
241
+ this.modeler.updateClientCursor(client);
242
+ });
201
243
  }
202
244
  /**
203
245
  * Sync the modeler nodes with the microservice