diff --git a/packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison b/packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison index 78b0c9ed9e..17be25a7a4 100644 --- a/packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison +++ b/packages/mermaid/src/diagrams/sequence/parser/sequenceDiagram.jison @@ -3,7 +3,7 @@ * (c) 2014-2015 Knut Sveidqvist * MIT license. * - * Based on js sequence diagrams jison grammr + * Based on js sequence diagrams jison grammer * https://bramp.github.io/js-sequence-diagrams/ * (c) 2012-2013 Andrew Brampton (bramp.net) * Simplified BSD license. diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDb.ts b/packages/mermaid/src/diagrams/sequence/sequenceDb.ts index 03d3210aa9..5a0916729b 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDb.ts +++ b/packages/mermaid/src/diagrams/sequence/sequenceDb.ts @@ -115,17 +115,16 @@ const activationCount = (part: string) => { if (!part) { return 0; } - for (i = 0; i < state.records.messages.length; i++) { if ( state.records.messages[i].type === LINETYPE.ACTIVE_START && - state.records.messages[i].from?.actor === part + state.records.messages[i].from === part ) { count++; } if ( state.records.messages[i].type === LINETYPE.ACTIVE_END && - state.records.messages[i].from?.actor === part + state.records.messages[i].from === part ) { count--; } @@ -156,12 +155,10 @@ export const addSignal = function ( activate: boolean = false ) { if (messageType === LINETYPE.ACTIVE_END) { - const cnt = activationCount(idFrom?.actor || ''); + const cnt = activationCount(idFrom || ''); if (cnt < 1) { // Bail out as there is an activation signal from an inactive participant - const error = new Error( - 'Trying to inactivate an inactive participant (' + idFrom?.actor + ')' - ); + const error = new Error('Trying to inactivate an inactive participant (' + idFrom + ')'); // @ts-ignore: we are passing hash param to the error object, however we should define our own custom error class to make it type safe error.hash = { @@ -516,10 +513,10 @@ export const apply = function (param: any | AddMessageParams | AddMessageParams[ state.records.destroyedActors[param.actor] = state.records.messages.length; break; case 'activeStart': - addSignal(param.actor, undefined, undefined, param.signalType); + addSignal(param.actor.actor, undefined, undefined, param.signalType); break; case 'activeEnd': - addSignal(param.actor, undefined, undefined, param.signalType); + addSignal(param.actor.actor, undefined, undefined, param.signalType); break; case 'addNote': addNote(param.actor, param.placement, param.text); diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js index 1724391e53..f27dd49d78 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js +++ b/packages/mermaid/src/diagrams/sequence/sequenceDiagram.spec.js @@ -534,10 +534,10 @@ deactivate Bob`; expect(messages.length).toBe(4); expect(messages[0].type).toBe(diagram.db.LINETYPE.DOTTED); expect(messages[1].type).toBe(diagram.db.LINETYPE.ACTIVE_START); - expect(messages[1].from.actor).toBe('Bob'); + expect(messages[1].from).toBe('Bob'); expect(messages[2].type).toBe(diagram.db.LINETYPE.DOTTED); expect(messages[3].type).toBe(diagram.db.LINETYPE.ACTIVE_END); - expect(messages[3].from.actor).toBe('Bob'); + expect(messages[3].from).toBe('Bob'); }); it('should handle actor one line notation activation', async () => { const str = ` @@ -556,10 +556,10 @@ deactivate Bob`; expect(messages[0].type).toBe(diagram.db.LINETYPE.DOTTED); expect(messages[0].activate).toBeTruthy(); expect(messages[1].type).toBe(diagram.db.LINETYPE.ACTIVE_START); - expect(messages[1].from.actor).toBe('Bob'); + expect(messages[1].from).toBe('Bob'); expect(messages[2].type).toBe(diagram.db.LINETYPE.DOTTED); expect(messages[3].type).toBe(diagram.db.LINETYPE.ACTIVE_END); - expect(messages[3].from.actor).toBe('Bob'); + expect(messages[3].from).toBe('Bob'); }); it('should handle stacked activations', async () => { const str = ` @@ -579,14 +579,14 @@ deactivate Bob`; expect(messages.length).toBe(8); expect(messages[0].type).toBe(diagram.db.LINETYPE.DOTTED); expect(messages[1].type).toBe(diagram.db.LINETYPE.ACTIVE_START); - expect(messages[1].from.actor).toBe('Bob'); + expect(messages[1].from).toBe('Bob'); expect(messages[2].type).toBe(diagram.db.LINETYPE.DOTTED); expect(messages[3].type).toBe(diagram.db.LINETYPE.ACTIVE_START); - expect(messages[3].from.actor).toBe('Carol'); + expect(messages[3].from).toBe('Carol'); expect(messages[5].type).toBe(diagram.db.LINETYPE.ACTIVE_END); - expect(messages[5].from.actor).toBe('Bob'); + expect(messages[5].from).toBe('Bob'); expect(messages[7].type).toBe(diagram.db.LINETYPE.ACTIVE_END); - expect(messages[7].from.actor).toBe('Carol'); + expect(messages[7].from).toBe('Carol'); }); it('should handle fail parsing when activating an inactive participant', async () => { const str = ` diff --git a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts index 98fdcddc40..e91c1f906a 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts +++ b/packages/mermaid/src/diagrams/sequence/sequenceRenderer.ts @@ -144,15 +144,15 @@ export const bounds = { this.updateBounds(_startx, _starty, _stopx, _stopy); }, newActivation: function (message, diagram, actors) { - const actorRect = actors[message.from.actor]; - const stackedSize = actorActivations(message.from.actor).length || 0; + const actorRect = actors[message.from]; + const stackedSize = actorActivations(message.from).length || 0; const x = actorRect.x + actorRect.width / 2 + ((stackedSize - 1) * conf.activationWidth) / 2; this.activations.push({ startx: x, starty: this.verticalPos + 2, stopx: x + conf.activationWidth, stopy: undefined, - actor: message.from.actor, + actor: message.from, anchored: svgDraw.anchorElement(diagram), }); }, @@ -162,7 +162,7 @@ export const bounds = { .map(function (activation) { return activation.actor; }) - .lastIndexOf(message.from.actor); + .lastIndexOf(message.from); return this.activations.splice(lastActorActivationIdx, 1)[0]; }, createLoop: function (title = { message: undefined, wrap: false, width: undefined }, fill) { @@ -836,7 +836,7 @@ export const draw = async function (_text: string, id: string, _version: string, activationData, verticalPos, conf, - actorActivations(msg.from.actor).length + actorActivations(msg.from).length ); bounds.insert(activationData.startx, verticalPos - 10, activationData.stopx, verticalPos); @@ -1545,14 +1545,14 @@ const calculateLoopBounds = async function (messages, actors, _maxWidthPerActor, break; case diagObj.db.LINETYPE.ACTIVE_START: { - const actorRect = actors[msg.from ? msg.from.actor : msg.to.actor]; - const stackedSize = actorActivations(msg.from ? msg.from.actor : msg.to.actor).length; + const actorRect = actors[msg.from ? msg.from : msg.to.actor]; + const stackedSize = actorActivations(msg.from ? msg.from : msg.to.actor).length; const x = actorRect.x + actorRect.width / 2 + ((stackedSize - 1) * conf.activationWidth) / 2; const toAdd = { startx: x, stopx: x + conf.activationWidth, - actor: msg.from.actor, + actor: msg.from, enabled: true, }; bounds.activations.push(toAdd); @@ -1562,7 +1562,7 @@ const calculateLoopBounds = async function (messages, actors, _maxWidthPerActor, { const lastActorActivationIdx = bounds.activations .map((a) => a.actor) - .lastIndexOf(msg.from.actor); + .lastIndexOf(msg.from); delete bounds.activations.splice(lastActorActivationIdx, 1)[0]; } break; diff --git a/packages/mermaid/src/diagrams/sequence/types.ts b/packages/mermaid/src/diagrams/sequence/types.ts index 754df95e3f..5cc6ae249c 100644 --- a/packages/mermaid/src/diagrams/sequence/types.ts +++ b/packages/mermaid/src/diagrams/sequence/types.ts @@ -20,8 +20,8 @@ export interface Actor { } export interface Message { - from?: { actor: string }; - to?: { actor: string }; + from?: string; + to?: string; message: | string | {