Skip to content

Commit 7bd63dc

Browse files
committed
component extensions.
1 parent 6ee5711 commit 7bd63dc

File tree

59 files changed

+448
-252
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+448
-252
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.3.0
2+
3+
This version introduces component extensions. By this it's possible to create own components. Breaking changes:
4+
5+
* Static method `Designer.utils.getParents()` is deleted. You should use the `getStepParents()` method from the `Designer` class. Example: `designer.getStepParents(needleStep)`
6+
* The `ComponentType` is not an enum anymore. It's type (`string`). This change doesn't affect serialized JSONs.
7+
18
## 0.2.3
29

310
Improved rendering of the switch step for 3 and more branches.

designer/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"test:single": "karma start --single-run",
2323
"eslint": "eslint ./src --ext .ts",
2424
"prettier": "prettier --check ./src",
25-
"prettier:fix": "prettier --write ./src",
26-
"serve": "http-server ./"
25+
"prettier:fix": "prettier --write ./src"
2726
},
2827
"author": "b4rtaz",
2928
"license": "MIT",
@@ -32,7 +31,6 @@
3231
"@typescript-eslint/eslint-plugin": "^5.40.0",
3332
"@typescript-eslint/parser": "^5.40.0",
3433
"eslint": "^8.25.0",
35-
"http-server": "^14.1.1",
3634
"karma": "^6.3.20",
3735
"karma-chrome-launcher": "^3.1.1",
3836
"karma-jasmine": "^5.0.1",

designer/src/behaviors/drag-step-behavior-view.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createDesignerConfigurationStub, createStepStub } from '../test-tools/stubs';
1+
import { createComponentContextStub, createDesignerConfigurationStub, createStepStub } from '../test-tools/stubs';
22
import { DragStepView } from './drag-step-behavior-view';
33

