sequential-workflow-designer 0.27.4 → 0.29.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/README.md +4 -4
- package/dist/index.umd.js +324 -278
- package/lib/cjs/index.cjs +142 -96
- package/lib/esm/index.js +142 -96
- package/lib/index.d.ts +18 -6
- package/package.json +5 -5
package/dist/index.umd.js
CHANGED
|
@@ -769,9 +769,193 @@
|
|
|
769
769
|
}
|
|
770
770
|
}
|
|
771
771
|
|
|
772
|
+
const defaultResolvers = [sequentialResolver, branchedResolver];
|
|
773
|
+
function branchedResolver(step) {
|
|
774
|
+
const branches = step.branches;
|
|
775
|
+
if (branches) {
|
|
776
|
+
return { type: exports.StepChildrenType.branches, items: branches };
|
|
777
|
+
}
|
|
778
|
+
return null;
|
|
779
|
+
}
|
|
780
|
+
function sequentialResolver(step) {
|
|
781
|
+
const sequence = step.sequence;
|
|
782
|
+
if (sequence) {
|
|
783
|
+
return { type: exports.StepChildrenType.sequence, items: sequence };
|
|
784
|
+
}
|
|
785
|
+
return null;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
exports.StepChildrenType = void 0;
|
|
789
|
+
(function (StepChildrenType) {
|
|
790
|
+
StepChildrenType[StepChildrenType["sequence"] = 1] = "sequence";
|
|
791
|
+
StepChildrenType[StepChildrenType["branches"] = 2] = "branches";
|
|
792
|
+
})(exports.StepChildrenType || (exports.StepChildrenType = {}));
|
|
793
|
+
class DefinitionWalker {
|
|
794
|
+
constructor(resolvers) {
|
|
795
|
+
this.resolvers = resolvers ? resolvers.concat(defaultResolvers) : defaultResolvers;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Returns children of the step. If the step doesn't have children, returns null.
|
|
799
|
+
* @param step The step.
|
|
800
|
+
*/
|
|
801
|
+
getChildren(step) {
|
|
802
|
+
const count = this.resolvers.length;
|
|
803
|
+
for (let i = 0; i < count; i++) {
|
|
804
|
+
const result = this.resolvers[i](step);
|
|
805
|
+
if (result) {
|
|
806
|
+
return result;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
return null;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Returns the parents of the step or the sequence.
|
|
813
|
+
* @param definition The definition.
|
|
814
|
+
* @param needle The step, stepId or sequence to find.
|
|
815
|
+
* @returns The parents of the step or the sequence.
|
|
816
|
+
*/
|
|
817
|
+
getParents(definition, needle) {
|
|
818
|
+
const result = [];
|
|
819
|
+
let searchSequence = null;
|
|
820
|
+
let searchStepId = null;
|
|
821
|
+
if (Array.isArray(needle)) {
|
|
822
|
+
searchSequence = needle;
|
|
823
|
+
}
|
|
824
|
+
else if (typeof needle === 'string') {
|
|
825
|
+
searchStepId = needle;
|
|
826
|
+
}
|
|
827
|
+
else {
|
|
828
|
+
searchStepId = needle.id;
|
|
829
|
+
}
|
|
830
|
+
if (this.find(definition.sequence, searchSequence, searchStepId, result)) {
|
|
831
|
+
result.reverse();
|
|
832
|
+
return result.map(item => {
|
|
833
|
+
return typeof item === 'string' ? item : item.step;
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
throw new Error(searchStepId ? `Cannot get parents of step: ${searchStepId}` : 'Cannot get parents of sequence');
|
|
837
|
+
}
|
|
838
|
+
findParentSequence(definition, stepId) {
|
|
839
|
+
const result = [];
|
|
840
|
+
if (this.find(definition.sequence, null, stepId, result)) {
|
|
841
|
+
return result[0];
|
|
842
|
+
}
|
|
843
|
+
return null;
|
|
844
|
+
}
|
|
845
|
+
getParentSequence(definition, stepId) {
|
|
846
|
+
const result = this.findParentSequence(definition, stepId);
|
|
847
|
+
if (!result) {
|
|
848
|
+
throw new Error(`Cannot find step by id: ${stepId}`);
|
|
849
|
+
}
|
|
850
|
+
return result;
|
|
851
|
+
}
|
|
852
|
+
findById(definition, stepId) {
|
|
853
|
+
const result = this.findParentSequence(definition, stepId);
|
|
854
|
+
return result ? result.step : null;
|
|
855
|
+
}
|
|
856
|
+
getById(definition, stepId) {
|
|
857
|
+
return this.getParentSequence(definition, stepId).step;
|
|
858
|
+
}
|
|
859
|
+
forEach(definition, callback) {
|
|
860
|
+
this.iterateSequence(definition.sequence, callback);
|
|
861
|
+
}
|
|
862
|
+
forEachSequence(sequence, callback) {
|
|
863
|
+
this.iterateSequence(sequence, callback);
|
|
864
|
+
}
|
|
865
|
+
forEachChildren(step, callback) {
|
|
866
|
+
this.iterateStep(step, callback);
|
|
867
|
+
}
|
|
868
|
+
find(sequence, needSequence, needStepId, result) {
|
|
869
|
+
if (needSequence && sequence === needSequence) {
|
|
870
|
+
return true;
|
|
871
|
+
}
|
|
872
|
+
const count = sequence.length;
|
|
873
|
+
for (let index = 0; index < count; index++) {
|
|
874
|
+
const step = sequence[index];
|
|
875
|
+
if (needStepId && step.id === needStepId) {
|
|
876
|
+
result.push({ step, index, parentSequence: sequence });
|
|
877
|
+
return true;
|
|
878
|
+
}
|
|
879
|
+
const children = this.getChildren(step);
|
|
880
|
+
if (children) {
|
|
881
|
+
switch (children.type) {
|
|
882
|
+
case exports.StepChildrenType.sequence:
|
|
883
|
+
{
|
|
884
|
+
const parentSequence = children.items;
|
|
885
|
+
if (this.find(parentSequence, needSequence, needStepId, result)) {
|
|
886
|
+
result.push({ step, index, parentSequence });
|
|
887
|
+
return true;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
break;
|
|
891
|
+
case exports.StepChildrenType.branches:
|
|
892
|
+
{
|
|
893
|
+
const branches = children.items;
|
|
894
|
+
const branchNames = Object.keys(branches);
|
|
895
|
+
for (const branchName of branchNames) {
|
|
896
|
+
const parentSequence = branches[branchName];
|
|
897
|
+
if (this.find(parentSequence, needSequence, needStepId, result)) {
|
|
898
|
+
result.push(branchName);
|
|
899
|
+
result.push({ step, index, parentSequence });
|
|
900
|
+
return true;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
break;
|
|
905
|
+
default:
|
|
906
|
+
throw new Error(`Not supported step children type: ${children.type}`);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
return false;
|
|
911
|
+
}
|
|
912
|
+
iterateSequence(sequence, callback) {
|
|
913
|
+
const count = sequence.length;
|
|
914
|
+
for (let index = 0; index < count; index++) {
|
|
915
|
+
const step = sequence[index];
|
|
916
|
+
if (callback(step, index, sequence) === false) {
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
if (!this.iterateStep(step, callback)) {
|
|
920
|
+
return false;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
return true;
|
|
924
|
+
}
|
|
925
|
+
iterateStep(step, callback) {
|
|
926
|
+
const children = this.getChildren(step);
|
|
927
|
+
if (children) {
|
|
928
|
+
switch (children.type) {
|
|
929
|
+
case exports.StepChildrenType.sequence:
|
|
930
|
+
{
|
|
931
|
+
const sequence = children.items;
|
|
932
|
+
if (!this.iterateSequence(sequence, callback)) {
|
|
933
|
+
return false;
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
break;
|
|
937
|
+
case exports.StepChildrenType.branches:
|
|
938
|
+
{
|
|
939
|
+
const sequences = Object.values(children.items);
|
|
940
|
+
for (const sequence of sequences) {
|
|
941
|
+
if (!this.iterateSequence(sequence, callback)) {
|
|
942
|
+
return false;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
break;
|
|
947
|
+
default:
|
|
948
|
+
throw new Error(`Not supported step children type: ${children.type}`);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
return true;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
772
955
|
class WorkspaceApi {
|
|
773
|
-
constructor(state, workspaceController) {
|
|
956
|
+
constructor(state, definitionWalker, workspaceController) {
|
|
774
957
|
this.state = state;
|
|
958
|
+
this.definitionWalker = definitionWalker;
|
|
775
959
|
this.workspaceController = workspaceController;
|
|
776
960
|
}
|
|
777
961
|
getViewport() {
|
|
@@ -798,11 +982,29 @@
|
|
|
798
982
|
updateCanvasSize() {
|
|
799
983
|
this.workspaceController.updateCanvasSize();
|
|
800
984
|
}
|
|
985
|
+
getRootSequence() {
|
|
986
|
+
const stepId = this.state.tryGetLastStepIdFromFolderPath();
|
|
987
|
+
if (stepId) {
|
|
988
|
+
const parentStep = this.definitionWalker.getParentSequence(this.state.definition, stepId);
|
|
989
|
+
const children = this.definitionWalker.getChildren(parentStep.step);
|
|
990
|
+
if (!children || children.type !== exports.StepChildrenType.sequence) {
|
|
991
|
+
throw new Error('Cannot find single sequence in folder step');
|
|
992
|
+
}
|
|
993
|
+
return {
|
|
994
|
+
sequence: children.items,
|
|
995
|
+
parentStep
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
return {
|
|
999
|
+
sequence: this.state.definition.sequence,
|
|
1000
|
+
parentStep: null
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
801
1003
|
}
|
|
802
1004
|
|
|
803
1005
|
class DesignerApi {
|
|
804
1006
|
static create(context) {
|
|
805
|
-
const workspace = new WorkspaceApi(context.state, context.workspaceController);
|
|
1007
|
+
const workspace = new WorkspaceApi(context.state, context.definitionWalker, context.workspaceController);
|
|
806
1008
|
const viewportController = context.services.viewportController.create(workspace);
|
|
807
1009
|
const toolboxDataProvider = new ToolboxDataProvider(context.componentContext.iconProvider, context.i18n, context.configuration.toolbox);
|
|
808
1010
|
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);
|
|
@@ -1061,11 +1263,11 @@
|
|
|
1061
1263
|
parent.appendChild(circle);
|
|
1062
1264
|
return new InputView(circle);
|
|
1063
1265
|
}
|
|
1064
|
-
constructor(
|
|
1065
|
-
this.
|
|
1266
|
+
constructor(g) {
|
|
1267
|
+
this.g = g;
|
|
1066
1268
|
}
|
|
1067
1269
|
setIsHidden(isHidden) {
|
|
1068
|
-
Dom.attrs(this.
|
|
1270
|
+
Dom.attrs(this.g, {
|
|
1069
1271
|
visibility: isHidden ? 'hidden' : 'visible'
|
|
1070
1272
|
});
|
|
1071
1273
|
}
|
|
@@ -1490,31 +1692,77 @@
|
|
|
1490
1692
|
};
|
|
1491
1693
|
|
|
1492
1694
|
const COMPONENT_CLASS_NAME$1 = 'switch';
|
|
1695
|
+
function createView(g, width, height, joinX, viewContext, sequenceComponents, regionView, cfg) {
|
|
1696
|
+
let inputView = null;
|
|
1697
|
+
if (cfg.inputSize > 0) {
|
|
1698
|
+
const iconUrl = viewContext.getStepIconUrl();
|
|
1699
|
+
inputView = InputView.createRectInput(g, joinX, cfg.paddingTop1, cfg.inputSize, cfg.inputRadius, cfg.inputIconSize, iconUrl);
|
|
1700
|
+
}
|
|
1701
|
+
return {
|
|
1702
|
+
g,
|
|
1703
|
+
width,
|
|
1704
|
+
height,
|
|
1705
|
+
joinX,
|
|
1706
|
+
placeholders: null,
|
|
1707
|
+
sequenceComponents,
|
|
1708
|
+
hasOutput: sequenceComponents ? sequenceComponents.some(c => c.hasOutput) : true,
|
|
1709
|
+
getClientPosition() {
|
|
1710
|
+
return regionView.getClientPosition();
|
|
1711
|
+
},
|
|
1712
|
+
resolveClick(click) {
|
|
1713
|
+
const result = regionView.resolveClick(click);
|
|
1714
|
+
return result === true || (result === null && g.contains(click.element)) ? true : result;
|
|
1715
|
+
},
|
|
1716
|
+
setIsDragging(isDragging) {
|
|
1717
|
+
if (cfg.autoHideInputOnDrag && inputView) {
|
|
1718
|
+
inputView.setIsHidden(isDragging);
|
|
1719
|
+
}
|
|
1720
|
+
},
|
|
1721
|
+
setIsSelected(isSelected) {
|
|
1722
|
+
regionView.setIsSelected(isSelected);
|
|
1723
|
+
},
|
|
1724
|
+
setIsDisabled(isDisabled) {
|
|
1725
|
+
Dom.toggleClass(g, isDisabled, 'sqd-disabled');
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
}
|
|
1493
1729
|
const createSwitchStepComponentViewFactory = (cfg) => (parent, stepContext, viewContext) => {
|
|
1494
1730
|
return viewContext.createRegionComponentView(parent, COMPONENT_CLASS_NAME$1, (g, regionViewBuilder) => {
|
|
1495
1731
|
const step = stepContext.step;
|
|
1496
1732
|
const paddingTop = cfg.paddingTop1 + cfg.paddingTop2;
|
|
1733
|
+
const name = viewContext.getStepName();
|
|
1734
|
+
const nameLabelView = LabelView.create(g, paddingTop, cfg.nameLabel, name, 'primary');
|
|
1497
1735
|
const branchNames = Object.keys(step.branches);
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1736
|
+
if (branchNames.length === 0) {
|
|
1737
|
+
const width = Math.max(nameLabelView.width, cfg.minBranchWidth) + cfg.paddingX * 2;
|
|
1738
|
+
const height = nameLabelView.height + paddingTop + cfg.noBranchPaddingBottom;
|
|
1739
|
+
const joinX = width / 2;
|
|
1740
|
+
const regionView = regionViewBuilder(g, [width], height);
|
|
1741
|
+
Dom.translate(nameLabelView.g, joinX, 0);
|
|
1742
|
+
JoinView.createStraightJoin(g, new Vector(joinX, 0), height);
|
|
1743
|
+
return createView(g, width, height, joinX, viewContext, null, regionView, cfg);
|
|
1744
|
+
}
|
|
1745
|
+
const branchComponents = [];
|
|
1746
|
+
const branchLabelViews = [];
|
|
1747
|
+
const branchSizes = [];
|
|
1748
|
+
let totalBranchesWidth = 0;
|
|
1749
|
+
let maxBranchesHeight = 0;
|
|
1750
|
+
branchNames.forEach(branchName => {
|
|
1751
|
+
const component = viewContext.createSequenceComponent(g, step.branches[branchName]);
|
|
1502
1752
|
const labelY = paddingTop + cfg.nameLabel.height + cfg.connectionHeight;
|
|
1503
1753
|
const translatedBranchName = viewContext.i18n(`stepComponent.${step.type}.branchName`, branchName);
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
const name = viewContext.getStepName();
|
|
1507
|
-
const nameLabelView = LabelView.create(g, paddingTop, cfg.nameLabel, name, 'primary');
|
|
1508
|
-
let prevOffsetX = 0;
|
|
1509
|
-
const branchSizes = branchComponents.map((component, i) => {
|
|
1510
|
-
const halfOfWidestBranchElement = Math.max(branchLabelViews[i].width, cfg.minContainerWidth) / 2;
|
|
1754
|
+
const labelView = LabelView.create(g, labelY, cfg.branchNameLabel, translatedBranchName, 'secondary');
|
|
1755
|
+
const halfOfWidestBranchElement = Math.max(labelView.width, cfg.minBranchWidth) / 2;
|
|
1511
1756
|
const branchOffsetLeft = Math.max(halfOfWidestBranchElement - component.view.joinX, 0) + cfg.paddingX;
|
|
1512
1757
|
const branchOffsetRight = Math.max(halfOfWidestBranchElement - (component.view.width - component.view.joinX), 0) + cfg.paddingX;
|
|
1513
1758
|
const width = component.view.width + branchOffsetLeft + branchOffsetRight;
|
|
1514
1759
|
const joinX = component.view.joinX + branchOffsetLeft;
|
|
1515
|
-
const offsetX =
|
|
1516
|
-
|
|
1517
|
-
|
|
1760
|
+
const offsetX = totalBranchesWidth;
|
|
1761
|
+
totalBranchesWidth += width;
|
|
1762
|
+
maxBranchesHeight = Math.max(maxBranchesHeight, component.view.height);
|
|
1763
|
+
branchComponents.push(component);
|
|
1764
|
+
branchLabelViews.push(labelView);
|
|
1765
|
+
branchSizes.push({ width, branchOffsetLeft, offsetX, joinX });
|
|
1518
1766
|
});
|
|
1519
1767
|
const centerBranchIndex = Math.floor(branchNames.length / 2);
|
|
1520
1768
|
const centerBranchSize = branchSizes[centerBranchIndex];
|
|
@@ -1522,8 +1770,6 @@
|
|
|
1522
1770
|
if (branchNames.length % 2 !== 0) {
|
|
1523
1771
|
joinX += centerBranchSize.joinX;
|
|
1524
1772
|
}
|
|
1525
|
-
const totalBranchesWidth = branchSizes.reduce((result, s) => result + s.width, 0);
|
|
1526
|
-
const maxBranchesHeight = Math.max(...branchComponents.map(s => s.view.height));
|
|
1527
1773
|
const halfOfWidestSwitchElement = nameLabelView.width / 2 + cfg.paddingX;
|
|
1528
1774
|
const switchOffsetLeft = Math.max(halfOfWidestSwitchElement - joinX, 0);
|
|
1529
1775
|
const switchOffsetRight = Math.max(halfOfWidestSwitchElement - (totalBranchesWidth - joinX), 0);
|
|
@@ -1545,18 +1791,16 @@
|
|
|
1545
1791
|
}
|
|
1546
1792
|
}
|
|
1547
1793
|
});
|
|
1548
|
-
let inputView = null;
|
|
1549
|
-
if (cfg.inputSize > 0) {
|
|
1550
|
-
const iconUrl = viewContext.getStepIconUrl();
|
|
1551
|
-
inputView = InputView.createRectInput(g, shiftedJoinX, cfg.paddingTop1, cfg.inputSize, cfg.inputRadius, cfg.inputIconSize, iconUrl);
|
|
1552
|
-
}
|
|
1553
1794
|
JoinView.createStraightJoin(g, new Vector(shiftedJoinX, 0), paddingTop);
|
|
1554
|
-
JoinView.createJoins(g, new Vector(shiftedJoinX, paddingTop + cfg.nameLabel.height), branchSizes.map(
|
|
1795
|
+
JoinView.createJoins(g, new Vector(shiftedJoinX, paddingTop + cfg.nameLabel.height), branchSizes.map(s => new Vector(switchOffsetLeft + s.offsetX + s.joinX, paddingTop + cfg.nameLabel.height + cfg.connectionHeight)));
|
|
1555
1796
|
if (stepContext.isOutputConnected) {
|
|
1556
1797
|
const ongoingSequenceIndexes = branchComponents
|
|
1557
1798
|
.map((component, index) => (component.hasOutput ? index : null))
|
|
1558
1799
|
.filter(index => index !== null);
|
|
1559
|
-
const ongoingJoinTargets = ongoingSequenceIndexes.map((i) =>
|
|
1800
|
+
const ongoingJoinTargets = ongoingSequenceIndexes.map((i) => {
|
|
1801
|
+
const branchSize = branchSizes[i];
|
|
1802
|
+
return new Vector(switchOffsetLeft + branchSize.offsetX + branchSize.joinX, paddingTop + cfg.connectionHeight + cfg.nameLabel.height + cfg.branchNameLabel.height + maxBranchesHeight);
|
|
1803
|
+
});
|
|
1560
1804
|
if (ongoingJoinTargets.length > 0) {
|
|
1561
1805
|
JoinView.createJoins(g, new Vector(shiftedJoinX, viewHeight), ongoingJoinTargets);
|
|
1562
1806
|
}
|
|
@@ -1565,33 +1809,7 @@
|
|
|
1565
1809
|
regions[0] += switchOffsetLeft;
|
|
1566
1810
|
regions[regions.length - 1] += switchOffsetRight;
|
|
1567
1811
|
const regionView = regionViewBuilder(g, regions, viewHeight);
|
|
1568
|
-
return
|
|
1569
|
-
g,
|
|
1570
|
-
width: viewWidth,
|
|
1571
|
-
height: viewHeight,
|
|
1572
|
-
joinX: shiftedJoinX,
|
|
1573
|
-
placeholders: null,
|
|
1574
|
-
sequenceComponents: branchComponents,
|
|
1575
|
-
hasOutput: branchComponents.some(c => c.hasOutput),
|
|
1576
|
-
getClientPosition() {
|
|
1577
|
-
return regionView.getClientPosition();
|
|
1578
|
-
},
|
|
1579
|
-
resolveClick(click) {
|
|
1580
|
-
const result = regionView.resolveClick(click);
|
|
1581
|
-
return result === true || (result === null && g.contains(click.element)) ? true : result;
|
|
1582
|
-
},
|
|
1583
|
-
setIsDragging(isDragging) {
|
|
1584
|
-
if (cfg.autoHideInputOnDrag && inputView) {
|
|
1585
|
-
inputView.setIsHidden(isDragging);
|
|
1586
|
-
}
|
|
1587
|
-
},
|
|
1588
|
-
setIsSelected(isSelected) {
|
|
1589
|
-
regionView.setIsSelected(isSelected);
|
|
1590
|
-
},
|
|
1591
|
-
setIsDisabled(isDisabled) {
|
|
1592
|
-
Dom.toggleClass(g, isDisabled, 'sqd-disabled');
|
|
1593
|
-
}
|
|
1594
|
-
};
|
|
1812
|
+
return createView(g, viewWidth, viewHeight, shiftedJoinX, viewContext, branchComponents, regionView, cfg);
|
|
1595
1813
|
});
|
|
1596
1814
|
};
|
|
1597
1815
|
|
|
@@ -2116,11 +2334,12 @@
|
|
|
2116
2334
|
|
|
2117
2335
|
const defaultConfiguration$2 = {
|
|
2118
2336
|
view: {
|
|
2119
|
-
|
|
2337
|
+
minBranchWidth: 88,
|
|
2120
2338
|
paddingX: 20,
|
|
2121
2339
|
paddingTop1: 0,
|
|
2122
2340
|
paddingTop2: 22,
|
|
2123
|
-
connectionHeight:
|
|
2341
|
+
connectionHeight: 20,
|
|
2342
|
+
noBranchPaddingBottom: 24,
|
|
2124
2343
|
inputSize: 18,
|
|
2125
2344
|
inputIconSize: 14,
|
|
2126
2345
|
inputRadius: 4,
|
|
@@ -2379,189 +2598,6 @@
|
|
|
2379
2598
|
}
|
|
2380
2599
|
}
|
|
2381
2600
|
|
|
2382
|
-
const defaultResolvers = [sequentialResolver, branchedResolver];
|
|
2383
|
-
function branchedResolver(step) {
|
|
2384
|
-
const branches = step.branches;
|
|
2385
|
-
if (branches) {
|
|
2386
|
-
return { type: exports.StepChildrenType.branches, items: branches };
|
|
2387
|
-
}
|
|
2388
|
-
return null;
|
|
2389
|
-
}
|
|
2390
|
-
function sequentialResolver(step) {
|
|
2391
|
-
const sequence = step.sequence;
|
|
2392
|
-
if (sequence) {
|
|
2393
|
-
return { type: exports.StepChildrenType.sequence, items: sequence };
|
|
2394
|
-
}
|
|
2395
|
-
return null;
|
|
2396
|
-
}
|
|
2397
|
-
|
|
2398
|
-
exports.StepChildrenType = void 0;
|
|
2399
|
-
(function (StepChildrenType) {
|
|
2400
|
-
StepChildrenType[StepChildrenType["sequence"] = 1] = "sequence";
|
|
2401
|
-
StepChildrenType[StepChildrenType["branches"] = 2] = "branches";
|
|
2402
|
-
})(exports.StepChildrenType || (exports.StepChildrenType = {}));
|
|
2403
|
-
class DefinitionWalker {
|
|
2404
|
-
constructor(resolvers) {
|
|
2405
|
-
this.resolvers = resolvers ? resolvers.concat(defaultResolvers) : defaultResolvers;
|
|
2406
|
-
}
|
|
2407
|
-
/**
|
|
2408
|
-
* Returns children of the step. If the step doesn't have children, returns null.
|
|
2409
|
-
* @param step The step.
|
|
2410
|
-
*/
|
|
2411
|
-
getChildren(step) {
|
|
2412
|
-
const count = this.resolvers.length;
|
|
2413
|
-
for (let i = 0; i < count; i++) {
|
|
2414
|
-
const result = this.resolvers[i](step);
|
|
2415
|
-
if (result) {
|
|
2416
|
-
return result;
|
|
2417
|
-
}
|
|
2418
|
-
}
|
|
2419
|
-
return null;
|
|
2420
|
-
}
|
|
2421
|
-
/**
|
|
2422
|
-
* Returns the parents of the step or the sequence.
|
|
2423
|
-
* @param definition The definition.
|
|
2424
|
-
* @param needle The step, stepId or sequence to find.
|
|
2425
|
-
* @returns The parents of the step or the sequence.
|
|
2426
|
-
*/
|
|
2427
|
-
getParents(definition, needle) {
|
|
2428
|
-
const result = [];
|
|
2429
|
-
let searchSequence = null;
|
|
2430
|
-
let searchStepId = null;
|
|
2431
|
-
if (Array.isArray(needle)) {
|
|
2432
|
-
searchSequence = needle;
|
|
2433
|
-
}
|
|
2434
|
-
else if (typeof needle === 'string') {
|
|
2435
|
-
searchStepId = needle;
|
|
2436
|
-
}
|
|
2437
|
-
else {
|
|
2438
|
-
searchStepId = needle.id;
|
|
2439
|
-
}
|
|
2440
|
-
if (this.find(definition.sequence, searchSequence, searchStepId, result)) {
|
|
2441
|
-
result.reverse();
|
|
2442
|
-
return result.map(item => {
|
|
2443
|
-
return typeof item === 'string' ? item : item.step;
|
|
2444
|
-
});
|
|
2445
|
-
}
|
|
2446
|
-
throw new Error(searchStepId ? `Cannot get parents of step: ${searchStepId}` : 'Cannot get parents of sequence');
|
|
2447
|
-
}
|
|
2448
|
-
findParentSequence(definition, stepId) {
|
|
2449
|
-
const result = [];
|
|
2450
|
-
if (this.find(definition.sequence, null, stepId, result)) {
|
|
2451
|
-
return result[0];
|
|
2452
|
-
}
|
|
2453
|
-
return null;
|
|
2454
|
-
}
|
|
2455
|
-
getParentSequence(definition, stepId) {
|
|
2456
|
-
const result = this.findParentSequence(definition, stepId);
|
|
2457
|
-
if (!result) {
|
|
2458
|
-
throw new Error(`Cannot find step by id: ${stepId}`);
|
|
2459
|
-
}
|
|
2460
|
-
return result;
|
|
2461
|
-
}
|
|
2462
|
-
findById(definition, stepId) {
|
|
2463
|
-
const result = this.findParentSequence(definition, stepId);
|
|
2464
|
-
return result ? result.step : null;
|
|
2465
|
-
}
|
|
2466
|
-
getById(definition, stepId) {
|
|
2467
|
-
return this.getParentSequence(definition, stepId).step;
|
|
2468
|
-
}
|
|
2469
|
-
forEach(definition, callback) {
|
|
2470
|
-
this.iterateSequence(definition.sequence, callback);
|
|
2471
|
-
}
|
|
2472
|
-
forEachSequence(sequence, callback) {
|
|
2473
|
-
this.iterateSequence(sequence, callback);
|
|
2474
|
-
}
|
|
2475
|
-
forEachChildren(step, callback) {
|
|
2476
|
-
this.iterateStep(step, callback);
|
|
2477
|
-
}
|
|
2478
|
-
find(sequence, needSequence, needStepId, result) {
|
|
2479
|
-
if (needSequence && sequence === needSequence) {
|
|
2480
|
-
return true;
|
|
2481
|
-
}
|
|
2482
|
-
const count = sequence.length;
|
|
2483
|
-
for (let index = 0; index < count; index++) {
|
|
2484
|
-
const step = sequence[index];
|
|
2485
|
-
if (needStepId && step.id === needStepId) {
|
|
2486
|
-
result.push({ step, index, parentSequence: sequence });
|
|
2487
|
-
return true;
|
|
2488
|
-
}
|
|
2489
|
-
const children = this.getChildren(step);
|
|
2490
|
-
if (children) {
|
|
2491
|
-
switch (children.type) {
|
|
2492
|
-
case exports.StepChildrenType.sequence:
|
|
2493
|
-
{
|
|
2494
|
-
const parentSequence = children.items;
|
|
2495
|
-
if (this.find(parentSequence, needSequence, needStepId, result)) {
|
|
2496
|
-
result.push({ step, index, parentSequence });
|
|
2497
|
-
return true;
|
|
2498
|
-
}
|
|
2499
|
-
}
|
|
2500
|
-
break;
|
|
2501
|
-
case exports.StepChildrenType.branches:
|
|
2502
|
-
{
|
|
2503
|
-
const branches = children.items;
|
|
2504
|
-
const branchNames = Object.keys(branches);
|
|
2505
|
-
for (const branchName of branchNames) {
|
|
2506
|
-
const parentSequence = branches[branchName];
|
|
2507
|
-
if (this.find(parentSequence, needSequence, needStepId, result)) {
|
|
2508
|
-
result.push(branchName);
|
|
2509
|
-
result.push({ step, index, parentSequence });
|
|
2510
|
-
return true;
|
|
2511
|
-
}
|
|
2512
|
-
}
|
|
2513
|
-
}
|
|
2514
|
-
break;
|
|
2515
|
-
default:
|
|
2516
|
-
throw new Error(`Not supported step children type: ${children.type}`);
|
|
2517
|
-
}
|
|
2518
|
-
}
|
|
2519
|
-
}
|
|
2520
|
-
return false;
|
|
2521
|
-
}
|
|
2522
|
-
iterateSequence(sequence, callback) {
|
|
2523
|
-
const count = sequence.length;
|
|
2524
|
-
for (let index = 0; index < count; index++) {
|
|
2525
|
-
const step = sequence[index];
|
|
2526
|
-
if (callback(step, index, sequence) === false) {
|
|
2527
|
-
return false;
|
|
2528
|
-
}
|
|
2529
|
-
if (!this.iterateStep(step, callback)) {
|
|
2530
|
-
return false;
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
return true;
|
|
2534
|
-
}
|
|
2535
|
-
iterateStep(step, callback) {
|
|
2536
|
-
const children = this.getChildren(step);
|
|
2537
|
-
if (children) {
|
|
2538
|
-
switch (children.type) {
|
|
2539
|
-
case exports.StepChildrenType.sequence:
|
|
2540
|
-
{
|
|
2541
|
-
const sequence = children.items;
|
|
2542
|
-
if (!this.iterateSequence(sequence, callback)) {
|
|
2543
|
-
return false;
|
|
2544
|
-
}
|
|
2545
|
-
}
|
|
2546
|
-
break;
|
|
2547
|
-
case exports.StepChildrenType.branches:
|
|
2548
|
-
{
|
|
2549
|
-
const sequences = Object.values(children.items);
|
|
2550
|
-
for (const sequence of sequences) {
|
|
2551
|
-
if (!this.iterateSequence(sequence, callback)) {
|
|
2552
|
-
return false;
|
|
2553
|
-
}
|
|
2554
|
-
}
|
|
2555
|
-
}
|
|
2556
|
-
break;
|
|
2557
|
-
default:
|
|
2558
|
-
throw new Error(`Not supported step children type: ${children.type}`);
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
return true;
|
|
2562
|
-
}
|
|
2563
|
-
}
|
|
2564
|
-
|
|
2565
2601
|
function readMousePosition(e) {
|
|
2566
2602
|
return new Vector(e.pageX, e.pageY);
|
|
2567
2603
|
}
|
|
@@ -3180,6 +3216,8 @@
|
|
|
3180
3216
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
3181
3217
|
PERFORMANCE OF THIS SOFTWARE.
|
|
3182
3218
|
***************************************************************************** */
|
|
3219
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
3220
|
+
|
|
3183
3221
|
|
|
3184
3222
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
3185
3223
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -3189,7 +3227,12 @@
|
|
|
3189
3227
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
3190
3228
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
3191
3229
|
});
|
|
3192
|
-
}
|
|
3230
|
+
}
|
|
3231
|
+
|
|
3232
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
3233
|
+
var e = new Error(message);
|
|
3234
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
3235
|
+
};
|
|
3193
3236
|
|
|
3194
3237
|
function isElementAttached(dom, element) {
|
|
3195
3238
|
return !(dom.compareDocumentPosition(element) & Node.DOCUMENT_POSITION_DISCONNECTED);
|
|
@@ -3240,11 +3283,11 @@
|
|
|
3240
3283
|
this.context = context;
|
|
3241
3284
|
this.onResizeHandler = () => this.onResize();
|
|
3242
3285
|
}
|
|
3243
|
-
render(sequence,
|
|
3286
|
+
render(sequence, parentPlaceIndicator) {
|
|
3244
3287
|
if (this.rootComponent) {
|
|
3245
3288
|
this.foreground.removeChild(this.rootComponent.view.g);
|
|
3246
3289
|
}
|
|
3247
|
-
this.rootComponent = this.context.services.rootComponent.create(this.foreground, sequence,
|
|
3290
|
+
this.rootComponent = this.context.services.rootComponent.create(this.foreground, sequence, parentPlaceIndicator, this.context);
|
|
3248
3291
|
this.refreshSize();
|
|
3249
3292
|
}
|
|
3250
3293
|
setPositionAndScale(position, scale) {
|
|
@@ -3404,10 +3447,14 @@
|
|
|
3404
3447
|
}
|
|
3405
3448
|
|
|
3406
3449
|
class RerenderStepPressingBehaviorHandler {
|
|
3407
|
-
constructor(designerContext) {
|
|
3450
|
+
constructor(command, designerContext) {
|
|
3451
|
+
this.command = command;
|
|
3408
3452
|
this.designerContext = designerContext;
|
|
3409
3453
|
}
|
|
3410
3454
|
handle() {
|
|
3455
|
+
if (this.command.beforeCallback) {
|
|
3456
|
+
this.command.beforeCallback();
|
|
3457
|
+
}
|
|
3411
3458
|
this.designerContext.workspaceController.updateRootComponent();
|
|
3412
3459
|
}
|
|
3413
3460
|
}
|
|
@@ -3445,7 +3492,7 @@
|
|
|
3445
3492
|
case exports.ClickCommandType.selectStep:
|
|
3446
3493
|
return SelectStepBehavior.create(commandOrNull.component, forceMove, this.context);
|
|
3447
3494
|
case exports.ClickCommandType.rerenderStep:
|
|
3448
|
-
return PressingBehavior.create(element, new RerenderStepPressingBehaviorHandler(this.context));
|
|
3495
|
+
return PressingBehavior.create(element, new RerenderStepPressingBehaviorHandler(commandOrNull, this.context));
|
|
3449
3496
|
case exports.ClickCommandType.openFolder:
|
|
3450
3497
|
return PressingBehavior.create(element, new OpenFolderPressingBehaviorHandler(commandOrNull, this.context));
|
|
3451
3498
|
case exports.ClickCommandType.triggerCustomAction:
|
|
@@ -3581,8 +3628,9 @@
|
|
|
3581
3628
|
}
|
|
3582
3629
|
|
|
3583
3630
|
class ContextMenuItemsBuilder {
|
|
3584
|
-
constructor(viewportApi, i18n, stateModifier, state, customMenuItemsProvider) {
|
|
3631
|
+
constructor(viewportApi, workspaceApi, i18n, stateModifier, state, customMenuItemsProvider) {
|
|
3585
3632
|
this.viewportApi = viewportApi;
|
|
3633
|
+
this.workspaceApi = workspaceApi;
|
|
3586
3634
|
this.i18n = i18n;
|
|
3587
3635
|
this.stateModifier = stateModifier;
|
|
3588
3636
|
this.state = state;
|
|
@@ -3641,8 +3689,9 @@
|
|
|
3641
3689
|
}
|
|
3642
3690
|
}
|
|
3643
3691
|
}
|
|
3644
|
-
else {
|
|
3645
|
-
|
|
3692
|
+
else if (!commandOrNull) {
|
|
3693
|
+
const rootSequence = this.workspaceApi.getRootSequence();
|
|
3694
|
+
this.tryAppendCustomItems(items, null, rootSequence.sequence);
|
|
3646
3695
|
}
|
|
3647
3696
|
items.push({
|
|
3648
3697
|
label: this.i18n('contextMenu.resetView', 'Reset view'),
|
|
@@ -3656,7 +3705,7 @@
|
|
|
3656
3705
|
}
|
|
3657
3706
|
tryAppendCustomItems(items, step, parentSequence) {
|
|
3658
3707
|
if (this.customMenuItemsProvider) {
|
|
3659
|
-
const customItems = this.customMenuItemsProvider.getItems(step, parentSequence);
|
|
3708
|
+
const customItems = this.customMenuItemsProvider.getItems(step, parentSequence, this.state.definition);
|
|
3660
3709
|
for (const customItem of customItems) {
|
|
3661
3710
|
items.push(customItem);
|
|
3662
3711
|
}
|
|
@@ -3747,15 +3796,11 @@
|
|
|
3747
3796
|
const clickBehaviorWrapper = designerContext.services.clickBehaviorWrapperExtension.create(designerContext.customActionController);
|
|
3748
3797
|
const wheelController = designerContext.services.wheelController.create(api.viewport, api.workspace);
|
|
3749
3798
|
const pinchToZoomController = PinchToZoomController.create(api.workspace, api.viewport, api.shadowRoot);
|
|
3750
|
-
const contextMenuItemsBuilder = new ContextMenuItemsBuilder(api.viewport, api.i18n, designerContext.stateModifier, designerContext.state, ((_a = designerContext.services.contextMenu) === null || _a === void 0 ? void 0 : _a.createItemsProvider)
|
|
3799
|
+
const contextMenuItemsBuilder = new ContextMenuItemsBuilder(api.viewport, api.workspace, api.i18n, designerContext.stateModifier, designerContext.state, ((_a = designerContext.services.contextMenu) === null || _a === void 0 ? void 0 : _a.createItemsProvider)
|
|
3751
3800
|
? designerContext.services.contextMenu.createItemsProvider(designerContext.customActionController)
|
|
3752
3801
|
: undefined);
|
|
3753
3802
|
const contextMenuController = new ContextMenuController(designerContext.theme, designerContext.configuration, contextMenuItemsBuilder);
|
|
3754
|
-
const workspace = new Workspace(view, designerContext.
|
|
3755
|
-
setTimeout(() => {
|
|
3756
|
-
workspace.updateRootComponent();
|
|
3757
|
-
api.viewport.resetViewport();
|
|
3758
|
-
});
|
|
3803
|
+
const workspace = new Workspace(view, designerContext.state, designerContext.behaviorController, wheelController, pinchToZoomController, contextMenuController, clickBehaviorResolver, clickBehaviorWrapper, api.viewport, api.workspace, designerContext.services);
|
|
3759
3804
|
designerContext.setWorkspaceController(workspace);
|
|
3760
3805
|
designerContext.state.onViewportChanged.subscribe(workspace.onViewportChanged);
|
|
3761
3806
|
race(0, designerContext.state.onDefinitionChanged, designerContext.state.onSelectedStepIdChanged, designerContext.state.onFolderPathChanged).subscribe(r => {
|
|
@@ -3765,11 +3810,11 @@
|
|
|
3765
3810
|
view.bindTouchStart(workspace.onClick, workspace.onPinchToZoom);
|
|
3766
3811
|
view.bindWheel(workspace.onWheel);
|
|
3767
3812
|
view.bindContextMenu(workspace.onContextMenu);
|
|
3813
|
+
workspace.scheduleInit();
|
|
3768
3814
|
return workspace;
|
|
3769
3815
|
}
|
|
3770
|
-
constructor(view,
|
|
3816
|
+
constructor(view, state, behaviorController, wheelController, pinchToZoomController, contextMenuController, clickBehaviorResolver, clickBehaviorWrapper, viewportApi, workspaceApi, services) {
|
|
3771
3817
|
this.view = view;
|
|
3772
|
-
this.definitionWalker = definitionWalker;
|
|
3773
3818
|
this.state = state;
|
|
3774
3819
|
this.behaviorController = behaviorController;
|
|
3775
3820
|
this.wheelController = wheelController;
|
|
@@ -3778,9 +3823,11 @@
|
|
|
3778
3823
|
this.clickBehaviorResolver = clickBehaviorResolver;
|
|
3779
3824
|
this.clickBehaviorWrapper = clickBehaviorWrapper;
|
|
3780
3825
|
this.viewportApi = viewportApi;
|
|
3826
|
+
this.workspaceApi = workspaceApi;
|
|
3781
3827
|
this.services = services;
|
|
3782
3828
|
this.onRendered = new SimpleEvent();
|
|
3783
3829
|
this.isValid = false;
|
|
3830
|
+
this.initTimeout = null;
|
|
3784
3831
|
this.selectedStepComponent = null;
|
|
3785
3832
|
this.validationErrorBadgeIndex = null;
|
|
3786
3833
|
this.onClick = (position, target, buttonIndex, altKey) => {
|
|
@@ -3810,28 +3857,23 @@
|
|
|
3810
3857
|
this.view.setPositionAndScale(viewport.position, viewport.scale);
|
|
3811
3858
|
};
|
|
3812
3859
|
}
|
|
3860
|
+
scheduleInit() {
|
|
3861
|
+
this.initTimeout = setTimeout(() => {
|
|
3862
|
+
this.initTimeout = null;
|
|
3863
|
+
this.updateRootComponent();
|
|
3864
|
+
this.viewportApi.resetViewport();
|
|
3865
|
+
});
|
|
3866
|
+
}
|
|
3813
3867
|
updateRootComponent() {
|
|
3814
3868
|
this.selectedStepComponent = null;
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
const children = this.definitionWalker.getChildren(parentSequence.step);
|
|
3821
|
-
if (!children || children.type !== exports.StepChildrenType.sequence) {
|
|
3822
|
-
throw new Error('Cannot find single sequence in folder step');
|
|
3869
|
+
const rootSequence = this.workspaceApi.getRootSequence();
|
|
3870
|
+
const parentPlaceIndicator = rootSequence.parentStep
|
|
3871
|
+
? {
|
|
3872
|
+
sequence: rootSequence.parentStep.parentSequence,
|
|
3873
|
+
index: rootSequence.parentStep.index
|
|
3823
3874
|
}
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
sequence: parentSequence.parentSequence,
|
|
3827
|
-
index: parentSequence.index
|
|
3828
|
-
};
|
|
3829
|
-
}
|
|
3830
|
-
else {
|
|
3831
|
-
sequence = this.state.definition.sequence;
|
|
3832
|
-
parentSequencePlaceIndicator = null;
|
|
3833
|
-
}
|
|
3834
|
-
this.view.render(sequence, parentSequencePlaceIndicator);
|
|
3875
|
+
: null;
|
|
3876
|
+
this.view.render(rootSequence.sequence, parentPlaceIndicator);
|
|
3835
3877
|
this.trySelectStepComponent(this.state.selectedStepId);
|
|
3836
3878
|
this.updateBadges();
|
|
3837
3879
|
this.onRendered.forward();
|
|
@@ -3873,6 +3915,10 @@
|
|
|
3873
3915
|
setTimeout(() => this.view.refreshSize());
|
|
3874
3916
|
}
|
|
3875
3917
|
destroy() {
|
|
3918
|
+
if (this.initTimeout) {
|
|
3919
|
+
clearTimeout(this.initTimeout);
|
|
3920
|
+
this.initTimeout = null;
|
|
3921
|
+
}
|
|
3876
3922
|
this.contextMenuController.destroy();
|
|
3877
3923
|
this.view.destroy();
|
|
3878
3924
|
}
|
|
@@ -3970,8 +4016,8 @@
|
|
|
3970
4016
|
class DefaultDraggedComponent {
|
|
3971
4017
|
static create(parent, step, componentContext) {
|
|
3972
4018
|
const canvas = Dom.svg('svg');
|
|
3973
|
-
canvas.style.marginLeft = -
|
|
3974
|
-
canvas.style.marginTop = -
|
|
4019
|
+
canvas.style.marginLeft = -10 + 'px';
|
|
4020
|
+
canvas.style.marginTop = -10 + 'px';
|
|
3975
4021
|
parent.appendChild(canvas);
|
|
3976
4022
|
const previewStepContext = {
|
|
3977
4023
|
parentSequence: [],
|