Add group component [#46]

This commit is contained in:
David Evans 2018-02-04 15:33:48 +00:00
parent e22381e37d
commit d283fe158c
14 changed files with 100 additions and 44 deletions

View File

@ -871,6 +871,14 @@ define('sequence/CodeMirrorMode',['core/ArrayUtilities'], (array) => {
}, connectors))); }, connectors)));
} }
const group = {type: 'keyword', suggest: true, then: {
'': textToEnd,
':': {type: 'operator', suggest: true, then: {
'': textToEnd,
}},
'\n': end,
}};
const BASE_THEN = { const BASE_THEN = {
'title': {type: 'keyword', suggest: true, then: { 'title': {type: 'keyword', suggest: true, then: {
'': textToEnd, '': textToEnd,
@ -922,13 +930,7 @@ define('sequence/CodeMirrorMode',['core/ArrayUtilities'], (array) => {
'as': CM_ERROR, 'as': CM_ERROR,
'\n': end, '\n': end,
}}, }},
'if': {type: 'keyword', suggest: true, then: { 'if': group,
'': textToEnd,
':': {type: 'operator', suggest: true, then: {
'': textToEnd,
}},
'\n': end,
}},
'else': {type: 'keyword', suggest: ['else\n', 'else if: '], then: { 'else': {type: 'keyword', suggest: ['else\n', 'else if: '], then: {
'if': {type: 'keyword', suggest: 'if: ', then: { 'if': {type: 'keyword', suggest: 'if: ', then: {
'': textToEnd, '': textToEnd,
@ -938,13 +940,8 @@ define('sequence/CodeMirrorMode',['core/ArrayUtilities'], (array) => {
}}, }},
'\n': end, '\n': end,
}}, }},
'repeat': {type: 'keyword', suggest: true, then: { 'repeat': group,
'': textToEnd, 'group': group,
':': {type: 'operator', suggest: true, then: {
'': textToEnd,
}},
'\n': end,
}},
'note': {type: 'keyword', suggest: true, then: { 'note': {type: 'keyword', suggest: true, then: {
'over': {type: 'keyword', suggest: true, then: { 'over': {type: 'keyword', suggest: true, then: {
'': agentListToText, '': agentListToText,
@ -1684,6 +1681,12 @@ define('sequence/Parser',[
tag: 'repeat', tag: 'repeat',
skip: [], skip: [],
}, },
'group': {
type: 'block begin',
blockType: 'group',
tag: '',
skip: [],
},
}; };
const CONNECT = { const CONNECT = {
@ -4074,7 +4077,10 @@ define('sequence/components/Block',[
SVGTextBlockClass: env.SVGTextBlockClass, SVGTextBlockClass: env.SVGTextBlockClass,
}); });
const labelHeight = Math.max(tagRender.height, labelRender.height); const labelHeight = Math.max(
Math.max(tagRender.height, labelRender.height),
config.section.label.minHeight
);
clickable.insertBefore(svg.make('rect', { clickable.insertBefore(svg.make('rect', {
'x': agentInfoL.x, 'x': agentInfoL.x,
@ -7289,11 +7295,12 @@ define('sequence/themes/Basic',[
}, },
}, },
label: { label: {
minHeight: 4,
padding: { padding: {
top: 1, top: 1,
left: 5, left: 5,
right: 3, right: 3,
bottom: 0, bottom: 1,
}, },
labelAttrs: { labelAttrs: {
'font-family': FONT, 'font-family': FONT,
@ -7684,6 +7691,7 @@ define('sequence/themes/Monospace',[
}, },
}, },
label: { label: {
minHeight: 8,
padding: { padding: {
top: 2, top: 2,
left: 8, left: 8,
@ -8077,11 +8085,12 @@ define('sequence/themes/Chunky',[
}, },
}, },
label: { label: {
minHeight: 5,
padding: { padding: {
top: 2, top: 2,
left: 5, left: 5,
right: 3, right: 3,
bottom: 0, bottom: 1,
}, },
labelAttrs: { labelAttrs: {
'font-family': FONT, 'font-family': FONT,
@ -8889,11 +8898,12 @@ define('sequence/themes/Sketch',[
}, },
}, },
label: { label: {
minHeight: 6,
padding: { padding: {
top: 2, top: 2,
left: 5, left: 5,
right: 3, right: 3,
bottom: 0, bottom: 1,
}, },
labelAttrs: { labelAttrs: {
'font-family': FONT_FAMILY, 'font-family': FONT_FAMILY,

File diff suppressed because one or more lines are too long

View File

@ -141,6 +141,20 @@ define([], [
'end myRef' 'end myRef'
), ),
}, },
{
title: 'Group',
code: (
'group {Label}\n' +
' {Agent1} -> {Agent2}\n' +
'end'
),
preview: (
'begin A, B\n' +
'group Label\n' +
' A -> B\n' +
'end'
),
},
{ {
title: 'Note over agent', title: 'Note over agent',
code: 'note over {Agent1}: {Message}', code: 'note over {Agent1}: {Message}',

View File

@ -268,6 +268,14 @@ define(['core/ArrayUtilities'], (array) => {
}, connectors))); }, connectors)));
} }
const group = {type: 'keyword', suggest: true, then: {
'': textToEnd,
':': {type: 'operator', suggest: true, then: {
'': textToEnd,
}},
'\n': end,
}};
const BASE_THEN = { const BASE_THEN = {
'title': {type: 'keyword', suggest: true, then: { 'title': {type: 'keyword', suggest: true, then: {
'': textToEnd, '': textToEnd,
@ -319,13 +327,7 @@ define(['core/ArrayUtilities'], (array) => {
'as': CM_ERROR, 'as': CM_ERROR,
'\n': end, '\n': end,
}}, }},
'if': {type: 'keyword', suggest: true, then: { 'if': group,
'': textToEnd,
':': {type: 'operator', suggest: true, then: {
'': textToEnd,
}},
'\n': end,
}},
'else': {type: 'keyword', suggest: ['else\n', 'else if: '], then: { 'else': {type: 'keyword', suggest: ['else\n', 'else if: '], then: {
'if': {type: 'keyword', suggest: 'if: ', then: { 'if': {type: 'keyword', suggest: 'if: ', then: {
'': textToEnd, '': textToEnd,
@ -335,13 +337,8 @@ define(['core/ArrayUtilities'], (array) => {
}}, }},
'\n': end, '\n': end,
}}, }},
'repeat': {type: 'keyword', suggest: true, then: { 'repeat': group,
'': textToEnd, 'group': group,
':': {type: 'operator', suggest: true, then: {
'': textToEnd,
}},
'\n': end,
}},
'note': {type: 'keyword', suggest: true, then: { 'note': {type: 'keyword', suggest: true, then: {
'over': {type: 'keyword', suggest: true, then: { 'over': {type: 'keyword', suggest: true, then: {
'': agentListToText, '': agentListToText,

View File

@ -239,7 +239,8 @@ defineDescribe('Code Mirror Mode', [
'else if another thing\n' + 'else if another thing\n' +
'else\n' + 'else\n' +
'end\n' + 'end\n' +
'repeat a few times' 'repeat a few times\n' +
'group foo\n'
); );
expect(getTokens(0)).toEqual([ expect(getTokens(0)).toEqual([
@ -272,6 +273,11 @@ defineDescribe('Code Mirror Mode', [
{v: ' few', type: 'string'}, {v: ' few', type: 'string'},
{v: ' times', type: 'string'}, {v: ' times', type: 'string'},
]); ]);
expect(getTokens(6)).toEqual([
{v: 'group', type: 'keyword'},
{v: ' foo', type: 'string'},
]);
}); });
it('allows colons in block statements', () => { it('allows colons in block statements', () => {
@ -428,6 +434,7 @@ defineDescribe('Code Mirror Mode', [
expect(hints).toContain('else\n'); expect(hints).toContain('else\n');
expect(hints).toContain('else if: '); expect(hints).toContain('else if: ');
expect(hints).toContain('repeat '); expect(hints).toContain('repeat ');
expect(hints).toContain('group ');
expect(hints).toContain('note '); expect(hints).toContain('note ');
expect(hints).toContain('state over '); expect(hints).toContain('state over ');
expect(hints).toContain('text '); expect(hints).toContain('text ');

View File

@ -30,6 +30,12 @@ define([
tag: 'repeat', tag: 'repeat',
skip: [], skip: [],
}, },
'group': {
type: 'block begin',
blockType: 'group',
tag: '',
skip: [],
},
}; };
const CONNECT = { const CONNECT = {

View File

@ -749,6 +749,17 @@ defineDescribe('Sequence Parser', ['./Parser'], (Parser) => {
]); ]);
}); });
it('converts group blocks', () => {
const parsed = parser.parse('group something');
expect(parsed.stages).toEqual([
PARSED.blockBegin({
blockType: 'group',
tag: '',
label: 'something',
}),
]);
});
it('rejects quoted keywords', () => { it('rejects quoted keywords', () => {
expect(() => parser.parse('"repeat" until something')).toThrow(); expect(() => parser.parse('"repeat" until something')).toThrow();
}); });

View File

@ -145,11 +145,11 @@ defineDescribe('SequenceDiagram', [
const content = getSimplifiedContent(diagram); const content = getSimplifiedContent(diagram);
expect(content).toContain('<svg viewBox="-5 -5 60 37">'); expect(content).toContain('<svg viewBox="-5 -5 60 39">');
expect(content).toContain('<line x1="20" y1="5" x2="20" y2="27"'); expect(content).toContain('<line x1="20" y1="7" x2="20" y2="29"');
expect(content).toContain('<line x1="30" y1="5" x2="30" y2="27"'); expect(content).toContain('<line x1="30" y1="7" x2="30" y2="29"');
expect(content).toContain('<rect x="10" y="0" width="30" height="7"'); expect(content).toContain('<rect x="10" y="0" width="30" height="9"');
expect(content).toContain('<g class="region collapsed"'); expect(content).toContain('<g class="region collapsed"');
}); });

View File

@ -69,7 +69,10 @@ define([
SVGTextBlockClass: env.SVGTextBlockClass, SVGTextBlockClass: env.SVGTextBlockClass,
}); });
const labelHeight = Math.max(tagRender.height, labelRender.height); const labelHeight = Math.max(
Math.max(tagRender.height, labelRender.height),
config.section.label.minHeight
);
clickable.insertBefore(svg.make('rect', { clickable.insertBefore(svg.make('rect', {
'x': agentInfoL.x, 'x': agentInfoL.x,

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@ -216,11 +216,12 @@ define([
}, },
}, },
label: { label: {
minHeight: 4,
padding: { padding: {
top: 1, top: 1,
left: 5, left: 5,
right: 3, right: 3,
bottom: 0, bottom: 1,
}, },
labelAttrs: { labelAttrs: {
'font-family': FONT, 'font-family': FONT,

View File

@ -227,11 +227,12 @@ define([
}, },
}, },
label: { label: {
minHeight: 5,
padding: { padding: {
top: 2, top: 2,
left: 5, left: 5,
right: 3, right: 3,
bottom: 0, bottom: 1,
}, },
labelAttrs: { labelAttrs: {
'font-family': FONT, 'font-family': FONT,

View File

@ -223,6 +223,7 @@ define([
}, },
}, },
label: { label: {
minHeight: 8,
padding: { padding: {
top: 2, top: 2,
left: 8, left: 8,

View File

@ -200,11 +200,12 @@ define([
}, },
}, },
label: { label: {
minHeight: 6,
padding: { padding: {
top: 2, top: 2,
left: 5, left: 5,
right: 3, right: 3,
bottom: 0, bottom: 1,
}, },
labelAttrs: { labelAttrs: {
'font-family': FONT_FAMILY, 'font-family': FONT_FAMILY,