sequential-workflow-designer 0.20.0 → 0.21.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/esm/index.js CHANGED
@@ -757,7 +757,7 @@ const BADGE_GAP = 4;
757
757
  class Badges {
758
758
  static createForStep(stepContext, view, componentContext) {
759
759
  const g = createG(view.g);
760
- const badges = componentContext.services.badges.map(ext => ext.createForStep(g, stepContext, componentContext));
760
+ const badges = componentContext.services.badges.map(ext => ext.createForStep(g, view, stepContext, componentContext));
761
761
  const position = new Vector(view.width, 0);
762
762
  return new Badges(g, position, badges);
763
763
  }
@@ -831,7 +831,7 @@ var PlaceholderDirection;
831
831
  class StepComponent {
832
832
  static create(view, stepContext, componentContext) {
833
833
  const badges = Badges.createForStep(stepContext, view, componentContext);
834
- return new StepComponent(view, stepContext.step, stepContext.parentSequence, view.hasOutput(), badges);
834
+ return new StepComponent(view, stepContext.step, stepContext.parentSequence, view.hasOutput, badges);
835
835
  }
836
836
  constructor(view, step, parentSequence, hasOutput, badges) {
837
837
  this.view = view;
@@ -917,7 +917,9 @@ class StepComponent {
917
917
 
918
918
  class StepComponentViewContextFactory {
919
919
  static create(stepContext, componentContext) {
920
+ const preferenceKeyPrefix = stepContext.step.id + ':';
920
921
  return {
922
+ i18n: componentContext.i18n,
921
923
  getStepIconUrl: () => componentContext.iconProvider.getIconUrl(stepContext.step),
922
924
  getStepName: () => componentContext.i18n(`step.${stepContext.step.type}.name`, stepContext.step.name),
923
925
  createSequenceComponent: (parentElement, sequence) => {
@@ -929,8 +931,12 @@ class StepComponentViewContextFactory {
929
931
  };
930
932
  return componentContext.services.sequenceComponent.create(parentElement, sequenceContext, componentContext);
931
933
  },
934
+ createRegionComponentView(parentElement, componentClassName, contentFactory) {
935
+ return componentContext.services.regionComponentView.create(parentElement, componentClassName, stepContext, this, contentFactory);
936
+ },
932
937
  createPlaceholderForArea: componentContext.services.placeholder.createForArea.bind(componentContext.services.placeholder),
933
- i18n: componentContext.i18n
938
+ getPreference: (key) => componentContext.preferenceStorage.getItem(preferenceKeyPrefix + key),
939
+ setPreference: (key, value) => componentContext.preferenceStorage.setItem(preferenceKeyPrefix + key, value)
934
940
  };
935
941
  }
936
942
  }
@@ -949,20 +955,22 @@ class StepComponentFactory {
949
955
  }
950
956
 
951
957
  class ComponentContext {
952
- static create(stepsConfiguration, validatorConfiguration, state, stepExtensionResolver, i18n, services) {
953
- const validator = new DefinitionValidator(validatorConfiguration, state);
954
- const iconProvider = new IconProvider(stepsConfiguration);
958
+ static create(configuration, state, stepExtensionResolver, definitionWalker, preferenceStorage, i18n, services) {
959
+ const validator = new DefinitionValidator(configuration.validator, state);
960
+ const iconProvider = new IconProvider(configuration.steps);
955
961
  const placeholderController = services.placeholderController.create();
956
962
  const stepComponentFactory = new StepComponentFactory(stepExtensionResolver);
957
- return new ComponentContext(validator, iconProvider, placeholderController, stepComponentFactory, i18n, services);
963
+ return new ComponentContext(validator, iconProvider, placeholderController, stepComponentFactory, definitionWalker, services, preferenceStorage, i18n);
958
964
  }
959
- constructor(validator, iconProvider, placeholderController, stepComponentFactory, i18n, services) {
965
+ constructor(validator, iconProvider, placeholderController, stepComponentFactory, definitionWalker, services, preferenceStorage, i18n) {
960
966
  this.validator = validator;
961
967
  this.iconProvider = iconProvider;
962
968
  this.placeholderController = placeholderController;
963
969
  this.stepComponentFactory = stepComponentFactory;
964
- this.i18n = i18n;
970
+ this.definitionWalker = definitionWalker;
965
971
  this.services = services;
972
+ this.preferenceStorage = preferenceStorage;
973
+ this.i18n = i18n;
966
974
  }
967
975
  }
968
976
 
@@ -1087,13 +1095,41 @@ class ValidationErrorBadgeView {
1087
1095
  }
1088
1096
  }
1089
1097
 
1098
+ class ValidatorFactory {
1099
+ static createForStep(stepContext, view, componentContext) {
1100
+ return () => {
1101
+ if (!componentContext.validator.validateStep(stepContext.step, stepContext.parentSequence)) {
1102
+ return false;
1103
+ }
1104
+ if (view.haveCollapsedChildren) {
1105
+ let allChildrenValid = true;
1106
+ componentContext.definitionWalker.forEachChildren(stepContext.step, (step, _, parentSequence) => {
1107
+ if (!componentContext.validator.validateStep(step, parentSequence)) {
1108
+ allChildrenValid = false;
1109
+ return false;
1110
+ }
1111
+ });
1112
+ if (!allChildrenValid) {
1113
+ return false;
1114
+ }
1115
+ }
1116
+ return true;
1117
+ };
1118
+ }
1119
+ static createForRoot(componentContext) {
1120
+ return () => {
1121
+ return componentContext.validator.validateRoot();
1122
+ };
1123
+ }
1124
+ }
1125
+
1090
1126
  class ValidationErrorBadge {
1091
- static createForStep(parentElement, stepContext, componentContext, configuration) {
1092
- const validator = () => componentContext.validator.validateStep(stepContext.step, stepContext.parentSequence);
1127
+ static createForStep(parentElement, view, stepContext, componentContext, configuration) {
1128
+ const validator = ValidatorFactory.createForStep(stepContext, view, componentContext);
1093
1129
  return new ValidationErrorBadge(parentElement, validator, configuration);
1094
1130
  }
1095
1131
  static createForRoot(parentElement, componentContext, configuration) {
1096
- const validator = () => componentContext.validator.validateRoot();
1132
+ const validator = ValidatorFactory.createForRoot(componentContext);
1097
1133
  return new ValidationErrorBadge(parentElement, validator, configuration);
1098
1134
  }
1099
1135
  constructor(parentElement, validator, configuration) {
@@ -1135,8 +1171,8 @@ class ValidationErrorBadgeExtension {
1135
1171
  this.id = 'validationError';
1136
1172
  this.createStartValue = () => true;
1137
1173
  }
1138
- createForStep(parentElement, stepContext, componentContext) {
1139
- return ValidationErrorBadge.createForStep(parentElement, stepContext, componentContext, this.configuration.view);
1174
+ createForStep(parentElement, view, stepContext, componentContext) {
1175
+ return ValidationErrorBadge.createForStep(parentElement, view, stepContext, componentContext, this.configuration.view);
1140
1176
  }
1141
1177
  createForRoot(parentElement, componentContext) {
1142
1178
  return ValidationErrorBadge.createForRoot(parentElement, componentContext, this.configuration.view);
@@ -1310,53 +1346,6 @@ class OutputView {
1310
1346
  }
1311
1347
  }
1312
1348
 
1313
- class RegionView {
1314
- static create(parent, widths, height) {
1315
- const totalWidth = widths.reduce((result, width) => result + width, 0);
1316
- const lines = [
1317
- drawLine(parent, 0, 0, totalWidth, 0),
1318
- drawLine(parent, 0, 0, 0, height),
1319
- drawLine(parent, 0, height, totalWidth, height),
1320
- drawLine(parent, totalWidth, 0, totalWidth, height)
1321
- ];
1322
- let offsetX = widths[0];
1323
- for (let i = 1; i < widths.length; i++) {
1324
- lines.push(drawLine(parent, offsetX, 0, offsetX, height));
1325
- offsetX += widths[i];
1326
- }
1327
- return new RegionView(lines, totalWidth, height);
1328
- }
1329
- constructor(lines, width, height) {
1330
- this.lines = lines;
1331
- this.width = width;
1332
- this.height = height;
1333
- }
1334
- getClientPosition() {
1335
- return getAbsolutePosition(this.lines[0]);
1336
- }
1337
- resolveClick(click) {
1338
- const regionPosition = this.getClientPosition();
1339
- const d = click.position.subtract(regionPosition);
1340
- return d.x >= 0 && d.y >= 0 && d.x < this.width * click.scale && d.y < this.height * click.scale;
1341
- }
1342
- setIsSelected(isSelected) {
1343
- this.lines.forEach(region => {
1344
- Dom.toggleClass(region, isSelected, 'sqd-selected');
1345
- });
1346
- }
1347
- }
1348
- function drawLine(parent, x1, y1, x2, y2) {
1349
- const line = Dom.svg('line', {
1350
- class: 'sqd-region',
1351
- x1,
1352
- y1,
1353
- x2,
1354
- y2
1355
- });
1356
- parent.insertBefore(line, parent.firstChild);
1357
- return line;
1358
- }
1359
-
1360
1349
  class DefaultSequenceComponentView {
1361
1350
  static create(parent, sequenceContext, componentContext) {
1362
1351
  const phWidth = componentContext.services.placeholder.gapSize.x;
@@ -1483,159 +1472,160 @@ class DefaultSequenceComponent {
1483
1472
  }
1484
1473
  }
1485
1474
 
1475
+ const COMPONENT_CLASS_NAME$2 = 'container';
1486
1476
  const createContainerStepComponentViewFactory = (cfg) => (parentElement, stepContext, viewContext) => {
1487
- const { step } = stepContext;
1488
- const g = ComponentDom.stepG('container', step.type, step.id);
1489
- parentElement.appendChild(g);
1490
- const name = viewContext.getStepName();
1491
- const labelView = LabelView.create(g, cfg.paddingTop, cfg.label, name, 'primary');
1492
- const sequenceComponent = viewContext.createSequenceComponent(g, step.sequence);
1493
- const halfOfWidestElement = labelView.width / 2;
1494
- const offsetLeft = Math.max(halfOfWidestElement - sequenceComponent.view.joinX, 0) + cfg.paddingX;
1495
- const offsetRight = Math.max(halfOfWidestElement - (sequenceComponent.view.width - sequenceComponent.view.joinX), 0) + cfg.paddingX;
1496
- const width = offsetLeft + sequenceComponent.view.width + offsetRight;
1497
- const height = cfg.paddingTop + cfg.label.height + sequenceComponent.view.height;
1498
- const joinX = sequenceComponent.view.joinX + offsetLeft;
1499
- Dom.translate(labelView.g, joinX, 0);
1500
- Dom.translate(sequenceComponent.view.g, offsetLeft, cfg.paddingTop + cfg.label.height);
1501
- const iconUrl = viewContext.getStepIconUrl();
1502
- const inputView = InputView.createRectInput(g, joinX, 0, cfg.inputSize, cfg.inputIconSize, iconUrl);
1503
- JoinView.createStraightJoin(g, new Vector(joinX, 0), cfg.paddingTop);
1504
- const regionView = RegionView.create(g, [width], height);
1505
- return {
1506
- g,
1507
- width,
1508
- height,
1509
- joinX,
1510
- placeholders: null,
1511
- sequenceComponents: [sequenceComponent],
1512
- getClientPosition() {
1513
- return regionView.getClientPosition();
1514
- },
1515
- resolveClick(click) {
1516
- return regionView.resolveClick(click) || g.contains(click.element) ? true : null;
1517
- },
1518
- setIsDragging(isDragging) {
1519
- inputView.setIsHidden(isDragging);
1520
- },
1521
- setIsSelected(isSelected) {
1522
- regionView.setIsSelected(isSelected);
1523
- },
1524
- setIsDisabled(isDisabled) {
1525
- Dom.toggleClass(g, isDisabled, 'sqd-disabled');
1526
- },
1527
- hasOutput() {
1528
- return sequenceComponent.hasOutput;
1529
- }
1530
- };
1477
+ return viewContext.createRegionComponentView(parentElement, COMPONENT_CLASS_NAME$2, (g, regionViewBuilder) => {
1478
+ const step = stepContext.step;
1479
+ const name = viewContext.getStepName();
1480
+ const labelView = LabelView.create(g, cfg.paddingTop, cfg.label, name, 'primary');
1481
+ const sequenceComponent = viewContext.createSequenceComponent(g, step.sequence);
1482
+ const halfOfWidestElement = labelView.width / 2;
1483
+ const offsetLeft = Math.max(halfOfWidestElement - sequenceComponent.view.joinX, 0) + cfg.paddingX;
1484
+ const offsetRight = Math.max(halfOfWidestElement - (sequenceComponent.view.width - sequenceComponent.view.joinX), 0) + cfg.paddingX;
1485
+ const width = offsetLeft + sequenceComponent.view.width + offsetRight;
1486
+ const height = cfg.paddingTop + cfg.label.height + sequenceComponent.view.height;
1487
+ const joinX = sequenceComponent.view.joinX + offsetLeft;
1488
+ Dom.translate(labelView.g, joinX, 0);
1489
+ Dom.translate(sequenceComponent.view.g, offsetLeft, cfg.paddingTop + cfg.label.height);
1490
+ const iconUrl = viewContext.getStepIconUrl();
1491
+ const inputView = InputView.createRectInput(g, joinX, 0, cfg.inputSize, cfg.inputIconSize, iconUrl);
1492
+ JoinView.createStraightJoin(g, new Vector(joinX, 0), cfg.paddingTop);
1493
+ const regionView = regionViewBuilder(g, [width], height);
1494
+ return {
1495
+ g,
1496
+ width,
1497
+ height,
1498
+ joinX,
1499
+ placeholders: null,
1500
+ sequenceComponents: [sequenceComponent],
1501
+ hasOutput: sequenceComponent.hasOutput,
1502
+ getClientPosition() {
1503
+ return regionView.getClientPosition();
1504
+ },
1505
+ resolveClick(click) {
1506
+ const result = regionView.resolveClick(click);
1507
+ return result === true || (result === null && g.contains(click.element)) ? true : result;
1508
+ },
1509
+ setIsDragging(isDragging) {
1510
+ inputView.setIsHidden(isDragging);
1511
+ },
1512
+ setIsSelected(isSelected) {
1513
+ regionView.setIsSelected(isSelected);
1514
+ },
1515
+ setIsDisabled(isDisabled) {
1516
+ Dom.toggleClass(g, isDisabled, 'sqd-disabled');
1517
+ }
1518
+ };
1519
+ });
1531
1520
  };
1532
1521
 
1522
+ const COMPONENT_CLASS_NAME$1 = 'switch';
1533
1523
  const createSwitchStepComponentViewFactory = (cfg) => (parent, stepContext, viewContext) => {
1534
- const { step } = stepContext;
1535
- const g = ComponentDom.stepG('switch', step.type, step.id);
1536
- parent.appendChild(g);
1537
- const branchNames = Object.keys(step.branches);
1538
- const branchComponents = branchNames.map(branchName => {
1539
- return viewContext.createSequenceComponent(g, step.branches[branchName]);
1540
- });
1541
- const branchLabelViews = branchNames.map(branchName => {
1542
- const labelY = cfg.paddingTop + cfg.nameLabel.height + cfg.connectionHeight;
1543
- const translatedBranchName = viewContext.i18n(`stepComponent.${step.type}.branchName`, branchName);
1544
- return LabelView.create(g, labelY, cfg.branchNameLabel, translatedBranchName, 'secondary');
1545
- });
1546
- const name = viewContext.getStepName();
1547
- const nameLabelView = LabelView.create(g, cfg.paddingTop, cfg.nameLabel, name, 'primary');
1548
- let prevOffsetX = 0;
1549
- const branchSizes = branchComponents.map((component, i) => {
1550
- const halfOfWidestBranchElement = Math.max(branchLabelViews[i].width, cfg.minContainerWidth) / 2;
1551
- const branchOffsetLeft = Math.max(halfOfWidestBranchElement - component.view.joinX, 0) + cfg.paddingX;
1552
- const branchOffsetRight = Math.max(halfOfWidestBranchElement - (component.view.width - component.view.joinX), 0) + cfg.paddingX;
1553
- const width = component.view.width + branchOffsetLeft + branchOffsetRight;
1554
- const joinX = component.view.joinX + branchOffsetLeft;
1555
- const offsetX = prevOffsetX;
1556
- prevOffsetX += width;
1557
- return { width, branchOffsetLeft, offsetX, joinX };
1558
- });
1559
- const centerBranchIndex = Math.floor(branchNames.length / 2);
1560
- const centerBranchSize = branchSizes[centerBranchIndex];
1561
- let joinX = centerBranchSize.offsetX;
1562
- if (branchNames.length % 2 !== 0) {
1563
- joinX += centerBranchSize.joinX;
1564
- }
1565
- const totalBranchesWidth = branchSizes.reduce((result, s) => result + s.width, 0);
1566
- const maxBranchesHeight = Math.max(...branchComponents.map(s => s.view.height));
1567
- const halfOfWidestSwitchElement = nameLabelView.width / 2 + cfg.paddingX;
1568
- const switchOffsetLeft = Math.max(halfOfWidestSwitchElement - joinX, 0);
1569
- const switchOffsetRight = Math.max(halfOfWidestSwitchElement - (totalBranchesWidth - joinX), 0);
1570
- const viewWidth = switchOffsetLeft + totalBranchesWidth + switchOffsetRight;
1571
- const viewHeight = maxBranchesHeight + cfg.paddingTop + cfg.nameLabel.height + cfg.branchNameLabel.height + cfg.connectionHeight * 2;
1572
- const shiftedJoinX = switchOffsetLeft + joinX;
1573
- Dom.translate(nameLabelView.g, shiftedJoinX, 0);
1574
- const branchOffsetTop = cfg.paddingTop + cfg.nameLabel.height + cfg.branchNameLabel.height + cfg.connectionHeight;
1575
- branchComponents.forEach((component, i) => {
1576
- const branchSize = branchSizes[i];
1577
- const branchOffsetLeft = switchOffsetLeft + branchSize.offsetX + branchSize.branchOffsetLeft;
1578
- Dom.translate(branchLabelViews[i].g, switchOffsetLeft + branchSize.offsetX + branchSize.joinX, 0);
1579
- Dom.translate(component.view.g, branchOffsetLeft, branchOffsetTop);
1580
- if (component.hasOutput && stepContext.isOutputConnected) {
1581
- const endOffsetTopOfComponent = cfg.paddingTop + cfg.nameLabel.height + cfg.branchNameLabel.height + cfg.connectionHeight + component.view.height;
1582
- const missingHeight = viewHeight - endOffsetTopOfComponent - cfg.connectionHeight;
1583
- if (missingHeight > 0) {
1584
- JoinView.createStraightJoin(g, new Vector(switchOffsetLeft + branchSize.offsetX + branchSize.joinX, endOffsetTopOfComponent), missingHeight);
1524
+ return viewContext.createRegionComponentView(parent, COMPONENT_CLASS_NAME$1, (g, regionViewBuilder) => {
1525
+ const step = stepContext.step;
1526
+ const branchNames = Object.keys(step.branches);
1527
+ const branchComponents = branchNames.map(branchName => {
1528
+ return viewContext.createSequenceComponent(g, step.branches[branchName]);
1529
+ });
1530
+ const branchLabelViews = branchNames.map(branchName => {
1531
+ const labelY = cfg.paddingTop + cfg.nameLabel.height + cfg.connectionHeight;
1532
+ const translatedBranchName = viewContext.i18n(`stepComponent.${step.type}.branchName`, branchName);
1533
+ return LabelView.create(g, labelY, cfg.branchNameLabel, translatedBranchName, 'secondary');
1534
+ });
1535
+ const name = viewContext.getStepName();
1536
+ const nameLabelView = LabelView.create(g, cfg.paddingTop, cfg.nameLabel, name, 'primary');
1537
+ let prevOffsetX = 0;
1538
+ const branchSizes = branchComponents.map((component, i) => {
1539
+ const halfOfWidestBranchElement = Math.max(branchLabelViews[i].width, cfg.minContainerWidth) / 2;
1540
+ const branchOffsetLeft = Math.max(halfOfWidestBranchElement - component.view.joinX, 0) + cfg.paddingX;
1541
+ const branchOffsetRight = Math.max(halfOfWidestBranchElement - (component.view.width - component.view.joinX), 0) + cfg.paddingX;
1542
+ const width = component.view.width + branchOffsetLeft + branchOffsetRight;
1543
+ const joinX = component.view.joinX + branchOffsetLeft;
1544
+ const offsetX = prevOffsetX;
1545
+ prevOffsetX += width;
1546
+ return { width, branchOffsetLeft, offsetX, joinX };
1547
+ });
1548
+ const centerBranchIndex = Math.floor(branchNames.length / 2);
1549
+ const centerBranchSize = branchSizes[centerBranchIndex];
1550
+ let joinX = centerBranchSize.offsetX;
1551
+ if (branchNames.length % 2 !== 0) {
1552
+ joinX += centerBranchSize.joinX;
1553
+ }
1554
+ const totalBranchesWidth = branchSizes.reduce((result, s) => result + s.width, 0);
1555
+ const maxBranchesHeight = Math.max(...branchComponents.map(s => s.view.height));
1556
+ const halfOfWidestSwitchElement = nameLabelView.width / 2 + cfg.paddingX;
1557
+ const switchOffsetLeft = Math.max(halfOfWidestSwitchElement - joinX, 0);
1558
+ const switchOffsetRight = Math.max(halfOfWidestSwitchElement - (totalBranchesWidth - joinX), 0);
1559
+ const viewWidth = switchOffsetLeft + totalBranchesWidth + switchOffsetRight;
1560
+ const viewHeight = maxBranchesHeight + cfg.paddingTop + cfg.nameLabel.height + cfg.branchNameLabel.height + cfg.connectionHeight * 2;
1561
+ const shiftedJoinX = switchOffsetLeft + joinX;
1562
+ Dom.translate(nameLabelView.g, shiftedJoinX, 0);
1563
+ const branchOffsetTop = cfg.paddingTop + cfg.nameLabel.height + cfg.branchNameLabel.height + cfg.connectionHeight;
1564
+ branchComponents.forEach((component, i) => {
1565
+ const branchSize = branchSizes[i];
1566
+ const branchOffsetLeft = switchOffsetLeft + branchSize.offsetX + branchSize.branchOffsetLeft;
1567
+ Dom.translate(branchLabelViews[i].g, switchOffsetLeft + branchSize.offsetX + branchSize.joinX, 0);
1568
+ Dom.translate(component.view.g, branchOffsetLeft, branchOffsetTop);
1569
+ if (component.hasOutput && stepContext.isOutputConnected) {
1570
+ const endOffsetTopOfComponent = cfg.paddingTop + cfg.nameLabel.height + cfg.branchNameLabel.height + cfg.connectionHeight + component.view.height;
1571
+ const missingHeight = viewHeight - endOffsetTopOfComponent - cfg.connectionHeight;
1572
+ if (missingHeight > 0) {
1573
+ JoinView.createStraightJoin(g, new Vector(switchOffsetLeft + branchSize.offsetX + branchSize.joinX, endOffsetTopOfComponent), missingHeight);
1574
+ }
1575
+ }
1576
+ });
1577
+ let inputView = null;
1578
+ if (cfg.inputSize > 0) {
1579
+ const iconUrl = viewContext.getStepIconUrl();
1580
+ inputView = InputView.createRectInput(g, shiftedJoinX, 0, cfg.inputSize, cfg.inputIconSize, iconUrl);
1581
+ }
1582
+ JoinView.createStraightJoin(g, new Vector(shiftedJoinX, 0), cfg.paddingTop);
1583
+ JoinView.createJoins(g, new Vector(shiftedJoinX, cfg.paddingTop + cfg.nameLabel.height), branchSizes.map(o => new Vector(switchOffsetLeft + o.offsetX + o.joinX, cfg.paddingTop + cfg.nameLabel.height + cfg.connectionHeight)));
1584
+ if (stepContext.isOutputConnected) {
1585
+ const ongoingSequenceIndexes = branchComponents
1586
+ .map((component, index) => (component.hasOutput ? index : null))
1587
+ .filter(index => index !== null);
1588
+ const ongoingJoinTargets = ongoingSequenceIndexes.map((i) => new Vector(switchOffsetLeft + branchSizes[i].offsetX + branchSizes[i].joinX, cfg.paddingTop + cfg.connectionHeight + cfg.nameLabel.height + cfg.branchNameLabel.height + maxBranchesHeight));
1589
+ if (ongoingJoinTargets.length > 0) {
1590
+ JoinView.createJoins(g, new Vector(shiftedJoinX, viewHeight), ongoingJoinTargets);
1585
1591
  }
1586
1592
  }
1593
+ const regions = branchSizes.map(s => s.width);
1594
+ regions[0] += switchOffsetLeft;
1595
+ regions[regions.length - 1] += switchOffsetRight;
1596
+ const regionView = regionViewBuilder(g, regions, viewHeight);
1597
+ return {
1598
+ g,
1599
+ width: viewWidth,
1600
+ height: viewHeight,
1601
+ joinX: shiftedJoinX,
1602
+ placeholders: null,
1603
+ sequenceComponents: branchComponents,
1604
+ hasOutput: branchComponents.some(c => c.hasOutput),
1605
+ getClientPosition() {
1606
+ return regionView.getClientPosition();
1607
+ },
1608
+ resolveClick(click) {
1609
+ const result = regionView.resolveClick(click);
1610
+ return result === true || (result === null && g.contains(click.element)) ? true : result;
1611
+ },
1612
+ setIsDragging(isDragging) {
1613
+ inputView === null || inputView === void 0 ? void 0 : inputView.setIsHidden(isDragging);
1614
+ },
1615
+ setIsSelected(isSelected) {
1616
+ regionView.setIsSelected(isSelected);
1617
+ },
1618
+ setIsDisabled(isDisabled) {
1619
+ Dom.toggleClass(g, isDisabled, 'sqd-disabled');
1620
+ }
1621
+ };
1587
1622
  });
1588
- let inputView = null;
1589
- if (cfg.inputSize > 0) {
1590
- const iconUrl = viewContext.getStepIconUrl();
1591
- inputView = InputView.createRectInput(g, shiftedJoinX, 0, cfg.inputSize, cfg.inputIconSize, iconUrl);
1592
- }
1593
- JoinView.createStraightJoin(g, new Vector(shiftedJoinX, 0), cfg.paddingTop);
1594
- JoinView.createJoins(g, new Vector(shiftedJoinX, cfg.paddingTop + cfg.nameLabel.height), branchSizes.map(o => new Vector(switchOffsetLeft + o.offsetX + o.joinX, cfg.paddingTop + cfg.nameLabel.height + cfg.connectionHeight)));
1595
- if (stepContext.isOutputConnected) {
1596
- const ongoingSequenceIndexes = branchComponents
1597
- .map((component, index) => (component.hasOutput ? index : null))
1598
- .filter(index => index !== null);
1599
- const ongoingJoinTargets = ongoingSequenceIndexes.map((i) => new Vector(switchOffsetLeft + branchSizes[i].offsetX + branchSizes[i].joinX, cfg.paddingTop + cfg.connectionHeight + cfg.nameLabel.height + cfg.branchNameLabel.height + maxBranchesHeight));
1600
- if (ongoingJoinTargets.length > 0) {
1601
- JoinView.createJoins(g, new Vector(shiftedJoinX, viewHeight), ongoingJoinTargets);
1602
- }
1603
- }
1604
- const regions = branchSizes.map(s => s.width);
1605
- regions[0] += switchOffsetLeft;
1606
- regions[regions.length - 1] += switchOffsetRight;
1607
- const regionView = RegionView.create(g, regions, viewHeight);
1608
- return {
1609
- g,
1610
- width: viewWidth,
1611
- height: viewHeight,
1612
- joinX: shiftedJoinX,
1613
- placeholders: null,
1614
- sequenceComponents: branchComponents,
1615
- getClientPosition() {
1616
- return regionView.getClientPosition();
1617
- },
1618
- resolveClick(click) {
1619
- return regionView.resolveClick(click) || g.contains(click.element) ? true : null;
1620
- },
1621
- setIsDragging(isDragging) {
1622
- inputView === null || inputView === void 0 ? void 0 : inputView.setIsHidden(isDragging);
1623
- },
1624
- setIsSelected(isSelected) {
1625
- regionView.setIsSelected(isSelected);
1626
- },
1627
- setIsDisabled(isDisabled) {
1628
- Dom.toggleClass(g, isDisabled, 'sqd-disabled');
1629
- },
1630
- hasOutput() {
1631
- return branchComponents.some(c => c.hasOutput);
1632
- }
1633
- };
1634
1623
  };
1635
1624
 
1625
+ const COMPONENT_CLASS_NAME = 'task';
1636
1626
  const createTaskStepComponentViewFactory = (isInterrupted, cfg) => (parentElement, stepContext, viewContext) => {
1637
1627
  const { step } = stepContext;
1638
- const g = ComponentDom.stepG('task', step.type, step.id);
1628
+ const g = ComponentDom.stepG(COMPONENT_CLASS_NAME, step.type, step.id);
1639
1629
  parentElement.appendChild(g);
1640
1630
  const boxHeight = cfg.paddingY * 2 + cfg.iconSize;
1641
1631
  const text = Dom.svg('text', {
@@ -1685,9 +1675,7 @@ const createTaskStepComponentViewFactory = (isInterrupted, cfg) => (parentElemen
1685
1675
  joinX: boxWidth / 2,
1686
1676
  sequenceComponents: null,
1687
1677
  placeholders: null,
1688
- hasOutput() {
1689
- return !!outputView;
1690
- },
1678
+ hasOutput: !!outputView,
1691
1679
  getClientPosition() {
1692
1680
  return getAbsolutePosition(rect);
1693
1681
  },
@@ -1976,6 +1964,64 @@ class RectPlaceholder {
1976
1964
  }
1977
1965
  }
1978
1966
 
1967
+ class DefaultRegionView {
1968
+ static create(parent, widths, height) {
1969
+ const totalWidth = widths.reduce((result, width) => result + width, 0);
1970
+ const lines = [
1971
+ drawLine(parent, 0, 0, totalWidth, 0),
1972
+ drawLine(parent, 0, 0, 0, height),
1973
+ drawLine(parent, 0, height, totalWidth, height),
1974
+ drawLine(parent, totalWidth, 0, totalWidth, height)
1975
+ ];
1976
+ let offsetX = widths[0];
1977
+ for (let i = 1; i < widths.length; i++) {
1978
+ lines.push(drawLine(parent, offsetX, 0, offsetX, height));
1979
+ offsetX += widths[i];
1980
+ }
1981
+ return new DefaultRegionView(lines, totalWidth, height);
1982
+ }
1983
+ constructor(lines, width, height) {
1984
+ this.lines = lines;
1985
+ this.width = width;
1986
+ this.height = height;
1987
+ }
1988
+ getClientPosition() {
1989
+ return getAbsolutePosition(this.lines[0]);
1990
+ }
1991
+ resolveClick(click) {
1992
+ const regionPosition = this.getClientPosition();
1993
+ const d = click.position.subtract(regionPosition);
1994
+ if (d.x >= 0 && d.y >= 0 && d.x < this.width * click.scale && d.y < this.height * click.scale) {
1995
+ return true;
1996
+ }
1997
+ return null;
1998
+ }
1999
+ setIsSelected(isSelected) {
2000
+ this.lines.forEach(region => {
2001
+ Dom.toggleClass(region, isSelected, 'sqd-selected');
2002
+ });
2003
+ }
2004
+ }
2005
+ function drawLine(parent, x1, y1, x2, y2) {
2006
+ const line = Dom.svg('line', {
2007
+ class: 'sqd-region',
2008
+ x1,
2009
+ y1,
2010
+ x2,
2011
+ y2
2012
+ });
2013
+ parent.insertBefore(line, parent.firstChild);
2014
+ return line;
2015
+ }
2016
+
2017
+ class DefaultRegionComponentViewExtension {
2018
+ create(parentElement, componentClassName, stepContext, _, contentFactory) {
2019
+ const g = ComponentDom.stepG(componentClassName, stepContext.step.type, stepContext.step.id);
2020
+ parentElement.appendChild(g);
2021
+ return contentFactory(g, DefaultRegionView.create);
2022
+ }
2023
+ }
2024
+
1979
2025
  function readMousePosition(e) {
1980
2026
  return new Vector(e.pageX, e.pageY);
1981
2027
  }
@@ -2477,9 +2523,22 @@ class WorkspaceControllerWrapper {
2477
2523
  }
2478
2524
  }
2479
2525
 
2526
+ class MemoryPreferenceStorage {
2527
+ constructor() {
2528
+ this.map = {};
2529
+ }
2530
+ setItem(key, value) {
2531
+ this.map[key] = value;
2532
+ }
2533
+ getItem(key) {
2534
+ var _a;
2535
+ return (_a = this.map[key]) !== null && _a !== void 0 ? _a : null;
2536
+ }
2537
+ }
2538
+
2480
2539
  class DesignerContext {
2481
2540
  static create(parent, startDefinition, configuration, services) {
2482
- var _a, _b, _c, _d;
2541
+ var _a, _b, _c, _d, _e;
2483
2542
  const definition = ObjectCloner.deepClone(startDefinition);
2484
2543
  const layoutController = new LayoutController(parent);
2485
2544
  const isReadonly = !!configuration.isReadonly;
@@ -2498,7 +2557,8 @@ class DesignerContext {
2498
2557
  if (configuration.undoStackSize) {
2499
2558
  historyController = HistoryController.create(configuration.undoStack, state, stateModifier, configuration);
2500
2559
  }
2501
- const componentContext = ComponentContext.create(configuration.steps, configuration.validator, state, stepExtensionResolver, i18n, services);
2560
+ const preferenceStorage = (_e = configuration.preferenceStorage) !== null && _e !== void 0 ? _e : new MemoryPreferenceStorage();
2561
+ const componentContext = ComponentContext.create(configuration, state, stepExtensionResolver, definitionWalker, preferenceStorage, i18n, services);
2502
2562
  return new DesignerContext(theme, state, configuration, services, componentContext, definitionWalker, i18n, stateModifier, layoutController, workspaceController, behaviorController, customActionController, historyController);
2503
2563
  }
2504
2564
  constructor(theme, state, configuration, services, componentContext, definitionWalker, i18n, stateModifier, layoutController, workspaceController, behaviorController, customActionController, historyController) {
@@ -3924,7 +3984,7 @@ class DefaultPlaceholderControllerExtension {
3924
3984
  }
3925
3985
 
3926
3986
  const defaultConfiguration$3 = {
3927
- gapWidth: 100,
3987
+ gapWidth: 88,
3928
3988
  gapHeight: 24,
3929
3989
  radius: 6,
3930
3990
  iconSize: 16
@@ -4193,6 +4253,9 @@ function merge(services, extensions) {
4193
4253
  if (ext.placeholder) {
4194
4254
  services.placeholder = ext.placeholder;
4195
4255
  }
4256
+ if (ext.regionComponentView) {
4257
+ services.regionComponentView = ext.regionComponentView;
4258
+ }
4196
4259
  if (ext.viewportController) {
4197
4260
  services.viewportController = ext.viewportController;
4198
4261
  }
@@ -4253,6 +4316,9 @@ function setDefaults(services, configuration) {
4253
4316
  if (!services.placeholder) {
4254
4317
  services.placeholder = RectPlaceholderExtension.create();
4255
4318
  }
4319
+ if (!services.regionComponentView) {
4320
+ services.regionComponentView = new DefaultRegionComponentViewExtension();
4321
+ }
4256
4322
  if (!services.viewportController) {
4257
4323
  services.viewportController = new DefaultViewportControllerExtension();
4258
4324
  }
@@ -4531,4 +4597,4 @@ class StepsDesignerExtension {
4531
4597
  }
4532
4598
  }
4533
4599
 
4534
- export { Badges, CenteredViewportCalculator, ClassicWheelControllerExtension, ClickCommandType, ComponentContext, ComponentDom, ControlBarApi, CustomActionController, DefaultSequenceComponent, DefaultSequenceComponentView, DefaultViewportController, DefaultViewportControllerExtension, DefinitionChangeType, Designer, DesignerApi, DesignerContext, DesignerState, Dom, Editor, EditorApi, Icons, InputView, JoinView, KeyboardAction, LabelView, LineGridDesignerExtension, ObjectCloner, OutputView, PathBarApi, PlaceholderDirection, QuantifiedScaleViewportCalculator, RectPlaceholder, RectPlaceholderView, RegionView, ServicesResolver, SimpleEvent, StepComponent, StepExtensionResolver, StepsDesignerExtension, ToolboxApi, Uid, ValidationErrorBadgeExtension, Vector, WorkspaceApi, createContainerStepComponentViewFactory, createSwitchStepComponentViewFactory, createTaskStepComponentViewFactory, getAbsolutePosition, race };
4600
+ export { Badges, CenteredViewportCalculator, ClassicWheelControllerExtension, ClickCommandType, ComponentContext, ComponentDom, ControlBarApi, CustomActionController, DefaultRegionComponentViewExtension, DefaultRegionView, DefaultSequenceComponent, DefaultSequenceComponentView, DefaultViewportController, DefaultViewportControllerExtension, DefinitionChangeType, Designer, DesignerApi, DesignerContext, DesignerState, Dom, Editor, EditorApi, Icons, InputView, JoinView, KeyboardAction, LabelView, LineGridDesignerExtension, ObjectCloner, OutputView, PathBarApi, PlaceholderDirection, QuantifiedScaleViewportCalculator, RectPlaceholder, RectPlaceholderView, ServicesResolver, SimpleEvent, StepComponent, StepExtensionResolver, StepsDesignerExtension, ToolboxApi, Uid, ValidationErrorBadgeExtension, Vector, WorkspaceApi, createContainerStepComponentViewFactory, createSwitchStepComponentViewFactory, createTaskStepComponentViewFactory, getAbsolutePosition, race };