44
describe('DragStepView', () => {
@@ -7,8 +7,9 @@ describe('DragStepView', () => {
77

88
const step = createStepStub();
99
const configuration = createDesignerConfigurationStub();
10+
const context = createComponentContextStub();
1011

11-
const component = DragStepView.create(step, configuration);
12+
const component = DragStepView.create(step, configuration, context);
1213

1314
expect(component).toBeDefined();
1415
expect(appendChildSpy).toHaveBeenCalled();

designer/src/behaviors/drag-step-behavior-view.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Dom } from '../core/dom';
22
import { Vector } from '../core/vector';
33
import { Sequence, Step } from '../definition';
44
import { DesignerConfiguration } from '../designer-configuration';
5-
import { StepComponentFactory } from '../workspace/step-component-factory';
5+
import { ComponentContext } from '../workspace/component-context';
66

77
const SAFE_OFFSET = 10;
88

99
export class DragStepView {
10-
public static create(step: Step, configuration: DesignerConfiguration): DragStepView {
10+
public static create(step: Step, configuration: DesignerConfiguration, context: ComponentContext): DragStepView {
1111
const theme = configuration.theme || 'light';
1212
const layer = Dom.element('div', {
1313
class: `sqd-drag sqd-theme-${theme}`
@@ -18,7 +18,7 @@ export class DragStepView {
1818
layer.appendChild(canvas);
1919

2020
const fakeSequence: Sequence = [];
21-
const stepComponent = StepComponentFactory.create(canvas, step, fakeSequence, configuration.steps);
21+
const stepComponent = context.stepComponentFactory.create(canvas, step, fakeSequence, context);
2222

2323
Dom.attrs(canvas, {
2424
width: stepComponent.view.width + SAFE_OFFSET * 2,

designer/src/behaviors/drag-step-behavior.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@ import { PlaceholderFinder } from './placeholder-finder';
88
import { DesignerState } from '../designer-state';
99
import { DefinitionModifier } from '../definition-modifier';
1010
import { WorkspaceController } from '../workspace/workspace-controller';
11+
import { ComponentContext } from '../workspace/component-context';
1112

1213
export class DragStepBehavior implements Behavior {
13-
public static create(context: DesignerContext, step: Step, movingStepComponent?: StepComponent): DragStepBehavior {
14-
const view = DragStepView.create(step, context.configuration);
14+
public static create(
15+
designerContext: DesignerContext,
16+
componentContext: ComponentContext,
17+
step: Step,
18+
movingStepComponent?: StepComponent
19+
): DragStepBehavior {
20+
const view = DragStepView.create(step, designerContext.configuration, componentContext);
1521
return new DragStepBehavior(
1622
view,
17-
context.workspaceController,
18-
context.state,
23+
designerContext.workspaceController,
24+
designerContext.state,
1925
step,
20-
context.definitionModifier,
26+
designerContext.definitionModifier,
2127
movingStepComponent
2228
);
2329
}

designer/src/behaviors/select-step-behavior.spec.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Step } from '../definition';
2-
import { createDesignerContextStub, createStepStub } from '../test-tools/stubs';
2+
import { createComponentContextStub, createDesignerContextStub, createStepStub } from '../test-tools/stubs';
33
import { StepComponent } from '../workspace/component';
44
import { SelectStepBehavior } from './select-step-behavior';
55

@@ -11,10 +11,11 @@ describe('SelectStepBehavior', () => {
1111
const stepComponent = jasmine.createSpyObj<StepComponent>('StepComponent', ['setState'], {
1212
step
1313
});
14-
const context = createDesignerContextStub();
15-
context.state.onSelectedStepChanged.subscribe(s => (selectedStep = s));
14+
const designerContext = createDesignerContextStub();
15+
const componentContext = createComponentContextStub();
16+
designerContext.state.onSelectedStepChanged.subscribe(s => (selectedStep = s));
1617

17-
const behavior = SelectStepBehavior.create(stepComponent, context);
18+
const behavior = SelectStepBehavior.create(stepComponent, designerContext, componentContext);
1819

1920
behavior.onStart();
2021
behavior.onEnd(false);

designer/src/behaviors/select-step-behavior.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@ import { Vector } from '../core/vector';
22
import { DesignerContext } from '../designer-context';
33
import { DesignerState } from '../designer-state';
44
import { StepComponent } from '../workspace/component';
5+
import { ComponentContext } from '../workspace/component-context';
56
import { Behavior } from './behavior';
67
import { DragStepBehavior } from './drag-step-behavior';
78

89
export class SelectStepBehavior implements Behavior {
9-
public static create(pressedStepComponent: StepComponent, context: DesignerContext): SelectStepBehavior {
10-
return new SelectStepBehavior(pressedStepComponent, context, context.state);
10+
public static create(
11+
pressedStepComponent: StepComponent,
12+
designerContext: DesignerContext,
13+
componentContext: ComponentContext
14+
): SelectStepBehavior {
15+
return new SelectStepBehavior(pressedStepComponent, designerContext, componentContext, designerContext.state);
1116
}
1217

1318
private constructor(
1419
private readonly pressedStepComponent: StepComponent,
15-
private readonly context: DesignerContext,
20+
private readonly designerContext: DesignerContext,
21+
private readonly componentContext: ComponentContext,
1622
private readonly state: DesignerState
1723
) {}
1824

@@ -23,7 +29,12 @@ export class SelectStepBehavior implements Behavior {
2329
public onMove(delta: Vector): Behavior | void {
2430
if (!this.state.isReadonly && delta.distance() > 2) {
2531
this.state.setSelectedStep(null);
26-
return DragStepBehavior.create(this.context, this.pressedStepComponent.step, this.pressedStepComponent);
32+
return DragStepBehavior.create(
33+
this.designerContext,
34+
this.componentContext,
35+
this.pressedStepComponent.step,
36+
this.pressedStepComponent
37+
);
2738
}
2839
}
2940

designer/src/core/sequence-modifier.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
import { Sequence, ComponentType, TaskStep } from '../definition';
1+
import { Sequence, TaskStep } from '../definition';
22
import { SequenceModifier } from './sequence-modifier';
33

44
describe('SequenceModifier', () => {
55
const A: TaskStep = {
66
id: '0x1',
77
name: 'A',
8-
componentType: ComponentType.task,
8+
componentType: 'task',
99
type: 'a',
1010
properties: {}
1111
};
1212
const B: TaskStep = {
1313
id: '0x2',
1414
name: 'B',
15-
componentType: ComponentType.task,
15+
componentType: 'task',
1616
type: 'b',
1717
properties: {}
1818
};
1919
const C: TaskStep = {
2020
id: '0x3',
2121
name: 'C',
22-
componentType: ComponentType.task,
22+
componentType: 'task',
2323
type: 'c',
2424
properties: {}
2525
};
2626
const D: TaskStep = {
2727
id: '0x4',
2828
name: 'D',
29-
componentType: ComponentType.task,
29+
componentType: 'task',
3030
type: 'd',
3131
properties: {}
3232
};

designer/src/core/steps-traverser.spec.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { ComponentType, ContainerStep, Step, SwitchStep, TaskStep } from '../definition';
1+
import { ContainerStep, Step, SwitchStep, TaskStep } from '../definition';
2+
import { StepExtensionsResolver } from '../workspace/step-extensions-resolver';
23
import { StepsTraverser } from './steps-traverser';
34

45
describe('StepsTraverser', () => {
56
function createIf(name: string, falseStep: Step): SwitchStep {
67
return {
7-
componentType: ComponentType.switch,
8+
componentType: 'switch',
89
id: 'if' + name,
910
type: 'if' + name,
1011
name,
@@ -18,7 +19,7 @@ describe('StepsTraverser', () => {
1819

1920
function createTask(name: string): TaskStep {
2021
return {
21-
componentType: ComponentType.task,
22+
componentType: 'task',
2223
id: 'task' + name,
2324
type: 'task' + name,
2425
name,
@@ -30,7 +31,7 @@ describe('StepsTraverser', () => {
3031
const ifAlfa = createIf('beta', taskFoo);
3132
const ifBeta = createIf('alfa', ifAlfa);
3233
const loop = {
33-
componentType: ComponentType.container,
34+
componentType: 'container',
3435
id: 'loop',
3536
name: 'loop',
3637
type: 'loop',
@@ -45,9 +46,16 @@ describe('StepsTraverser', () => {
4546
properties: {}
4647
};
4748

49+
let traverser: StepsTraverser;
50+
51+
beforeAll(() => {
52+
const extensions = StepExtensionsResolver.resolve({});
53+
traverser = new StepsTraverser(extensions);
54+
});
55+
4856
describe('getParents', () => {
4957
it('returns task parents', () => {
50-
const parents = StepsTraverser.getParents(definition, taskFoo);
58+
const parents = traverser.getParents(definition, taskFoo);
5159
expect(parents.length).toEqual(6);
5260
expect(parents[0]).toEqual(loop);
5361
expect(parents[1]).toEqual(ifBeta);
@@ -58,37 +66,37 @@ describe('StepsTraverser', () => {
5866
});
5967

6068
it('returns alfa parents', () => {
61-
const parents = StepsTraverser.getParents(definition, ifBeta);
69+
const parents = traverser.getParents(definition, ifBeta);
6270
expect(parents.length).toEqual(2);
6371
expect(parents[0]).toEqual(loop);
6472
expect(parents[1]).toEqual(ifBeta);
6573
});
6674

6775
it('returns loop parents', () => {
68-
const parents = StepsTraverser.getParents(definition, loop);
76+
const parents = traverser.getParents(definition, loop);
6977
expect(parents.length).toEqual(1);
7078
expect(parents[0]).toEqual(loop);
7179
});
7280
});
7381

7482
describe('findById', () => {
7583
it('returns null when stepId not exists', () => {
76-
const found = StepsTraverser.findById(definition, 'undefined');
84+
const found = traverser.findById(definition, 'undefined');
7785
expect(found).toBeNull();
7886
});
7987

8088
it('returns task step', () => {
81-
const found = StepsTraverser.findById(definition, taskFoo.id);
89+
const found = traverser.findById(definition, taskFoo.id);
8290
expect(found).toEqual(taskFoo);
8391
});
8492

8593
it('returns container step', () => {
86-
const found = StepsTraverser.findById(definition, loop.id);
94+
const found = traverser.findById(definition, loop.id);
8795
expect(found).toEqual(loop);
8896
});
8997

9098
it('returns switch step', () => {
91-
const found = StepsTraverser.findById(definition, ifBeta.id);
99+
const found = traverser.findById(definition, ifBeta.id);
92100
expect(found).toEqual(ifBeta);
93101
});
94102
});

0 commit comments

Comments
 (0)