sequential-workflow-designer 0.25.0 → 0.26.0

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/lib/cjs/index.cjs CHANGED
@@ -200,27 +200,17 @@ function race(timeout, a, b, c, d) {
200
200
  }
201
201
 
202
202
  class ControlBarApi {
203
- static create(state, historyController, stateModifier, viewportApi) {
204
- const api = new ControlBarApi(state, historyController, stateModifier, viewportApi);
203
+ static create(state, historyController, stateModifier) {
204
+ const api = new ControlBarApi(state, historyController, stateModifier);
205
205
  race(0, state.onIsReadonlyChanged, state.onSelectedStepIdChanged, state.onIsDragDisabledChanged, api.isUndoRedoSupported() ? state.onDefinitionChanged : undefined).subscribe(api.onStateChanged.forward);
206
206
  return api;
207
207
  }
208
- constructor(state, historyController, stateModifier, viewportApi) {
208
+ constructor(state, historyController, stateModifier) {
209
209
  this.state = state;
210
210
  this.historyController = historyController;
211
211
  this.stateModifier = stateModifier;
212
- this.viewportApi = viewportApi;
213
212
  this.onStateChanged = new SimpleEvent();
214
213
  }
215
- resetViewport() {
216
- this.viewportApi.resetViewport();
217
- }
218
- zoomIn() {
219
- this.viewportApi.zoom(true);
220
- }
221
- zoomOut() {
222
- this.viewportApi.zoom(false);
223
- }
224
214
  isDragDisabled() {
225
215
  return this.state.isDragDisabled;
226
216
  }
@@ -691,21 +681,20 @@ function animate(interval, handler) {
691
681
  }
692
682
 
693
683
  class ViewportAnimator {
694
- constructor(api) {
695
- this.api = api;
684
+ constructor(state) {
685
+ this.state = state;
696
686
  }
697
687
  execute(target) {
698
688
  if (this.animation && this.animation.isAlive) {
699
689
  this.animation.stop();
700
690
  }
701
- const viewport = this.api.getViewport();
702
- const startPosition = viewport.position;
703
- const startScale = viewport.scale;
691
+ const startPosition = this.state.viewport.position;
692
+ const startScale = this.state.viewport.scale;
704
693
  const deltaPosition = startPosition.subtract(target.position);
705
694
  const deltaScale = startScale - target.scale;
706
695
  this.animation = animate(150, progress => {
707
696
  const newScale = startScale - deltaScale * progress;
708
- this.api.setViewport({
697
+ this.state.setViewport({
709
698
  position: startPosition.subtract(deltaPosition.multiplyByScalar(progress)),
710
699
  scale: newScale
711
700
  });
@@ -738,23 +727,23 @@ class ZoomByWheelCalculator {
738
727
  }
739
728
 
740
729
  class ViewportApi {
741
- constructor(workspaceController, viewportController, api) {
730
+ constructor(state, workspaceController, viewportController) {
731
+ this.state = state;
742
732
  this.workspaceController = workspaceController;
743
733
  this.viewportController = viewportController;
744
- this.api = api;
745
- this.animator = new ViewportAnimator(this.api);
734
+ this.animator = new ViewportAnimator(this.state);
746
735
  }
747
736
  limitScale(scale) {
748
737
  return this.viewportController.limitScale(scale);
749
738
  }
750
739
  resetViewport() {
751
740
  const defaultViewport = this.viewportController.getDefault();
752
- this.api.setViewport(defaultViewport);
741
+ this.state.setViewport(defaultViewport);
753
742
  }
754
743
  zoom(direction) {
755
744
  const viewport = this.viewportController.getZoomed(direction);
756
745
  if (viewport) {
757
- this.api.setViewport(viewport);
746
+ this.state.setViewport(viewport);
758
747
  }
759
748
  }
760
749
  moveViewportToStep(stepId) {
@@ -767,11 +756,10 @@ class ViewportApi {
767
756
  this.animator.execute(viewport);
768
757
  }
769
758
  handleWheelEvent(e) {
770
- const viewport = this.api.getViewport();
771
- const canvasPosition = this.api.getCanvasPosition();
772
- const newViewport = ZoomByWheelCalculator.calculate(this.viewportController, viewport, canvasPosition, e);
759
+ const canvasPosition = this.workspaceController.getCanvasPosition();
760
+ const newViewport = ZoomByWheelCalculator.calculate(this.viewportController, this.state.viewport, canvasPosition, e);
773
761
  if (newViewport) {
774
- this.api.setViewport(newViewport);
762
+ this.state.setViewport(newViewport);
775
763
  }
776
764
  }
777
765
  }
@@ -781,6 +769,12 @@ class WorkspaceApi {
781
769
  this.state = state;
782
770
  this.workspaceController = workspaceController;
783
771
  }
772
+ getViewport() {
773
+ return this.state.viewport;
774
+ }
775
+ setViewport(viewport) {
776
+ this.state.setViewport(viewport);
777
+ }
784
778
  getCanvasPosition() {
785
779
  return this.workspaceController.getCanvasPosition();
786
780
  }
@@ -790,12 +784,6 @@ class WorkspaceApi {
790
784
  getRootComponentSize() {
791
785
  return this.workspaceController.getRootComponentSize();
792
786
  }
793
- getViewport() {
794
- return this.state.viewport;
795
- }
796
- setViewport(viewport) {
797
- this.state.setViewport(viewport);
798
- }
799
787
  updateRootComponent() {
800
788
  this.workspaceController.updateRootComponent();
801
789
  }
@@ -811,9 +799,8 @@ class DesignerApi {
811
799
  static create(context) {
812
800
  const workspace = new WorkspaceApi(context.state, context.workspaceController);
813
801
  const viewportController = context.services.viewportController.create(workspace);
814
- const viewport = new ViewportApi(context.workspaceController, viewportController, workspace);
815
802
  const toolboxDataProvider = new ToolboxDataProvider(context.componentContext.iconProvider, context.i18n, context.configuration.toolbox);
816
- return new DesignerApi(context.configuration.shadowRoot, ControlBarApi.create(context.state, context.historyController, context.stateModifier, viewport), new ToolboxApi(context.state, context, context.behaviorController, toolboxDataProvider, context.configuration.uidGenerator), new EditorApi(context.state, context.definitionWalker, context.stateModifier), workspace, viewport, new PathBarApi(context.state, context.definitionWalker), context.definitionWalker, context.i18n);
803
+ return new DesignerApi(context.configuration.shadowRoot, ControlBarApi.create(context.state, context.historyController, context.stateModifier), new ToolboxApi(context.state, context, context.behaviorController, toolboxDataProvider, context.configuration.uidGenerator), new EditorApi(context.state, context.definitionWalker, context.stateModifier), workspace, new ViewportApi(context.state, context.workspaceController, viewportController), new PathBarApi(context.state, context.definitionWalker), context.definitionWalker, context.i18n);
817
804
  }
818
805
  constructor(shadowRoot, controlBar, toolbox, editor, workspace, viewport, pathBar, definitionWalker, i18n) {
819
806
  this.shadowRoot = shadowRoot;
@@ -828,36 +815,15 @@ class DesignerApi {
828
815
  }
829
816
  }
830
817
 
831
- class DefinitionValidator {
832
- constructor(configuration, state) {
833
- this.configuration = configuration;
834
- this.state = state;
835
- }
836
- validateStep(step, parentSequence) {
837
- var _a;
838
- if ((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.step) {
839
- return this.configuration.step(step, parentSequence, this.state.definition);
840
- }
841
- return true;
842
- }
843
- validateRoot() {
844
- var _a;
845
- if ((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.root) {
846
- return this.configuration.root(this.state.definition);
847
- }
848
- return true;
849
- }
850
- }
851
-
852
- class IconProvider {
853
- constructor(configuration) {
854
- this.configuration = configuration;
818
+ const TYPE = 'selectStep';
819
+ class SelectStepBehaviorEndToken {
820
+ static is(token) {
821
+ return Boolean(token) && token.type === TYPE;
855
822
  }
856
- getIconUrl(step) {
857
- if (this.configuration.iconUrlProvider) {
858
- return this.configuration.iconUrlProvider(step.componentType, step.type);
859
- }
860
- return null;
823
+ constructor(stepId, time) {
824
+ this.stepId = stepId;
825
+ this.time = time;
826
+ this.type = TYPE;
861
827
  }
862
828
  }
863
829
 
@@ -922,349 +888,104 @@ function createG(parentElement) {
922
888
  return g;
923
889
  }
924
890
 
925
- exports.ClickCommandType = void 0;
926
- (function (ClickCommandType) {
927
- ClickCommandType[ClickCommandType["selectStep"] = 1] = "selectStep";
928
- ClickCommandType[ClickCommandType["rerenderStep"] = 2] = "rerenderStep";
929
- ClickCommandType[ClickCommandType["openFolder"] = 3] = "openFolder";
930
- ClickCommandType[ClickCommandType["triggerCustomAction"] = 4] = "triggerCustomAction";
931
- })(exports.ClickCommandType || (exports.ClickCommandType = {}));
932
- exports.PlaceholderDirection = void 0;
933
- (function (PlaceholderDirection) {
934
- PlaceholderDirection[PlaceholderDirection["none"] = 0] = "none";
935
- PlaceholderDirection[PlaceholderDirection["in"] = 1] = "in";
936
- PlaceholderDirection[PlaceholderDirection["out"] = 2] = "out";
937
- })(exports.PlaceholderDirection || (exports.PlaceholderDirection = {}));
938
-
939
- class StepComponent {
940
- static create(view, stepContext, componentContext) {
941
- const badges = Badges.createForStep(stepContext, view, componentContext);
942
- return new StepComponent(view, stepContext.step, stepContext.parentSequence, view.hasOutput, badges);
891
+ class ValidationErrorBadgeView {
892
+ static create(parent, cfg) {
893
+ const g = Dom.svg('g');
894
+ const halfOfSize = cfg.size / 2;
895
+ const circle = Dom.svg('path', {
896
+ class: 'sqd-validation-error',
897
+ d: `M 0 ${-halfOfSize} l ${halfOfSize} ${cfg.size} l ${-cfg.size} 0 Z`
898
+ });
899
+ Dom.translate(circle, halfOfSize, halfOfSize);
900
+ g.appendChild(circle);
901
+ const icon = Icons.appendPath(g, 'sqd-validation-error-icon-path', Icons.alert, cfg.iconSize);
902
+ const offsetX = (cfg.size - cfg.iconSize) / 2;
903
+ const offsetY = offsetX * 1.5;
904
+ Dom.translate(icon, offsetX, offsetY);
905
+ parent.appendChild(g);
906
+ return new ValidationErrorBadgeView(parent, g, cfg.size, cfg.size);
943
907
  }
944
- constructor(view, step, parentSequence, hasOutput, badges) {
945
- this.view = view;
946
- this.step = step;
947
- this.parentSequence = parentSequence;
948
- this.hasOutput = hasOutput;
949
- this.badges = badges;
908
+ constructor(parent, g, width, height) {
909
+ this.parent = parent;
910
+ this.g = g;
911
+ this.width = width;
912
+ this.height = height;
950
913
  }
951
- findById(stepId) {
952
- if (this.step.id === stepId) {
953
- return this;
954
- }
955
- if (this.view.sequenceComponents) {
956
- for (const component of this.view.sequenceComponents) {
957
- const result = component.findById(stepId);
958
- if (result) {
959
- return result;
960
- }
961
- }
962
- }
963
- return null;
914
+ destroy() {
915
+ this.parent.removeChild(this.g);
964
916
  }
965
- resolveClick(click) {
966
- if (this.view.sequenceComponents) {
967
- for (const component of this.view.sequenceComponents) {
968
- const result = component.resolveClick(click);
969
- if (result) {
970
- return result;
971
- }
917
+ }
918
+
919
+ class ValidatorFactory {
920
+ static createForStep(stepContext, view, componentContext) {
921
+ return () => {
922
+ if (!componentContext.validator.validateStep(stepContext.step, stepContext.parentSequence)) {
923
+ return false;
972
924
  }
973
- }
974
- const badgeResult = this.badges.resolveClick(click);
975
- if (badgeResult) {
976
- return badgeResult;
977
- }
978
- const viewResult = this.view.resolveClick(click);
979
- if (viewResult) {
980
- return viewResult === true
981
- ? {
982
- type: exports.ClickCommandType.selectStep,
983
- component: this
925
+ if (view.haveCollapsedChildren) {
926
+ let allChildrenValid = true;
927
+ componentContext.definitionWalker.forEachChildren(stepContext.step, (step, _, parentSequence) => {
928
+ if (!componentContext.validator.validateStep(step, parentSequence)) {
929
+ allChildrenValid = false;
930
+ return false;
931
+ }
932
+ });
933
+ if (!allChildrenValid) {
934
+ return false;
984
935
  }
985
- : viewResult;
986
- }
987
- return null;
988
- }
989
- resolvePlaceholders(skipComponent, result) {
990
- if (skipComponent !== this) {
991
- if (this.view.sequenceComponents) {
992
- this.view.sequenceComponents.forEach(component => component.resolvePlaceholders(skipComponent, result));
993
936
  }
994
- if (this.view.placeholders) {
995
- this.view.placeholders.forEach(ph => result.placeholders.push(ph));
996
- }
997
- result.components.push(this);
998
- }
937
+ return true;
938
+ };
999
939
  }
1000
- setIsDragging(isDragging) {
1001
- this.view.setIsDragging(isDragging);
940
+ static createForRoot(componentContext) {
941
+ return () => {
942
+ return componentContext.validator.validateRoot();
943
+ };
1002
944
  }
1003
- setIsSelected(isSelected) {
1004
- this.view.setIsSelected(isSelected);
945
+ }
946
+
947
+ class ValidationErrorBadge {
948
+ static createForStep(parentElement, view, stepContext, componentContext, configuration) {
949
+ const validator = ValidatorFactory.createForStep(stepContext, view, componentContext);
950
+ return new ValidationErrorBadge(parentElement, validator, configuration);
1005
951
  }
1006
- setIsDisabled(isDisabled) {
1007
- this.view.setIsDisabled(isDisabled);
952
+ static createForRoot(parentElement, componentContext, configuration) {
953
+ const validator = ValidatorFactory.createForRoot(componentContext);
954
+ return new ValidationErrorBadge(parentElement, validator, configuration);
1008
955
  }
1009
- updateBadges(result) {
1010
- if (this.view.sequenceComponents) {
1011
- this.view.sequenceComponents.forEach(component => component.updateBadges(result));
956
+ constructor(parentElement, validator, configuration) {
957
+ this.parentElement = parentElement;
958
+ this.validator = validator;
959
+ this.configuration = configuration;
960
+ this.view = null;
961
+ }
962
+ update(result) {
963
+ const isValid = this.validator();
964
+ if (isValid) {
965
+ if (this.view) {
966
+ this.view.destroy();
967
+ this.view = null;
968
+ }
1012
969
  }
1013
- this.badges.update(result);
970
+ else if (!this.view) {
971
+ this.view = ValidationErrorBadgeView.create(this.parentElement, this.configuration);
972
+ }
973
+ return isValid && result;
1014
974
  }
1015
- }
1016
-
1017
- class StepComponentViewContextFactory {
1018
- static create(stepContext, componentContext) {
1019
- const preferenceKeyPrefix = stepContext.step.id + ':';
1020
- return {
1021
- i18n: componentContext.i18n,
1022
- getStepIconUrl: () => componentContext.iconProvider.getIconUrl(stepContext.step),
1023
- getStepName: () => componentContext.i18n(`step.${stepContext.step.type}.name`, stepContext.step.name),
1024
- createSequenceComponent: (parentElement, sequence) => {
1025
- const sequenceContext = {
1026
- sequence,
1027
- depth: stepContext.depth + 1,
1028
- isInputConnected: true,
1029
- isOutputConnected: stepContext.isOutputConnected,
1030
- isPreview: stepContext.isPreview
1031
- };
1032
- return componentContext.services.sequenceComponent.create(parentElement, sequenceContext, componentContext);
1033
- },
1034
- createRegionComponentView(parentElement, componentClassName, contentFactory) {
1035
- return componentContext.services.regionComponentView.create(parentElement, componentClassName, stepContext, this, contentFactory);
1036
- },
1037
- createPlaceholderForArea: componentContext.services.placeholder.createForArea.bind(componentContext.services.placeholder),
1038
- getPreference: (key) => componentContext.preferenceStorage.getItem(preferenceKeyPrefix + key),
1039
- setPreference: (key, value) => componentContext.preferenceStorage.setItem(preferenceKeyPrefix + key, value)
1040
- };
975
+ resolveClick() {
976
+ return null;
1041
977
  }
1042
978
  }
1043
979
 
1044
- class StepComponentFactory {
1045
- constructor(stepExtensionResolver) {
1046
- this.stepExtensionResolver = stepExtensionResolver;
980
+ const defaultConfiguration$7 = {
981
+ view: {
982
+ size: 22,
983
+ iconSize: 12
1047
984
  }
1048
- create(parentElement, stepContext, componentContext) {
1049
- const viewContext = StepComponentViewContextFactory.create(stepContext, componentContext);
1050
- const extension = this.stepExtensionResolver.resolve(stepContext.step.componentType);
1051
- const view = extension.createComponentView(parentElement, stepContext, viewContext);
1052
- const wrappedView = componentContext.services.stepComponentViewWrapper.wrap(view, stepContext);
1053
- return StepComponent.create(wrappedView, stepContext, componentContext);
1054
- }
1055
- }
1056
-
1057
- class ComponentContext {
1058
- static create(configuration, state, stepExtensionResolver, definitionWalker, preferenceStorage, placeholderController, i18n, services) {
1059
- const validator = new DefinitionValidator(configuration.validator, state);
1060
- const iconProvider = new IconProvider(configuration.steps);
1061
- const stepComponentFactory = new StepComponentFactory(stepExtensionResolver);
1062
- return new ComponentContext(configuration.shadowRoot, validator, iconProvider, placeholderController, stepComponentFactory, definitionWalker, services, preferenceStorage, i18n);
1063
- }
1064
- constructor(shadowRoot, validator, iconProvider, placeholderController, stepComponentFactory, definitionWalker, services, preferenceStorage, i18n) {
1065
- this.shadowRoot = shadowRoot;
1066
- this.validator = validator;
1067
- this.iconProvider = iconProvider;
1068
- this.placeholderController = placeholderController;
1069
- this.stepComponentFactory = stepComponentFactory;
1070
- this.definitionWalker = definitionWalker;
1071
- this.services = services;
1072
- this.preferenceStorage = preferenceStorage;
1073
- this.i18n = i18n;
1074
- }
1075
- }
1076
-
1077
- class CustomActionController {
1078
- constructor(configuration, state, stateModifier) {
1079
- this.configuration = configuration;
1080
- this.state = state;
1081
- this.stateModifier = stateModifier;
1082
- }
1083
- trigger(action, step, sequence) {
1084
- const handler = this.configuration.customActionHandler;
1085
- if (!handler) {
1086
- console.warn(`Custom action handler is not defined (action type: ${action.type})`);
1087
- return;
1088
- }
1089
- const context = this.createCustomActionHandlerContext();
1090
- handler(action, step, sequence, context);
1091
- }
1092
- createCustomActionHandlerContext() {
1093
- return {
1094
- notifyStepNameChanged: (stepId) => this.notifyStepChanged(exports.DefinitionChangeType.stepNameChanged, stepId, false),
1095
- notifyStepPropertiesChanged: (stepId) => this.notifyStepChanged(exports.DefinitionChangeType.stepPropertyChanged, stepId, false),
1096
- notifyStepInserted: (stepId) => this.notifyStepChanged(exports.DefinitionChangeType.stepInserted, stepId, true),
1097
- notifyStepMoved: (stepId) => this.notifyStepChanged(exports.DefinitionChangeType.stepMoved, stepId, true),
1098
- notifyStepDeleted: (stepId) => this.notifyStepChanged(exports.DefinitionChangeType.stepDeleted, stepId, true)
1099
- };
1100
- }
1101
- notifyStepChanged(changeType, stepId, updateDependencies) {
1102
- if (!stepId) {
1103
- throw new Error('Step id is empty');
1104
- }
1105
- this.state.notifyDefinitionChanged(changeType, stepId);
1106
- if (updateDependencies) {
1107
- this.stateModifier.updateDependencies();
1108
- }
1109
- }
1110
- }
1111
-
1112
- class EditorView {
1113
- static create(parent) {
1114
- return new EditorView(parent);
1115
- }
1116
- constructor(parent) {
1117
- this.parent = parent;
1118
- this.currentContainer = null;
1119
- }
1120
- setContent(content, className) {
1121
- const container = Dom.element('div', {
1122
- class: className
1123
- });
1124
- container.appendChild(content);
1125
- if (this.currentContainer) {
1126
- this.parent.removeChild(this.currentContainer);
1127
- }
1128
- this.parent.appendChild(container);
1129
- this.currentContainer = container;
1130
- }
1131
- destroy() {
1132
- if (this.currentContainer) {
1133
- this.parent.removeChild(this.currentContainer);
1134
- }
1135
- }
1136
- }
1137
-
1138
- class Editor {
1139
- static create(parent, api, stepEditorClassName, stepEditorProvider, rootEditorClassName, rootEditorProvider, customSelectedStepIdProvider) {
1140
- const view = EditorView.create(parent);
1141
- function render(step) {
1142
- const definition = api.getDefinition();
1143
- let content;
1144
- let className;
1145
- if (step) {
1146
- const stepContext = api.createStepEditorContext(step.id);
1147
- content = stepEditorProvider(step, stepContext, definition, api.isReadonly());
1148
- className = stepEditorClassName;
1149
- }
1150
- else {
1151
- const rootContext = api.createRootEditorContext();
1152
- content = rootEditorProvider(definition, rootContext, api.isReadonly());
1153
- className = rootEditorClassName;
1154
- }
1155
- view.setContent(content, className);
1156
- }
1157
- const renderer = api.runRenderer(step => render(step), customSelectedStepIdProvider);
1158
- return new Editor(view, renderer);
1159
- }
1160
- constructor(view, renderer) {
1161
- this.view = view;
1162
- this.renderer = renderer;
1163
- }
1164
- destroy() {
1165
- this.view.destroy();
1166
- this.renderer.destroy();
1167
- }
1168
- }
1169
-
1170
- class ValidationErrorBadgeView {
1171
- static create(parent, cfg) {
1172
- const g = Dom.svg('g');
1173
- const halfOfSize = cfg.size / 2;
1174
- const circle = Dom.svg('path', {
1175
- class: 'sqd-validation-error',
1176
- d: `M 0 ${-halfOfSize} l ${halfOfSize} ${cfg.size} l ${-cfg.size} 0 Z`
1177
- });
1178
- Dom.translate(circle, halfOfSize, halfOfSize);
1179
- g.appendChild(circle);
1180
- const icon = Icons.appendPath(g, 'sqd-validation-error-icon-path', Icons.alert, cfg.iconSize);
1181
- const offsetX = (cfg.size - cfg.iconSize) / 2;
1182
- const offsetY = offsetX * 1.5;
1183
- Dom.translate(icon, offsetX, offsetY);
1184
- parent.appendChild(g);
1185
- return new ValidationErrorBadgeView(parent, g, cfg.size, cfg.size);
1186
- }
1187
- constructor(parent, g, width, height) {
1188
- this.parent = parent;
1189
- this.g = g;
1190
- this.width = width;
1191
- this.height = height;
1192
- }
1193
- destroy() {
1194
- this.parent.removeChild(this.g);
1195
- }
1196
- }
1197
-
1198
- class ValidatorFactory {
1199
- static createForStep(stepContext, view, componentContext) {
1200
- return () => {
1201
- if (!componentContext.validator.validateStep(stepContext.step, stepContext.parentSequence)) {
1202
- return false;
1203
- }
1204
- if (view.haveCollapsedChildren) {
1205
- let allChildrenValid = true;
1206
- componentContext.definitionWalker.forEachChildren(stepContext.step, (step, _, parentSequence) => {
1207
- if (!componentContext.validator.validateStep(step, parentSequence)) {
1208
- allChildrenValid = false;
1209
- return false;
1210
- }
1211
- });
1212
- if (!allChildrenValid) {
1213
- return false;
1214
- }
1215
- }
1216
- return true;
1217
- };
1218
- }
1219
- static createForRoot(componentContext) {
1220
- return () => {
1221
- return componentContext.validator.validateRoot();
1222
- };
1223
- }
1224
- }
1225
-
1226
- class ValidationErrorBadge {
1227
- static createForStep(parentElement, view, stepContext, componentContext, configuration) {
1228
- const validator = ValidatorFactory.createForStep(stepContext, view, componentContext);
1229
- return new ValidationErrorBadge(parentElement, validator, configuration);
1230
- }
1231
- static createForRoot(parentElement, componentContext, configuration) {
1232
- const validator = ValidatorFactory.createForRoot(componentContext);
1233
- return new ValidationErrorBadge(parentElement, validator, configuration);
1234
- }
1235
- constructor(parentElement, validator, configuration) {
1236
- this.parentElement = parentElement;
1237
- this.validator = validator;
1238
- this.configuration = configuration;
1239
- this.view = null;
1240
- }
1241
- update(result) {
1242
- const isValid = this.validator();
1243
- if (isValid) {
1244
- if (this.view) {
1245
- this.view.destroy();
1246
- this.view = null;
1247
- }
1248
- }
1249
- else if (!this.view) {
1250
- this.view = ValidationErrorBadgeView.create(this.parentElement, this.configuration);
1251
- }
1252
- return isValid && result;
1253
- }
1254
- resolveClick() {
1255
- return null;
1256
- }
1257
- }
1258
-
1259
- const defaultConfiguration$7 = {
1260
- view: {
1261
- size: 22,
1262
- iconSize: 12
1263
- }
1264
- };
1265
- class ValidationErrorBadgeExtension {
1266
- static create(configuration) {
1267
- return new ValidationErrorBadgeExtension(configuration !== null && configuration !== void 0 ? configuration : defaultConfiguration$7);
985
+ };
986
+ class ValidationErrorBadgeExtension {
987
+ static create(configuration) {
988
+ return new ValidationErrorBadgeExtension(configuration !== null && configuration !== void 0 ? configuration : defaultConfiguration$7);
1268
989
  }
1269
990
  constructor(configuration) {
1270
991
  this.configuration = configuration;
@@ -1564,6 +1285,20 @@ class DefaultSequenceComponent {
1564
1285
  }
1565
1286
  }
1566
1287
 
1288
+ exports.ClickCommandType = void 0;
1289
+ (function (ClickCommandType) {
1290
+ ClickCommandType[ClickCommandType["selectStep"] = 1] = "selectStep";
1291
+ ClickCommandType[ClickCommandType["rerenderStep"] = 2] = "rerenderStep";
1292
+ ClickCommandType[ClickCommandType["openFolder"] = 3] = "openFolder";
1293
+ ClickCommandType[ClickCommandType["triggerCustomAction"] = 4] = "triggerCustomAction";
1294
+ })(exports.ClickCommandType || (exports.ClickCommandType = {}));
1295
+ exports.PlaceholderDirection = void 0;
1296
+ (function (PlaceholderDirection) {
1297
+ PlaceholderDirection[PlaceholderDirection["none"] = 0] = "none";
1298
+ PlaceholderDirection[PlaceholderDirection["in"] = 1] = "in";
1299
+ PlaceholderDirection[PlaceholderDirection["out"] = 2] = "out";
1300
+ })(exports.PlaceholderDirection || (exports.PlaceholderDirection = {}));
1301
+
1567
1302
  class StartStopRootComponentView {
1568
1303
  static create(parent, sequence, parentPlaceIndicator, context, cfg) {
1569
1304
  const g = Dom.svg('g', {
@@ -2042,28 +1777,106 @@ class DefaultViewportControllerExtension {
2042
1777
  }
2043
1778
  }
2044
1779
 
2045
- class StepExtensionResolver {
2046
- static create(services) {
2047
- const dict = {};
2048
- for (let i = services.steps.length - 1; i >= 0; i--) {
2049
- const extension = services.steps[i];
2050
- dict[extension.componentType] = extension;
2051
- }
2052
- return new StepExtensionResolver(dict);
1780
+ class StepComponent {
1781
+ static create(view, stepContext, componentContext) {
1782
+ const badges = Badges.createForStep(stepContext, view, componentContext);
1783
+ return new StepComponent(view, stepContext.step, stepContext.parentSequence, view.hasOutput, badges);
2053
1784
  }
2054
- constructor(dict) {
2055
- this.dict = dict;
1785
+ constructor(view, step, parentSequence, hasOutput, badges) {
1786
+ this.view = view;
1787
+ this.step = step;
1788
+ this.parentSequence = parentSequence;
1789
+ this.hasOutput = hasOutput;
1790
+ this.badges = badges;
2056
1791
  }
2057
- resolve(componentType) {
2058
- const extension = this.dict[componentType];
2059
- if (!extension) {
2060
- throw new Error(`Not supported component type: ${componentType}`);
1792
+ findById(stepId) {
1793
+ if (this.step.id === stepId) {
1794
+ return this;
2061
1795
  }
2062
- return extension;
2063
- }
2064
- }
2065
-
2066
- class RectPlaceholderView {
1796
+ if (this.view.sequenceComponents) {
1797
+ for (const component of this.view.sequenceComponents) {
1798
+ const result = component.findById(stepId);
1799
+ if (result) {
1800
+ return result;
1801
+ }
1802
+ }
1803
+ }
1804
+ return null;
1805
+ }
1806
+ resolveClick(click) {
1807
+ if (this.view.sequenceComponents) {
1808
+ for (const component of this.view.sequenceComponents) {
1809
+ const result = component.resolveClick(click);
1810
+ if (result) {
1811
+ return result;
1812
+ }
1813
+ }
1814
+ }
1815
+ const badgeResult = this.badges.resolveClick(click);
1816
+ if (badgeResult) {
1817
+ return badgeResult;
1818
+ }
1819
+ const viewResult = this.view.resolveClick(click);
1820
+ if (viewResult) {
1821
+ return viewResult === true
1822
+ ? {
1823
+ type: exports.ClickCommandType.selectStep,
1824
+ component: this
1825
+ }
1826
+ : viewResult;
1827
+ }
1828
+ return null;
1829
+ }
1830
+ resolvePlaceholders(skipComponent, result) {
1831
+ if (skipComponent !== this) {
1832
+ if (this.view.sequenceComponents) {
1833
+ this.view.sequenceComponents.forEach(component => component.resolvePlaceholders(skipComponent, result));
1834
+ }
1835
+ if (this.view.placeholders) {
1836
+ this.view.placeholders.forEach(ph => result.placeholders.push(ph));
1837
+ }
1838
+ result.components.push(this);
1839
+ }
1840
+ }
1841
+ setIsDragging(isDragging) {
1842
+ this.view.setIsDragging(isDragging);
1843
+ }
1844
+ setIsSelected(isSelected) {
1845
+ this.view.setIsSelected(isSelected);
1846
+ }
1847
+ setIsDisabled(isDisabled) {
1848
+ this.view.setIsDisabled(isDisabled);
1849
+ }
1850
+ updateBadges(result) {
1851
+ if (this.view.sequenceComponents) {
1852
+ this.view.sequenceComponents.forEach(component => component.updateBadges(result));
1853
+ }
1854
+ this.badges.update(result);
1855
+ }
1856
+ }
1857
+
1858
+ class StepExtensionResolver {
1859
+ static create(services) {
1860
+ const dict = {};
1861
+ for (let i = services.steps.length - 1; i >= 0; i--) {
1862
+ const extension = services.steps[i];
1863
+ dict[extension.componentType] = extension;
1864
+ }
1865
+ return new StepExtensionResolver(dict);
1866
+ }
1867
+ constructor(dict) {
1868
+ this.dict = dict;
1869
+ }
1870
+ resolve(componentType) {
1871
+ const extension = this.dict[componentType];
1872
+ if (!extension) {
1873
+ throw new Error(`Not supported component type: ${componentType}`);
1874
+ }
1875
+ return extension;
1876
+ }
1877
+ }
1878
+
1879
+ class RectPlaceholderView {
2067
1880
  static create(parent, width, height, radius, iconSize, direction) {
2068
1881
  const g = Dom.svg('g', {
2069
1882
  visibility: 'hidden',
@@ -2122,63 +1935,414 @@ class RectPlaceholder {
2122
1935
  resolveClick() {
2123
1936
  return null;
2124
1937
  }
2125
- }
2126
-
2127
- class DefaultRegionView {
2128
- static create(parent, widths, height) {
2129
- const totalWidth = widths.reduce((result, width) => result + width, 0);
2130
- const lines = [
2131
- drawLine(parent, 0, 0, totalWidth, 0),
2132
- drawLine(parent, 0, 0, 0, height),
2133
- drawLine(parent, 0, height, totalWidth, height),
2134
- drawLine(parent, totalWidth, 0, totalWidth, height)
2135
- ];
2136
- let offsetX = widths[0];
2137
- for (let i = 1; i < widths.length; i++) {
2138
- lines.push(drawLine(parent, offsetX, 0, offsetX, height));
2139
- offsetX += widths[i];
1938
+ }
1939
+
1940
+ class DefaultRegionView {
1941
+ static create(parent, widths, height) {
1942
+ const totalWidth = widths.reduce((result, width) => result + width, 0);
1943
+ const lines = [
1944
+ drawLine(parent, 0, 0, totalWidth, 0),
1945
+ drawLine(parent, 0, 0, 0, height),
1946
+ drawLine(parent, 0, height, totalWidth, height),
1947
+ drawLine(parent, totalWidth, 0, totalWidth, height)
1948
+ ];
1949
+ let offsetX = widths[0];
1950
+ for (let i = 1; i < widths.length; i++) {
1951
+ lines.push(drawLine(parent, offsetX, 0, offsetX, height));
1952
+ offsetX += widths[i];
1953
+ }
1954
+ return new DefaultRegionView(lines, totalWidth, height);
1955
+ }
1956
+ constructor(lines, width, height) {
1957
+ this.lines = lines;
1958
+ this.width = width;
1959
+ this.height = height;
1960
+ }
1961
+ getClientPosition() {
1962
+ return getAbsolutePosition(this.lines[0]);
1963
+ }
1964
+ resolveClick(click) {
1965
+ const regionPosition = this.getClientPosition();
1966
+ const d = click.position.subtract(regionPosition);
1967
+ if (d.x >= 0 && d.y >= 0 && d.x < this.width * click.scale && d.y < this.height * click.scale) {
1968
+ return true;
1969
+ }
1970
+ return null;
1971
+ }
1972
+ setIsSelected(isSelected) {
1973
+ this.lines.forEach(region => {
1974
+ Dom.toggleClass(region, isSelected, 'sqd-selected');
1975
+ });
1976
+ }
1977
+ }
1978
+ function drawLine(parent, x1, y1, x2, y2) {
1979
+ const line = Dom.svg('line', {
1980
+ class: 'sqd-region',
1981
+ x1,
1982
+ y1,
1983
+ x2,
1984
+ y2
1985
+ });
1986
+ parent.insertBefore(line, parent.firstChild);
1987
+ return line;
1988
+ }
1989
+
1990
+ class DefaultRegionComponentViewExtension {
1991
+ create(parentElement, componentClassName, stepContext, _, contentFactory) {
1992
+ const g = ComponentDom.stepG(componentClassName, stepContext.step.type, stepContext.step.id);
1993
+ parentElement.appendChild(g);
1994
+ return contentFactory(g, DefaultRegionView.create);
1995
+ }
1996
+ }
1997
+
1998
+ class DefaultViewportControllerDesignerExtension {
1999
+ static create(configuration) {
2000
+ return new DefaultViewportControllerDesignerExtension(DefaultViewportControllerExtension.create(configuration));
2001
+ }
2002
+ constructor(viewportController) {
2003
+ this.viewportController = viewportController;
2004
+ }
2005
+ }
2006
+
2007
+ class LineGrid {
2008
+ static create(size) {
2009
+ const path = Dom.svg('path', {
2010
+ class: 'sqd-line-grid-path',
2011
+ fill: 'none'
2012
+ });
2013
+ return new LineGrid(size, path);
2014
+ }
2015
+ constructor(size, element) {
2016
+ this.size = size;
2017
+ this.element = element;
2018
+ }
2019
+ setScale(_, scaledSize) {
2020
+ Dom.attrs(this.element, {
2021
+ d: `M ${scaledSize.x} 0 L 0 0 0 ${scaledSize.y}`
2022
+ });
2023
+ }
2024
+ }
2025
+
2026
+ const defaultConfiguration$4 = {
2027
+ gridSizeX: 48,
2028
+ gridSizeY: 48
2029
+ };
2030
+ class LineGridExtension {
2031
+ static create(configuration) {
2032
+ return new LineGridExtension(configuration !== null && configuration !== void 0 ? configuration : defaultConfiguration$4);
2033
+ }
2034
+ constructor(configuration) {
2035
+ this.configuration = configuration;
2036
+ }
2037
+ create() {
2038
+ const size = new Vector(this.configuration.gridSizeX, this.configuration.gridSizeY);
2039
+ return LineGrid.create(size);
2040
+ }
2041
+ }
2042
+
2043
+ class LineGridDesignerExtension {
2044
+ static create(configuration) {
2045
+ const grid = LineGridExtension.create(configuration);
2046
+ return new LineGridDesignerExtension(grid);
2047
+ }
2048
+ constructor(grid) {
2049
+ this.grid = grid;
2050
+ }
2051
+ }
2052
+
2053
+ class StartStopRootComponentDesignerExtension {
2054
+ static create(configuration) {
2055
+ return new StartStopRootComponentDesignerExtension(StartStopRootComponentExtension.create(configuration));
2056
+ }
2057
+ constructor(rootComponent) {
2058
+ this.rootComponent = rootComponent;
2059
+ }
2060
+ }
2061
+
2062
+ const defaultConfiguration$3 = {
2063
+ view: {
2064
+ paddingTop: 20,
2065
+ paddingX: 20,
2066
+ inputSize: 18,
2067
+ inputIconSize: 14,
2068
+ label: {
2069
+ height: 22,
2070
+ paddingX: 10,
2071
+ minWidth: 50,
2072
+ radius: 10
2073
+ }
2074
+ }
2075
+ };
2076
+ class ContainerStepExtension {
2077
+ static create(configuration) {
2078
+ return new ContainerStepExtension(configuration !== null && configuration !== void 0 ? configuration : defaultConfiguration$3);
2079
+ }
2080
+ constructor(configuration) {
2081
+ this.configuration = configuration;
2082
+ this.componentType = 'container';
2083
+ this.createComponentView = createContainerStepComponentViewFactory(this.configuration.view);
2084
+ }
2085
+ }
2086
+
2087
+ const defaultConfiguration$2 = {
2088
+ view: {
2089
+ minContainerWidth: 40,
2090
+ paddingX: 20,
2091
+ paddingTop: 20,
2092
+ connectionHeight: 16,
2093
+ inputSize: 18,
2094
+ inputIconSize: 14,
2095
+ branchNameLabel: {
2096
+ height: 22,
2097
+ paddingX: 10,
2098
+ minWidth: 50,
2099
+ radius: 10
2100
+ },
2101
+ nameLabel: {
2102
+ height: 22,
2103
+ paddingX: 10,
2104
+ minWidth: 50,
2105
+ radius: 10
2106
+ }
2107
+ }
2108
+ };
2109
+ class SwitchStepExtension {
2110
+ static create(configuration) {
2111
+ return new SwitchStepExtension(configuration !== null && configuration !== void 0 ? configuration : defaultConfiguration$2);
2112
+ }
2113
+ constructor(configuration) {
2114
+ this.configuration = configuration;
2115
+ this.componentType = 'switch';
2116
+ this.createComponentView = createSwitchStepComponentViewFactory(this.configuration.view);
2117
+ }
2118
+ }
2119
+
2120
+ const defaultConfiguration$1 = {
2121
+ view: {
2122
+ paddingLeft: 12,
2123
+ paddingRight: 12,
2124
+ paddingY: 10,
2125
+ textMarginLeft: 12,
2126
+ minTextWidth: 70,
2127
+ iconSize: 22,
2128
+ radius: 5,
2129
+ inputSize: 14,
2130
+ outputSize: 10
2131
+ }
2132
+ };
2133
+ class TaskStepExtension {
2134
+ static create(configuration) {
2135
+ return new TaskStepExtension(configuration !== null && configuration !== void 0 ? configuration : defaultConfiguration$1);
2136
+ }
2137
+ constructor(configuration) {
2138
+ this.configuration = configuration;
2139
+ this.componentType = 'task';
2140
+ this.createComponentView = createTaskStepComponentViewFactory(false, this.configuration.view);
2141
+ }
2142
+ }
2143
+
2144
+ class StepsDesignerExtension {
2145
+ static create(configuration) {
2146
+ const steps = [];
2147
+ if (configuration.container) {
2148
+ steps.push(ContainerStepExtension.create(configuration.container));
2149
+ }
2150
+ if (configuration.switch) {
2151
+ steps.push(SwitchStepExtension.create(configuration.switch));
2152
+ }
2153
+ if (configuration.task) {
2154
+ steps.push(TaskStepExtension.create(configuration.task));
2155
+ }
2156
+ return new StepsDesignerExtension(steps);
2157
+ }
2158
+ constructor(steps) {
2159
+ this.steps = steps;
2160
+ }
2161
+ }
2162
+
2163
+ class DefinitionValidator {
2164
+ constructor(configuration, state) {
2165
+ this.configuration = configuration;
2166
+ this.state = state;
2167
+ }
2168
+ validateStep(step, parentSequence) {
2169
+ var _a;
2170
+ if ((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.step) {
2171
+ return this.configuration.step(step, parentSequence, this.state.definition);
2172
+ }
2173
+ return true;
2174
+ }
2175
+ validateRoot() {
2176
+ var _a;
2177
+ if ((_a = this.configuration) === null || _a === void 0 ? void 0 : _a.root) {
2178
+ return this.configuration.root(this.state.definition);
2179
+ }
2180
+ return true;
2181
+ }
2182
+ }
2183
+
2184
+ class IconProvider {
2185
+ constructor(configuration) {
2186
+ this.configuration = configuration;
2187
+ }
2188
+ getIconUrl(step) {
2189
+ if (this.configuration.iconUrlProvider) {
2190
+ return this.configuration.iconUrlProvider(step.componentType, step.type);
2191
+ }
2192
+ return null;
2193
+ }
2194
+ }
2195
+
2196
+ class StepComponentViewContextFactory {
2197
+ static create(stepContext, componentContext) {
2198
+ const preferenceKeyPrefix = stepContext.step.id + ':';
2199
+ return {
2200
+ i18n: componentContext.i18n,
2201
+ getStepIconUrl: () => componentContext.iconProvider.getIconUrl(stepContext.step),
2202
+ getStepName: () => componentContext.i18n(`step.${stepContext.step.type}.name`, stepContext.step.name),
2203
+ createSequenceComponent: (parentElement, sequence) => {
2204
+ const sequenceContext = {
2205
+ sequence,
2206
+ depth: stepContext.depth + 1,
2207
+ isInputConnected: true,
2208
+ isOutputConnected: stepContext.isOutputConnected,
2209
+ isPreview: stepContext.isPreview
2210
+ };
2211
+ return componentContext.services.sequenceComponent.create(parentElement, sequenceContext, componentContext);
2212
+ },
2213
+ createRegionComponentView(parentElement, componentClassName, contentFactory) {
2214
+ return componentContext.services.regionComponentView.create(parentElement, componentClassName, stepContext, this, contentFactory);
2215
+ },
2216
+ createPlaceholderForArea: componentContext.services.placeholder.createForArea.bind(componentContext.services.placeholder),
2217
+ getPreference: (key) => componentContext.preferenceStorage.getItem(preferenceKeyPrefix + key),
2218
+ setPreference: (key, value) => componentContext.preferenceStorage.setItem(preferenceKeyPrefix + key, value)
2219
+ };
2220
+ }
2221
+ }
2222
+
2223
+ class StepComponentFactory {
2224
+ constructor(stepExtensionResolver) {
2225
+ this.stepExtensionResolver = stepExtensionResolver;
2226
+ }
2227
+ create(parentElement, stepContext, componentContext) {
2228
+ const viewContext = StepComponentViewContextFactory.create(stepContext, componentContext);
2229
+ const extension = this.stepExtensionResolver.resolve(stepContext.step.componentType);
2230
+ const view = extension.createComponentView(parentElement, stepContext, viewContext);
2231
+ const wrappedView = componentContext.services.stepComponentViewWrapper.wrap(view, stepContext);
2232
+ return StepComponent.create(wrappedView, stepContext, componentContext);
2233
+ }
2234
+ }
2235
+
2236
+ class ComponentContext {
2237
+ static create(configuration, state, stepExtensionResolver, definitionWalker, preferenceStorage, placeholderController, i18n, services) {
2238
+ const validator = new DefinitionValidator(configuration.validator, state);
2239
+ const iconProvider = new IconProvider(configuration.steps);
2240
+ const stepComponentFactory = new StepComponentFactory(stepExtensionResolver);
2241
+ return new ComponentContext(configuration.shadowRoot, validator, iconProvider, placeholderController, stepComponentFactory, definitionWalker, services, preferenceStorage, i18n);
2242
+ }
2243
+ constructor(shadowRoot, validator, iconProvider, placeholderController, stepComponentFactory, definitionWalker, services, preferenceStorage, i18n) {
2244
+ this.shadowRoot = shadowRoot;
2245
+ this.validator = validator;
2246
+ this.iconProvider = iconProvider;
2247
+ this.placeholderController = placeholderController;
2248
+ this.stepComponentFactory = stepComponentFactory;
2249
+ this.definitionWalker = definitionWalker;
2250
+ this.services = services;
2251
+ this.preferenceStorage = preferenceStorage;
2252
+ this.i18n = i18n;
2253
+ }
2254
+ }
2255
+
2256
+ class CustomActionController {
2257
+ constructor(configuration, state, stateModifier) {
2258
+ this.configuration = configuration;
2259
+ this.state = state;
2260
+ this.stateModifier = stateModifier;
2261
+ }
2262
+ trigger(action, step, sequence) {
2263
+ const handler = this.configuration.customActionHandler;
2264
+ if (!handler) {
2265
+ console.warn(`Custom action handler is not defined (action type: ${action.type})`);
2266
+ return;
2267
+ }
2268
+ const context = this.createCustomActionHandlerContext();
2269
+ handler(action, step, sequence, context);
2270
+ }
2271
+ createCustomActionHandlerContext() {
2272
+ return {
2273
+ notifyStepNameChanged: (stepId) => this.notifyStepChanged(exports.DefinitionChangeType.stepNameChanged, stepId, false),
2274
+ notifyStepPropertiesChanged: (stepId) => this.notifyStepChanged(exports.DefinitionChangeType.stepPropertyChanged, stepId, false),
2275
+ notifyStepInserted: (stepId) => this.notifyStepChanged(exports.DefinitionChangeType.stepInserted, stepId, true),
2276
+ notifyStepMoved: (stepId) => this.notifyStepChanged(exports.DefinitionChangeType.stepMoved, stepId, true),
2277
+ notifyStepDeleted: (stepId) => this.notifyStepChanged(exports.DefinitionChangeType.stepDeleted, stepId, true)
2278
+ };
2279
+ }
2280
+ notifyStepChanged(changeType, stepId, updateDependencies) {
2281
+ if (!stepId) {
2282
+ throw new Error('Step id is empty');
2283
+ }
2284
+ this.state.notifyDefinitionChanged(changeType, stepId);
2285
+ if (updateDependencies) {
2286
+ this.stateModifier.updateDependencies();
2140
2287
  }
2141
- return new DefaultRegionView(lines, totalWidth, height);
2142
2288
  }
2143
- constructor(lines, width, height) {
2144
- this.lines = lines;
2145
- this.width = width;
2146
- this.height = height;
2289
+ }
2290
+
2291
+ class EditorView {
2292
+ static create(parent) {
2293
+ return new EditorView(parent);
2147
2294
  }
2148
- getClientPosition() {
2149
- return getAbsolutePosition(this.lines[0]);
2295
+ constructor(parent) {
2296
+ this.parent = parent;
2297
+ this.currentContainer = null;
2150
2298
  }
2151
- resolveClick(click) {
2152
- const regionPosition = this.getClientPosition();
2153
- const d = click.position.subtract(regionPosition);
2154
- if (d.x >= 0 && d.y >= 0 && d.x < this.width * click.scale && d.y < this.height * click.scale) {
2155
- return true;
2299
+ setContent(content, className) {
2300
+ const container = Dom.element('div', {
2301
+ class: className
2302
+ });
2303
+ container.appendChild(content);
2304
+ if (this.currentContainer) {
2305
+ this.parent.removeChild(this.currentContainer);
2156
2306
  }
2157
- return null;
2307
+ this.parent.appendChild(container);
2308
+ this.currentContainer = container;
2158
2309
  }
2159
- setIsSelected(isSelected) {
2160
- this.lines.forEach(region => {
2161
- Dom.toggleClass(region, isSelected, 'sqd-selected');
2162
- });
2310
+ destroy() {
2311
+ if (this.currentContainer) {
2312
+ this.parent.removeChild(this.currentContainer);
2313
+ }
2163
2314
  }
2164
- }
2165
- function drawLine(parent, x1, y1, x2, y2) {
2166
- const line = Dom.svg('line', {
2167
- class: 'sqd-region',
2168
- x1,
2169
- y1,
2170
- x2,
2171
- y2
2172
- });
2173
- parent.insertBefore(line, parent.firstChild);
2174
- return line;
2175
2315
  }
2176
2316
 
2177
- class DefaultRegionComponentViewExtension {
2178
- create(parentElement, componentClassName, stepContext, _, contentFactory) {
2179
- const g = ComponentDom.stepG(componentClassName, stepContext.step.type, stepContext.step.id);
2180
- parentElement.appendChild(g);
2181
- return contentFactory(g, DefaultRegionView.create);
2317
+ class Editor {
2318
+ static create(parent, api, stepEditorClassName, stepEditorProvider, rootEditorClassName, rootEditorProvider, customSelectedStepIdProvider) {
2319
+ const view = EditorView.create(parent);
2320
+ function render(step) {
2321
+ const definition = api.getDefinition();
2322
+ let content;
2323
+ let className;
2324
+ if (step) {
2325
+ const stepContext = api.createStepEditorContext(step.id);
2326
+ content = stepEditorProvider(step, stepContext, definition, api.isReadonly());
2327
+ className = stepEditorClassName;
2328
+ }
2329
+ else {
2330
+ const rootContext = api.createRootEditorContext();
2331
+ content = rootEditorProvider(definition, rootContext, api.isReadonly());
2332
+ className = rootEditorClassName;
2333
+ }
2334
+ view.setContent(content, className);
2335
+ }
2336
+ const renderer = api.runRenderer(step => render(step), customSelectedStepIdProvider);
2337
+ return new Editor(view, renderer);
2338
+ }
2339
+ constructor(view, renderer) {
2340
+ this.view = view;
2341
+ this.renderer = renderer;
2342
+ }
2343
+ destroy() {
2344
+ this.view.destroy();
2345
+ this.renderer.destroy();
2182
2346
  }
2183
2347
  }
2184
2348
 
@@ -2227,6 +2391,8 @@ class BehaviorController {
2227
2391
  constructor(dom, shadowRoot) {
2228
2392
  this.dom = dom;
2229
2393
  this.shadowRoot = shadowRoot;
2394
+ this.previousEndToken = null;
2395
+ this.state = null;
2230
2396
  this.onMouseMove = (e) => {
2231
2397
  e.preventDefault();
2232
2398
  e.stopPropagation();
@@ -2298,7 +2464,7 @@ class BehaviorController {
2298
2464
  const delta = this.state.startPosition.subtract(position);
2299
2465
  const newBehavior = this.state.behavior.onMove(delta);
2300
2466
  if (newBehavior) {
2301
- this.state.behavior.onEnd(true, null);
2467
+ this.state.behavior.onEnd(true, null, null);
2302
2468
  this.state.behavior = newBehavior;
2303
2469
  this.state.startPosition = position;
2304
2470
  this.state.behavior.onStart(this.state.startPosition);
@@ -2312,8 +2478,9 @@ class BehaviorController {
2312
2478
  this.unbind(this.shadowRoot);
2313
2479
  }
2314
2480
  this.unbind(window);
2315
- this.state.behavior.onEnd(interrupt, element);
2316
- this.state = undefined;
2481
+ const endToken = this.state.behavior.onEnd(interrupt, element, this.previousEndToken);
2482
+ this.state = null;
2483
+ this.previousEndToken = endToken || null;
2317
2484
  }
2318
2485
  }
2319
2486
 
@@ -2989,9 +3156,11 @@ class SelectStepBehavior {
2989
3156
  }
2990
3157
  }
2991
3158
  onEnd(interrupt) {
2992
- if (!interrupt) {
2993
- this.stateModifier.trySelectStep(this.pressedStepComponent.step, this.pressedStepComponent.parentSequence);
3159
+ if (interrupt) {
3160
+ return;
2994
3161
  }
3162
+ this.stateModifier.trySelectStep(this.pressedStepComponent.step, this.pressedStepComponent.parentSequence);
3163
+ return new SelectStepBehaviorEndToken(this.pressedStepComponent.step.id, Date.now());
2995
3164
  }
2996
3165
  }
2997
3166
 
@@ -3360,13 +3529,14 @@ class Workspace {
3360
3529
  var _a;
3361
3530
  const view = WorkspaceView.create(parent, designerContext.componentContext);
3362
3531
  const clickBehaviorResolver = new ClickBehaviorResolver(designerContext);
3532
+ const clickBehaviorWrapper = designerContext.services.clickBehaviorWrapperExtension.create(designerContext.customActionController);
3363
3533
  const wheelController = designerContext.services.wheelController.create(api.viewport, api.workspace);
3364
3534
  const pinchToZoomController = PinchToZoomController.create(api.workspace, api.viewport, api.shadowRoot);
3365
3535
  const contextMenuItemsBuilder = new ContextMenuItemsBuilder(api.viewport, api.i18n, designerContext.stateModifier, designerContext.state, ((_a = designerContext.services.contextMenu) === null || _a === void 0 ? void 0 : _a.createItemsProvider)
3366
3536
  ? designerContext.services.contextMenu.createItemsProvider(designerContext.customActionController)
3367
3537
  : undefined);
3368
3538
  const contextMenuController = new ContextMenuController(designerContext.theme, designerContext.configuration, contextMenuItemsBuilder);
3369
- const workspace = new Workspace(view, designerContext.definitionWalker, designerContext.state, designerContext.behaviorController, wheelController, pinchToZoomController, contextMenuController, clickBehaviorResolver, api.viewport, designerContext.services);
3539
+ const workspace = new Workspace(view, designerContext.definitionWalker, designerContext.state, designerContext.behaviorController, wheelController, pinchToZoomController, contextMenuController, clickBehaviorResolver, clickBehaviorWrapper, api.viewport, designerContext.services);
3370
3540
  setTimeout(() => {
3371
3541
  workspace.updateRootComponent();
3372
3542
  api.viewport.resetViewport();
@@ -3382,7 +3552,7 @@ class Workspace {
3382
3552
  view.bindContextMenu(workspace.onContextMenu);
3383
3553
  return workspace;
3384
3554
  }
3385
- constructor(view, definitionWalker, state, behaviorController, wheelController, pinchToZoomController, contextMenuController, clickBehaviorResolver, viewportApi, services) {
3555
+ constructor(view, definitionWalker, state, behaviorController, wheelController, pinchToZoomController, contextMenuController, clickBehaviorResolver, clickBehaviorWrapper, viewportApi, services) {
3386
3556
  this.view = view;
3387
3557
  this.definitionWalker = definitionWalker;
3388
3558
  this.state = state;
@@ -3391,6 +3561,7 @@ class Workspace {
3391
3561
  this.pinchToZoomController = pinchToZoomController;
3392
3562
  this.contextMenuController = contextMenuController;
3393
3563
  this.clickBehaviorResolver = clickBehaviorResolver;
3564
+ this.clickBehaviorWrapper = clickBehaviorWrapper;
3394
3565
  this.viewportApi = viewportApi;
3395
3566
  this.services = services;
3396
3567
  this.onRendered = new SimpleEvent();
@@ -3404,7 +3575,8 @@ class Workspace {
3404
3575
  const forceMove = isMiddleButton || altKey;
3405
3576
  const commandOrNull = this.resolveClick(target, position);
3406
3577
  const behavior = this.clickBehaviorResolver.resolve(commandOrNull, target, forceMove);
3407
- this.behaviorController.start(position, behavior);
3578
+ const wrappedBehavior = this.clickBehaviorWrapper.wrap(behavior, commandOrNull);
3579
+ this.behaviorController.start(position, wrappedBehavior);
3408
3580
  }
3409
3581
  };
3410
3582
  this.onPinchToZoom = (distance, centerPoint) => {
@@ -3722,7 +3894,7 @@ class ControlBar {
3722
3894
  static create(parent, api) {
3723
3895
  const isUndoRedoSupported = api.controlBar.isUndoRedoSupported();
3724
3896
  const view = ControlBarView.create(parent, isUndoRedoSupported, api.i18n);
3725
- const bar = new ControlBar(view, api.controlBar, isUndoRedoSupported);
3897
+ const bar = new ControlBar(view, api.controlBar, api.viewport, isUndoRedoSupported);
3726
3898
  view.bindResetButtonClick(() => bar.onResetButtonClicked());
3727
3899
  view.bindZoomInButtonClick(() => bar.onZoomInButtonClicked());
3728
3900
  view.bindZoomOutButtonClick(() => bar.onZoomOutButtonClicked());
@@ -3736,9 +3908,10 @@ class ControlBar {
3736
3908
  bar.refreshButtons();
3737
3909
  return bar;
3738
3910
  }
3739
- constructor(view, controlBarApi, isUndoRedoSupported) {
3911
+ constructor(view, controlBarApi, viewportApi, isUndoRedoSupported) {
3740
3912
  this.view = view;
3741
3913
  this.controlBarApi = controlBarApi;
3914
+ this.viewportApi = viewportApi;
3742
3915
  this.isUndoRedoSupported = isUndoRedoSupported;
3743
3916
  }
3744
3917
  updateLayout() {
@@ -3748,13 +3921,13 @@ class ControlBar {
3748
3921
  //
3749
3922
  }
3750
3923
  onResetButtonClicked() {
3751
- this.controlBarApi.resetViewport();
3924
+ this.viewportApi.resetViewport();
3752
3925
  }
3753
3926
  onZoomInButtonClicked() {
3754
- this.controlBarApi.zoomIn();
3927
+ this.viewportApi.zoom(true);
3755
3928
  }
3756
3929
  onZoomOutButtonClicked() {
3757
- this.controlBarApi.zoomOut();
3930
+ this.viewportApi.zoom(false);
3758
3931
  }
3759
3932
  onMoveButtonClicked() {
3760
3933
  this.controlBarApi.toggleIsDragDisabled();
@@ -4272,31 +4445,6 @@ class ToolboxExtension {
4272
4445
  }
4273
4446
  }
4274
4447
 
4275
- const defaultConfiguration$4 = {
4276
- view: {
4277
- paddingTop: 20,
4278
- paddingX: 20,
4279
- inputSize: 18,
4280
- inputIconSize: 14,
4281
- label: {
4282
- height: 22,
4283
- paddingX: 10,
4284
- minWidth: 50,
4285
- radius: 10
4286
- }
4287
- }
4288
- };
4289
- class ContainerStepExtension {
4290
- static create(configuration) {
4291
- return new ContainerStepExtension(configuration !== null && configuration !== void 0 ? configuration : defaultConfiguration$4);
4292
- }
4293
- constructor(configuration) {
4294
- this.configuration = configuration;
4295
- this.componentType = 'container';
4296
- this.createComponentView = createContainerStepComponentViewFactory(this.configuration.view);
4297
- }
4298
- }
4299
-
4300
4448
  class DefaultPlaceholderControllerExtension {
4301
4449
  create() {
4302
4450
  return {
@@ -4305,7 +4453,7 @@ class DefaultPlaceholderControllerExtension {
4305
4453
  }
4306
4454
  }
4307
4455
 
4308
- const defaultConfiguration$3 = {
4456
+ const defaultConfiguration = {
4309
4457
  gapWidth: 88,
4310
4458
  gapHeight: 24,
4311
4459
  radius: 6,
@@ -4313,7 +4461,7 @@ const defaultConfiguration$3 = {
4313
4461
  };
4314
4462
  class RectPlaceholderExtension {
4315
4463
  static create(configuration) {
4316
- return new RectPlaceholderExtension(configuration !== null && configuration !== void 0 ? configuration : defaultConfiguration$3);
4464
+ return new RectPlaceholderExtension(configuration !== null && configuration !== void 0 ? configuration : defaultConfiguration);
4317
4465
  }
4318
4466
  constructor(configuration) {
4319
4467
  this.configuration = configuration;
@@ -4327,63 +4475,6 @@ class RectPlaceholderExtension {
4327
4475
  }
4328
4476
  }
4329
4477
 
4330
- const defaultConfiguration$2 = {
4331
- view: {
4332
- minContainerWidth: 40,
4333
- paddingX: 20,
4334
- paddingTop: 20,
4335
- connectionHeight: 16,
4336
- inputSize: 18,
4337
- inputIconSize: 14,
4338
- branchNameLabel: {
4339
- height: 22,
4340
- paddingX: 10,
4341
- minWidth: 50,
4342
- radius: 10
4343
- },
4344
- nameLabel: {
4345
- height: 22,
4346
- paddingX: 10,
4347
- minWidth: 50,
4348
- radius: 10
4349
- }
4350
- }
4351
- };
4352
- class SwitchStepExtension {
4353
- static create(configuration) {
4354
- return new SwitchStepExtension(configuration !== null && configuration !== void 0 ? configuration : defaultConfiguration$2);
4355
- }
4356
- constructor(configuration) {
4357
- this.configuration = configuration;
4358
- this.componentType = 'switch';
4359
- this.createComponentView = createSwitchStepComponentViewFactory(this.configuration.view);
4360
- }
4361
- }
4362
-
4363
- const defaultConfiguration$1 = {
4364
- view: {
4365
- paddingLeft: 12,
4366
- paddingRight: 12,
4367
- paddingY: 10,
4368
- textMarginLeft: 12,
4369
- minTextWidth: 70,
4370
- iconSize: 22,
4371
- radius: 5,
4372
- inputSize: 14,
4373
- outputSize: 10
4374
- }
4375
- };
4376
- class TaskStepExtension {
4377
- static create(configuration) {
4378
- return new TaskStepExtension(configuration !== null && configuration !== void 0 ? configuration : defaultConfiguration$1);
4379
- }
4380
- constructor(configuration) {
4381
- this.configuration = configuration;
4382
- this.componentType = 'task';
4383
- this.createComponentView = createTaskStepComponentViewFactory(false, this.configuration.view);
4384
- }
4385
- }
4386
-
4387
4478
  class DefaultSequenceComponentExtension {
4388
4479
  constructor() {
4389
4480
  this.create = DefaultSequenceComponent.create;
@@ -4396,39 +4487,15 @@ class DefaultStepComponentViewWrapperExtension {
4396
4487
  }
4397
4488
  }
4398
4489
 
4399
- class LineGrid {
4400
- static create(size) {
4401
- const path = Dom.svg('path', {
4402
- class: 'sqd-line-grid-path',
4403
- fill: 'none'
4404
- });
4405
- return new LineGrid(size, path);
4406
- }
4407
- constructor(size, element) {
4408
- this.size = size;
4409
- this.element = element;
4410
- }
4411
- setScale(_, scaledSize) {
4412
- Dom.attrs(this.element, {
4413
- d: `M ${scaledSize.x} 0 L 0 0 0 ${scaledSize.y}`
4414
- });
4490
+ class DefaultClickBehaviorWrapper {
4491
+ constructor() {
4492
+ this.wrap = (behavior) => behavior;
4415
4493
  }
4416
4494
  }
4417
4495
 
4418
- const defaultConfiguration = {
4419
- gridSizeX: 48,
4420
- gridSizeY: 48
4421
- };
4422
- class LineGridExtension {
4423
- static create(configuration) {
4424
- return new LineGridExtension(configuration !== null && configuration !== void 0 ? configuration : defaultConfiguration);
4425
- }
4426
- constructor(configuration) {
4427
- this.configuration = configuration;
4428
- }
4496
+ class DefaultClickBehaviorWrapperExtension {
4429
4497
  create() {
4430
- const size = new Vector(this.configuration.gridSizeX, this.configuration.gridSizeY);
4431
- return LineGrid.create(size);
4498
+ return new DefaultClickBehaviorWrapper();
4432
4499
  }
4433
4500
  }
4434
4501
 
@@ -4448,6 +4515,9 @@ function merge(services, extensions) {
4448
4515
  if (ext.stepComponentViewWrapper) {
4449
4516
  services.stepComponentViewWrapper = ext.stepComponentViewWrapper;
4450
4517
  }
4518
+ if (ext.clickBehaviorWrapperExtension) {
4519
+ services.clickBehaviorWrapperExtension = ext.clickBehaviorWrapperExtension;
4520
+ }
4451
4521
  if (ext.badges) {
4452
4522
  services.badges = (services.badges || []).concat(ext.badges);
4453
4523
  }
@@ -4499,6 +4569,9 @@ function setDefaults(services, configuration) {
4499
4569
  if (!services.stepComponentViewWrapper) {
4500
4570
  services.stepComponentViewWrapper = new DefaultStepComponentViewWrapperExtension();
4501
4571
  }
4572
+ if (!services.clickBehaviorWrapperExtension) {
4573
+ services.clickBehaviorWrapperExtension = new DefaultClickBehaviorWrapperExtension();
4574
+ }
4502
4575
  if (!services.badges) {
4503
4576
  services.badges = [];
4504
4577
  }
@@ -4795,35 +4868,6 @@ class Designer {
4795
4868
  }
4796
4869
  }
4797
4870
 
4798
- class LineGridDesignerExtension {
4799
- static create(configuration) {
4800
- const grid = LineGridExtension.create(configuration);
4801
- return new LineGridDesignerExtension(grid);
4802
- }
4803
- constructor(grid) {
4804
- this.grid = grid;
4805
- }
4806
- }
4807
-
4808
- class StepsDesignerExtension {
4809
- static create(configuration) {
4810
- const steps = [];
4811
- if (configuration.container) {
4812
- steps.push(ContainerStepExtension.create(configuration.container));
4813
- }
4814
- if (configuration.switch) {
4815
- steps.push(SwitchStepExtension.create(configuration.switch));
4816
- }
4817
- if (configuration.task) {
4818
- steps.push(TaskStepExtension.create(configuration.task));
4819
- }
4820
- return new StepsDesignerExtension(steps);
4821
- }
4822
- constructor(steps) {
4823
- this.steps = steps;
4824
- }
4825
- }
4826
-
4827
4871
  exports.Badges = Badges;
4828
4872
  exports.CenteredViewportCalculator = CenteredViewportCalculator;
4829
4873
  exports.ClassicWheelControllerExtension = ClassicWheelControllerExtension;
@@ -4836,6 +4880,7 @@ exports.DefaultRegionView = DefaultRegionView;
4836
4880
  exports.DefaultSequenceComponent = DefaultSequenceComponent;
4837
4881
  exports.DefaultSequenceComponentView = DefaultSequenceComponentView;
4838
4882
  exports.DefaultViewportController = DefaultViewportController;
4883
+ exports.DefaultViewportControllerDesignerExtension = DefaultViewportControllerDesignerExtension;
4839
4884
  exports.DefaultViewportControllerExtension = DefaultViewportControllerExtension;
4840
4885
  exports.Designer = Designer;
4841
4886
  exports.DesignerApi = DesignerApi;
@@ -4854,12 +4899,15 @@ exports.OutputView = OutputView;
4854
4899
  exports.PathBarApi = PathBarApi;
4855
4900
  exports.RectPlaceholder = RectPlaceholder;
4856
4901
  exports.RectPlaceholderView = RectPlaceholderView;
4902
+ exports.SelectStepBehaviorEndToken = SelectStepBehaviorEndToken;
4857
4903
  exports.ServicesResolver = ServicesResolver;
4858
4904
  exports.SimpleEvent = SimpleEvent;
4905
+ exports.StartStopRootComponentDesignerExtension = StartStopRootComponentDesignerExtension;
4859
4906
  exports.StartStopRootComponentExtension = StartStopRootComponentExtension;
4860
4907
  exports.StepComponent = StepComponent;
4861
4908
  exports.StepExtensionResolver = StepExtensionResolver;
4862
4909
  exports.StepsDesignerExtension = StepsDesignerExtension;
4910
+ exports.TYPE = TYPE;
4863
4911
  exports.ToolboxApi = ToolboxApi;
4864
4912
  exports.Uid = Uid;
4865
4913
  exports.ValidationErrorBadgeExtension = ValidationErrorBadgeExtension;