@dcrackel/hematournamentui 1.0.712 → 1.0.714

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.
Files changed (107) hide show
  1. package/.prettierignore +7 -7
  2. package/.storybook/main.js +3 -1
  3. package/README.md +42 -0
  4. package/dist/HemaTournamentUI-lib.es.js +6856 -6243
  5. package/dist/HemaTournamentUI-lib.umd.js +27 -27
  6. package/dist/hematournamentui-tailwind.css +79 -9
  7. package/package.json +96 -96
  8. package/prettier.config.js +16 -16
  9. package/src/index.js +43 -42
  10. package/src/main.js +1 -1
  11. package/src/mocks/getDEBouts-TableOf128.js +37 -37
  12. package/src/mocks/getDEBouts-TableOf64.js +35 -35
  13. package/src/stories/Atoms/Input/BaseInput.test.js +97 -97
  14. package/src/stories/Atoms/Input/BaseInput.vue +149 -149
  15. package/src/stories/Molecules/Indicators/MissingHemaRatingsId/MissingHemaRatingsId.stories.js +23 -23
  16. package/src/stories/Molecules/Indicators/MissingHemaRatingsId/MissingHemaRatingsId.vue +35 -35
  17. package/src/stories/Molecules/Indicators/RegistrationStatus/RegistrationStatus.vue +30 -30
  18. package/src/stories/Molecules/Menus/HoverActions/HoverActions.test.js +138 -0
  19. package/src/stories/Molecules/Menus/HoverActions/HoverActions.vue +212 -0
  20. package/src/stories/Molecules/Modals/BracketDirectorsModal/BracketDirectorsModal.stories.js +49 -0
  21. package/src/stories/Molecules/Modals/BracketDirectorsModal/BracketDirectorsModal.test.js +129 -0
  22. package/src/stories/Molecules/Modals/BracketDirectorsModal/BracketDirectorsModal.vue +165 -0
  23. package/src/stories/Molecules/Modals/DirectorModal/DirectorModal.stories.js +6 -0
  24. package/src/stories/Molecules/Modals/DirectorModal/DirectorModal.test.js +18 -18
  25. package/src/stories/Molecules/Modals/DirectorModal/DirectorModal.vue +1 -1
  26. package/src/stories/Organisms/Cards/BoutCard/BoutCard.vue +5 -1
  27. package/src/stories/Organisms/Cards/BoutCard/Variants/BoutCardActive/BoutCardActive.vue +19 -10
  28. package/src/stories/Organisms/Cards/BoutCard/Variants/BoutCardInactive/BoutCardInactive.vue +11 -7
  29. package/src/stories/Organisms/Cards/BracketDirectorAssignmentCard/BracketDirectorAssignmentCard.stories.js +42 -33
  30. package/src/stories/Organisms/Cards/BracketDirectorAssignmentCard/BracketDirectorAssignmentCard.test.js +76 -45
  31. package/src/stories/Organisms/Cards/BracketDirectorAssignmentCard/BracketDirectorAssignmentCard.vue +122 -103
  32. package/src/stories/Organisms/Cards/Director/DirectorCard.test.js +82 -0
  33. package/src/stories/Organisms/Cards/Director/DirectorCard.vue +32 -51
  34. package/src/stories/Organisms/Cards/EditBout/EditBout.test.js +51 -51
  35. package/src/stories/Organisms/Cards/EventCard/EventCard.test.js +106 -106
  36. package/src/stories/Organisms/Cards/FencerCard/FencerCard.vue +298 -298
  37. package/src/stories/Organisms/Cards/TableauBoutCard/TableauBoutCard.stories.js +77 -60
  38. package/src/stories/Organisms/Cards/TableauBoutCard/TableauBoutCard.test.js +144 -143
  39. package/src/stories/Organisms/Cards/TableauBoutCard/TableauBoutCard.vue +289 -256
  40. package/src/stories/Organisms/Cards/TableauFencerCard/TableauFencerCard.stories.js +69 -69
  41. package/src/stories/Organisms/Cards/TableauFencerCard/TableauFencerCard.vue +80 -80
  42. package/src/stories/Organisms/Cards/WaitlistFencerCard/WaitlistFencerCard.vue +153 -153
  43. package/src/stories/Organisms/ComplexInputs/DropDown/DropDownMenu.vue +4 -0
  44. package/src/stories/Organisms/ComplexInputs/ImageCropper/ImageCropper.stories.js +31 -31
  45. package/src/stories/Organisms/ComplexInputs/ImageCropper/ImageCropper.test.js +109 -109
  46. package/src/stories/Organisms/ComplexInputs/ImageCropper/ImageCropper.vue +192 -192
  47. package/src/stories/Organisms/Containers/Tableau/Tableau.stories.js +1 -0
  48. package/src/stories/Organisms/Containers/Tableau/Tableau.test.js +247 -204
  49. package/src/stories/Organisms/Containers/Tableau/Tableau.vue +89 -15
  50. package/src/stories/Organisms/Containers/Tableau/components/BracketDirectorAssignmentPanel.test.js +51 -29
  51. package/src/stories/Organisms/Containers/Tableau/components/BracketDirectorAssignmentPanel.vue +63 -46
  52. package/src/stories/Organisms/Containers/Tableau/components/TableauSvgOverlay.test.js +21 -21
  53. package/src/stories/Organisms/Containers/Tableau/components/TableauSvgOverlay.vue +39 -39
  54. package/src/stories/Organisms/Containers/Tableau/layout/TableauLayoutEngine.js +145 -145
  55. package/src/stories/Organisms/Containers/Tableau/layout/TableauLayoutEngine.test.js +64 -64
  56. package/src/stories/Organisms/Containers/Tableau/plannedAssignments.js +36 -57
  57. package/src/stories/Organisms/Containers/Tableau/plannedAssignments.test.js +101 -65
  58. package/src/stories/Organisms/Containers/TableauColumn/TableauColumn.vue +14 -1
  59. package/src/stories/Organisms/Wizards/EditEventWizard/BasicEventInfo/BasicEventInfo.stories.js +52 -52
  60. package/src/stories/Organisms/Wizards/EditEventWizard/BasicEventInfo/BasicEventInfo.vue +10 -3
  61. package/src/stories/Organisms/Wizards/EditEventWizard/DirectElimination/DirectElimination.vue +226 -226
  62. package/src/stories/Organisms/Wizards/EditEventWizard/DirectEliminationPromotion/DirectEliminationPromotion.vue +204 -204
  63. package/src/stories/Organisms/Wizards/EditEventWizard/EditEventWizard.stories.js +137 -137
  64. package/src/stories/Organisms/Wizards/EditEventWizard/EventCustomization/EventCustomization.vue +172 -172
  65. package/src/stories/Organisms/Wizards/EditEventWizard/PoolConfiguration/PoolConfiguration.vue +216 -216
  66. package/src/stories/Organisms/Wizards/EditEventWizard/PriceFields.test.js +79 -79
  67. package/src/stories/Organisms/Wizards/EditEventWizard/RuleSerialization.test.js +29 -29
  68. package/src/stories/Organisms/Wizards/EditEventWizard/WeaponSelection.test.js +138 -0
  69. package/src/stories/Templates/EventManagement/Bracket/Bracket.stories.js +149 -9
  70. package/src/stories/Templates/EventManagement/Bracket/Bracket.test.js +54 -2
  71. package/src/stories/Templates/EventManagement/Bracket/Bracket.vue +77 -8
  72. package/src/stories/Templates/EventManagement/Bracket/BracketDirectorAssignment.test.js +242 -0
  73. package/src/stories/Templates/EventManagement/Bracket/BracketMobile.test.js +131 -0
  74. package/src/stories/Templates/EventManagement/Bracket/BracketPlannedSuggestions.js +50 -39
  75. package/src/stories/Templates/EventManagement/Bracket/BracketStories.test.js +201 -0
  76. package/src/stories/Templates/EventManagement/Bracket/BracketStoryAssignments.js +93 -0
  77. package/src/stories/Templates/EventManagement/Bracket/BracketStoryAssignments.test.js +152 -0
  78. package/src/stories/Templates/EventManagement/Bracket/BracketStoryHarness.js +39 -39
  79. package/src/stories/Templates/EventManagement/Bracket/BracketStoryHarness.test.js +79 -79
  80. package/src/stories/Templates/EventManagement/EditEventInfo/EditEventInfo.stories.js +93 -93
  81. package/src/stories/Templates/EventManagement/EditEventInfo/EditEventInfo.vue +91 -91
  82. package/src/stories/Templates/EventManagement/PoolLive/PoolLive.test.js +121 -121
  83. package/src/stories/Templates/Menus/EditEventsTopMenu/EditEventsTopMenu.stories.js +9 -2
  84. package/src/stories/Templates/Menus/EditEventsTopMenu/EditEventsTopMenu.vue +5 -4
  85. package/src/stories/Templates/PersonManagement/Admin/Administration/Administration.stories.js +81 -81
  86. package/src/stories/Templates/PersonManagement/Admin/Administration/Administration.test.js +39 -39
  87. package/src/stories/Templates/PersonManagement/Admin/Administration/Administration.vue +101 -101
  88. package/src/stories/Templates/PersonManagement/Admin/FencerAdmin/FencerAdmin.stories.js +71 -71
  89. package/src/stories/Templates/PersonManagement/Admin/FencerAdmin/FencerAdmin.vue +86 -86
  90. package/src/stories/Templates/PersonManagement/Admin/MergeAccounts/MergeAccounts.stories.js +86 -86
  91. package/src/stories/Templates/PersonManagement/Admin/MergeAccounts/MergeAccounts.vue +247 -247
  92. package/src/stories/Templates/PersonManagement/Basic/BasicEdit.vue +170 -170
  93. package/src/stories/Templates/PersonManagement/PersonManagement.stories.js +156 -156
  94. package/src/stories/Templates/PersonManagement/PersonManagement.test.js +329 -329
  95. package/src/stories/Templates/PersonManagement/PersonManagement.vue +329 -329
  96. package/src/stories/Templates/PersonManagement/PersonManagementDraft.js +42 -42
  97. package/src/stories/Templates/TournamentManagement/TournamentManagement.stories.js +84 -84
  98. package/src/stories/Templates/TournamentManagement/TournamentManagement.test.js +114 -114
  99. package/src/stories/Templates/TournamentManagement/TournamentManagement.vue +363 -363
  100. package/src/stories/Templates/TournamentManagement/TournamentPageOne/TournamentPageOne.stories.js +116 -116
  101. package/src/stories/Templates/TournamentManagement/TournamentPageOne/TournamentPageOne.vue +307 -307
  102. package/src/stories/Util/Validations/PersonManagementValidations.js +45 -45
  103. package/src/stories/Util/Validations/PriceValidation.js +6 -6
  104. package/src/stories/Util/boutDirectorAssignment.js +46 -0
  105. package/src/stories/Util/bracketDirectors.js +86 -0
  106. package/src/stories/Util/registrationStatus.js +11 -11
  107. package/src/stories/Util/tabs.js +19 -47
@@ -1,145 +1,145 @@
1
- const toNodeKey = value => String(value);
2
-
3
- const snapToPixel = value => Math.round(value) + 0.5;
4
-
5
- const getPointRelativeToRoot = (rootElement, element) => {
6
- const rootBounds = rootElement.getBoundingClientRect();
7
- const elementBounds = element.getBoundingClientRect();
8
-
9
- return {
10
- x: snapToPixel(elementBounds.left - rootBounds.left + elementBounds.width / 2),
11
- y: snapToPixel(elementBounds.top - rootBounds.top + elementBounds.height / 2)
12
- };
13
- };
14
-
15
- export const createDomAnchorLayout = ({ rootElement, getInputAnchor, getOutputAnchor }) => ({
16
- size: {
17
- width: Math.ceil(rootElement.scrollWidth),
18
- height: Math.ceil(rootElement.scrollHeight)
19
- },
20
- getInputPoint: nodeId => {
21
- const element = getInputAnchor(toNodeKey(nodeId));
22
- return element ? getPointRelativeToRoot(rootElement, element) : null;
23
- },
24
- getOutputPoint: nodeId => {
25
- const element = getOutputAnchor(toNodeKey(nodeId));
26
- return element ? getPointRelativeToRoot(rootElement, element) : null;
27
- }
28
- });
29
-
30
- const groupChildrenByParent = bouts => {
31
- const childrenByParent = new Map();
32
-
33
- bouts.forEach(bout => {
34
- if (!bout?.DEBoutId || !bout?.DENextBoutId) return;
35
- const parentId = toNodeKey(bout.DENextBoutId);
36
- const childIds = childrenByParent.get(parentId) || [];
37
- childrenByParent.set(parentId, [...childIds, toNodeKey(bout.DEBoutId)]);
38
- });
39
-
40
- return childrenByParent;
41
- };
42
-
43
- const clamp = (value, minimum, maximum) => Math.max(minimum, Math.min(maximum, value));
44
-
45
- const getTrunkX = (childPoints, parentPoint) => {
46
- const averageChildX = childPoints.reduce((total, point) => total + point.x, 0) / childPoints.length;
47
- const childrenAreRightOfParent = averageChildX > parentPoint.x;
48
- const minimumChildX = Math.min(...childPoints.map(point => point.x));
49
- const maximumChildX = Math.max(...childPoints.map(point => point.x));
50
-
51
- if (childrenAreRightOfParent) {
52
- return clamp(parentPoint.x + 120, parentPoint.x + 6, minimumChildX - 16);
53
- }
54
-
55
- return clamp(parentPoint.x - 120, maximumChildX + 16, parentPoint.x - 6);
56
- };
57
-
58
- const createSingleChildPath = ({ childId, childPoint, parentId, parentPoint }) => {
59
- const trunkX = getTrunkX([childPoint], parentPoint);
60
- return {
61
- key: `${childId}->${parentId}`,
62
- path: `M ${childPoint.x} ${childPoint.y} L ${trunkX} ${childPoint.y} L ${trunkX} ${parentPoint.y} L ${parentPoint.x} ${parentPoint.y}`,
63
- segmentRole: 'single',
64
- sourceBoutId: childId,
65
- sourceBoutIds: [childId],
66
- targetBoutId: parentId
67
- };
68
- };
69
-
70
- const createPairedChildPaths = ({ childIds, childPoints, parentId, parentPoint }) => {
71
- const trunkX = getTrunkX(childPoints, parentPoint);
72
- const [firstPoint, secondPoint] = childPoints;
73
- const top = firstPoint.y <= secondPoint.y ? firstPoint : secondPoint;
74
- const bottom = firstPoint.y <= secondPoint.y ? secondPoint : firstPoint;
75
- const middleY = (top.y + bottom.y) / 2;
76
-
77
- return [
78
- {
79
- key: `${childIds[0]}->join(${parentId})`,
80
- path: `M ${firstPoint.x} ${firstPoint.y} L ${trunkX} ${firstPoint.y}`,
81
- segmentRole: 'child',
82
- sourceBoutId: childIds[0],
83
- sourceBoutIds: [childIds[0]],
84
- targetBoutId: parentId
85
- },
86
- {
87
- key: `${childIds[1]}->join(${parentId})`,
88
- path: `M ${secondPoint.x} ${secondPoint.y} L ${trunkX} ${secondPoint.y}`,
89
- segmentRole: 'child',
90
- sourceBoutId: childIds[1],
91
- sourceBoutIds: [childIds[1]],
92
- targetBoutId: parentId
93
- },
94
- {
95
- key: `trunk(${parentId})`,
96
- path: `M ${trunkX} ${top.y} L ${trunkX} ${bottom.y}`,
97
- segmentRole: 'merge',
98
- sourceBoutIds: [...childIds],
99
- targetBoutId: parentId
100
- },
101
- {
102
- key: `join(${parentId})->parent`,
103
- path: `M ${trunkX} ${middleY} L ${parentPoint.x} ${middleY} L ${parentPoint.x} ${parentPoint.y}`,
104
- segmentRole: 'parent',
105
- sourceBoutIds: [...childIds],
106
- targetBoutId: parentId
107
- }
108
- ];
109
- };
110
-
111
- export const buildBracketPaths = ({ bouts, getInputPoint, getOutputPoint }) => {
112
- const paths = [];
113
-
114
- groupChildrenByParent(bouts).forEach((childIds, parentId) => {
115
- const parentPoint = getInputPoint(parentId);
116
- const children = childIds
117
- .map(childId => ({ id: childId, point: getOutputPoint(childId) }))
118
- .filter(child => child.point);
119
- if (!parentPoint || children.length === 0) return;
120
-
121
- if (children.length === 1) {
122
- paths.push(
123
- createSingleChildPath({
124
- childId: children[0].id,
125
- childPoint: children[0].point,
126
- parentId,
127
- parentPoint
128
- })
129
- );
130
- return;
131
- }
132
-
133
- const pairedChildren = children.slice(0, 2);
134
- paths.push(
135
- ...createPairedChildPaths({
136
- childIds: pairedChildren.map(child => child.id),
137
- childPoints: pairedChildren.map(child => child.point),
138
- parentId,
139
- parentPoint
140
- })
141
- );
142
- });
143
-
144
- return paths;
145
- };
1
+ const toNodeKey = value => String(value);
2
+
3
+ const snapToPixel = value => Math.round(value) + 0.5;
4
+
5
+ const getPointRelativeToRoot = (rootElement, element) => {
6
+ const rootBounds = rootElement.getBoundingClientRect();
7
+ const elementBounds = element.getBoundingClientRect();
8
+
9
+ return {
10
+ x: snapToPixel(elementBounds.left - rootBounds.left + elementBounds.width / 2),
11
+ y: snapToPixel(elementBounds.top - rootBounds.top + elementBounds.height / 2)
12
+ };
13
+ };
14
+
15
+ export const createDomAnchorLayout = ({ rootElement, getInputAnchor, getOutputAnchor }) => ({
16
+ size: {
17
+ width: Math.ceil(rootElement.scrollWidth),
18
+ height: Math.ceil(rootElement.scrollHeight)
19
+ },
20
+ getInputPoint: nodeId => {
21
+ const element = getInputAnchor(toNodeKey(nodeId));
22
+ return element ? getPointRelativeToRoot(rootElement, element) : null;
23
+ },
24
+ getOutputPoint: nodeId => {
25
+ const element = getOutputAnchor(toNodeKey(nodeId));
26
+ return element ? getPointRelativeToRoot(rootElement, element) : null;
27
+ }
28
+ });
29
+
30
+ const groupChildrenByParent = bouts => {
31
+ const childrenByParent = new Map();
32
+
33
+ bouts.forEach(bout => {
34
+ if (!bout?.DEBoutId || !bout?.DENextBoutId) return;
35
+ const parentId = toNodeKey(bout.DENextBoutId);
36
+ const childIds = childrenByParent.get(parentId) || [];
37
+ childrenByParent.set(parentId, [...childIds, toNodeKey(bout.DEBoutId)]);
38
+ });
39
+
40
+ return childrenByParent;
41
+ };
42
+
43
+ const clamp = (value, minimum, maximum) => Math.max(minimum, Math.min(maximum, value));
44
+
45
+ const getTrunkX = (childPoints, parentPoint) => {
46
+ const averageChildX = childPoints.reduce((total, point) => total + point.x, 0) / childPoints.length;
47
+ const childrenAreRightOfParent = averageChildX > parentPoint.x;
48
+ const minimumChildX = Math.min(...childPoints.map(point => point.x));
49
+ const maximumChildX = Math.max(...childPoints.map(point => point.x));
50
+
51
+ if (childrenAreRightOfParent) {
52
+ return clamp(parentPoint.x + 120, parentPoint.x + 6, minimumChildX - 16);
53
+ }
54
+
55
+ return clamp(parentPoint.x - 120, maximumChildX + 16, parentPoint.x - 6);
56
+ };
57
+
58
+ const createSingleChildPath = ({ childId, childPoint, parentId, parentPoint }) => {
59
+ const trunkX = getTrunkX([childPoint], parentPoint);
60
+ return {
61
+ key: `${childId}->${parentId}`,
62
+ path: `M ${childPoint.x} ${childPoint.y} L ${trunkX} ${childPoint.y} L ${trunkX} ${parentPoint.y} L ${parentPoint.x} ${parentPoint.y}`,
63
+ segmentRole: 'single',
64
+ sourceBoutId: childId,
65
+ sourceBoutIds: [childId],
66
+ targetBoutId: parentId
67
+ };
68
+ };
69
+
70
+ const createPairedChildPaths = ({ childIds, childPoints, parentId, parentPoint }) => {
71
+ const trunkX = getTrunkX(childPoints, parentPoint);
72
+ const [firstPoint, secondPoint] = childPoints;
73
+ const top = firstPoint.y <= secondPoint.y ? firstPoint : secondPoint;
74
+ const bottom = firstPoint.y <= secondPoint.y ? secondPoint : firstPoint;
75
+ const middleY = (top.y + bottom.y) / 2;
76
+
77
+ return [
78
+ {
79
+ key: `${childIds[0]}->join(${parentId})`,
80
+ path: `M ${firstPoint.x} ${firstPoint.y} L ${trunkX} ${firstPoint.y}`,
81
+ segmentRole: 'child',
82
+ sourceBoutId: childIds[0],
83
+ sourceBoutIds: [childIds[0]],
84
+ targetBoutId: parentId
85
+ },
86
+ {
87
+ key: `${childIds[1]}->join(${parentId})`,
88
+ path: `M ${secondPoint.x} ${secondPoint.y} L ${trunkX} ${secondPoint.y}`,
89
+ segmentRole: 'child',
90
+ sourceBoutId: childIds[1],
91
+ sourceBoutIds: [childIds[1]],
92
+ targetBoutId: parentId
93
+ },
94
+ {
95
+ key: `trunk(${parentId})`,
96
+ path: `M ${trunkX} ${top.y} L ${trunkX} ${bottom.y}`,
97
+ segmentRole: 'merge',
98
+ sourceBoutIds: [...childIds],
99
+ targetBoutId: parentId
100
+ },
101
+ {
102
+ key: `join(${parentId})->parent`,
103
+ path: `M ${trunkX} ${middleY} L ${parentPoint.x} ${middleY} L ${parentPoint.x} ${parentPoint.y}`,
104
+ segmentRole: 'parent',
105
+ sourceBoutIds: [...childIds],
106
+ targetBoutId: parentId
107
+ }
108
+ ];
109
+ };
110
+
111
+ export const buildBracketPaths = ({ bouts, getInputPoint, getOutputPoint }) => {
112
+ const paths = [];
113
+
114
+ groupChildrenByParent(bouts).forEach((childIds, parentId) => {
115
+ const parentPoint = getInputPoint(parentId);
116
+ const children = childIds
117
+ .map(childId => ({ id: childId, point: getOutputPoint(childId) }))
118
+ .filter(child => child.point);
119
+ if (!parentPoint || children.length === 0) return;
120
+
121
+ if (children.length === 1) {
122
+ paths.push(
123
+ createSingleChildPath({
124
+ childId: children[0].id,
125
+ childPoint: children[0].point,
126
+ parentId,
127
+ parentPoint
128
+ })
129
+ );
130
+ return;
131
+ }
132
+
133
+ const pairedChildren = children.slice(0, 2);
134
+ paths.push(
135
+ ...createPairedChildPaths({
136
+ childIds: pairedChildren.map(child => child.id),
137
+ childPoints: pairedChildren.map(child => child.point),
138
+ parentId,
139
+ parentPoint
140
+ })
141
+ );
142
+ });
143
+
144
+ return paths;
145
+ };
@@ -1,64 +1,64 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { buildBracketPaths, createDomAnchorLayout } from './TableauLayoutEngine';
3
-
4
- const createElement = ({ left, top, width = 0, height = 0 }) => ({
5
- getBoundingClientRect: () => ({ left, top, width, height })
6
- });
7
-
8
- describe('createDomAnchorLayout', () => {
9
- it('measures anchors relative to the tableau root', () => {
10
- const rootElement = {
11
- ...createElement({ left: 10, top: 20 }),
12
- scrollWidth: 400,
13
- scrollHeight: 300
14
- };
15
- const inputAnchor = createElement({ left: 110, top: 70 });
16
- const layout = createDomAnchorLayout({
17
- rootElement,
18
- getInputAnchor: () => inputAnchor,
19
- getOutputAnchor: () => null
20
- });
21
-
22
- expect(layout.size).toEqual({ width: 400, height: 300 });
23
- expect(layout.getInputPoint('3')).toEqual({ x: 100.5, y: 50.5 });
24
- expect(layout.getOutputPoint('3')).toBeNull();
25
- });
26
- });
27
-
28
- describe('buildBracketPaths', () => {
29
- const bouts = [
30
- { DEBoutId: 1, DENextBoutId: 3 },
31
- { DEBoutId: 2, DENextBoutId: 3 },
32
- { DEBoutId: 3, DENextBoutId: null }
33
- ];
34
-
35
- it('joins two child bouts to their next bout', () => {
36
- const outputPoints = {
37
- 1: { x: 160, y: 30 },
38
- 2: { x: 160, y: 100 }
39
- };
40
- const paths = buildBracketPaths({
41
- bouts,
42
- getInputPoint: id => (id === '3' ? { x: 200, y: 65 } : null),
43
- getOutputPoint: id => outputPoints[id] || null
44
- });
45
-
46
- expect(paths).toHaveLength(4);
47
- expect(paths.map(path => path.key)).toEqual(['1->join(3)', '2->join(3)', 'trunk(3)', 'join(3)->parent']);
48
- expect(paths.map(path => path.segmentRole)).toEqual(['child', 'child', 'merge', 'parent']);
49
- expect(paths[0]).toMatchObject({ sourceBoutId: '1', sourceBoutIds: ['1'], targetBoutId: '3' });
50
- expect(paths[2]).toMatchObject({ sourceBoutIds: ['1', '2'], targetBoutId: '3' });
51
- });
52
-
53
- it('keeps the correct child id when only one anchor is mounted', () => {
54
- const paths = buildBracketPaths({
55
- bouts,
56
- getInputPoint: id => (id === '3' ? { x: 200, y: 65 } : null),
57
- getOutputPoint: id => (id === '2' ? { x: 160, y: 100 } : null)
58
- });
59
-
60
- expect(paths).toHaveLength(1);
61
- expect(paths[0].key).toBe('2->3');
62
- expect(paths[0]).toMatchObject({ segmentRole: 'single', sourceBoutId: '2', targetBoutId: '3' });
63
- });
64
- });
1
+ import { describe, expect, it } from 'vitest';
2
+ import { buildBracketPaths, createDomAnchorLayout } from './TableauLayoutEngine';
3
+
4
+ const createElement = ({ left, top, width = 0, height = 0 }) => ({
5
+ getBoundingClientRect: () => ({ left, top, width, height })
6
+ });
7
+
8
+ describe('createDomAnchorLayout', () => {
9
+ it('measures anchors relative to the tableau root', () => {
10
+ const rootElement = {
11
+ ...createElement({ left: 10, top: 20 }),
12
+ scrollWidth: 400,
13
+ scrollHeight: 300
14
+ };
15
+ const inputAnchor = createElement({ left: 110, top: 70 });
16
+ const layout = createDomAnchorLayout({
17
+ rootElement,
18
+ getInputAnchor: () => inputAnchor,
19
+ getOutputAnchor: () => null
20
+ });
21
+
22
+ expect(layout.size).toEqual({ width: 400, height: 300 });
23
+ expect(layout.getInputPoint('3')).toEqual({ x: 100.5, y: 50.5 });
24
+ expect(layout.getOutputPoint('3')).toBeNull();
25
+ });
26
+ });
27
+
28
+ describe('buildBracketPaths', () => {
29
+ const bouts = [
30
+ { DEBoutId: 1, DENextBoutId: 3 },
31
+ { DEBoutId: 2, DENextBoutId: 3 },
32
+ { DEBoutId: 3, DENextBoutId: null }
33
+ ];
34
+
35
+ it('joins two child bouts to their next bout', () => {
36
+ const outputPoints = {
37
+ 1: { x: 160, y: 30 },
38
+ 2: { x: 160, y: 100 }
39
+ };
40
+ const paths = buildBracketPaths({
41
+ bouts,
42
+ getInputPoint: id => (id === '3' ? { x: 200, y: 65 } : null),
43
+ getOutputPoint: id => outputPoints[id] || null
44
+ });
45
+
46
+ expect(paths).toHaveLength(4);
47
+ expect(paths.map(path => path.key)).toEqual(['1->join(3)', '2->join(3)', 'trunk(3)', 'join(3)->parent']);
48
+ expect(paths.map(path => path.segmentRole)).toEqual(['child', 'child', 'merge', 'parent']);
49
+ expect(paths[0]).toMatchObject({ sourceBoutId: '1', sourceBoutIds: ['1'], targetBoutId: '3' });
50
+ expect(paths[2]).toMatchObject({ sourceBoutIds: ['1', '2'], targetBoutId: '3' });
51
+ });
52
+
53
+ it('keeps the correct child id when only one anchor is mounted', () => {
54
+ const paths = buildBracketPaths({
55
+ bouts,
56
+ getInputPoint: id => (id === '3' ? { x: 200, y: 65 } : null),
57
+ getOutputPoint: id => (id === '2' ? { x: 160, y: 100 } : null)
58
+ });
59
+
60
+ expect(paths).toHaveLength(1);
61
+ expect(paths[0].key).toBe('2->3');
62
+ expect(paths[0]).toMatchObject({ segmentRole: 'single', sourceBoutId: '2', targetBoutId: '3' });
63
+ });
64
+ });
@@ -1,57 +1,36 @@
1
- const toKey = value => String(value ?? '');
2
-
3
- const hasIdentity = value => value !== null && value !== undefined && String(value).length > 0;
4
-
5
- export const createStationByRing = stations =>
6
- Object.fromEntries(
7
- (stations || []).filter(station => hasIdentity(station?.RingId)).map(station => [toKey(station.RingId), station])
8
- );
9
-
10
- export const createPlannedStationByBout = ({ assignments, stations }) => {
11
- const stationByRing = createStationByRing(stations);
12
-
13
- return Object.fromEntries(
14
- (assignments || [])
15
- .filter(assignment => hasIdentity(assignment?.DEBoutId))
16
- .map(assignment => [toKey(assignment.DEBoutId), stationByRing[toKey(assignment.RingId)]])
17
- .filter(([, station]) => station)
18
- );
19
- };
20
-
21
- export const getPlannedStationForBout = (plannedStationByBout, bout) =>
22
- plannedStationByBout[toKey(bout?.DEBoutId ?? bout?.BoutId)] || null;
23
-
24
- export const isBoutSuggestedForViewer = ({ bout, plannedStationByBout, viewerPersonId }) => {
25
- if (!hasIdentity(viewerPersonId)) return false;
26
- const directorId = getPlannedStationForBout(plannedStationByBout, bout)?.Director?.PersonId;
27
- return hasIdentity(directorId) && toKey(directorId) === toKey(viewerPersonId);
28
- };
29
-
30
- const getStationColor = (plannedStationByBout, boutId) => plannedStationByBout[toKey(boutId)]?.Color || null;
31
-
32
- const getSharedSourceColor = (plannedStationByBout, sourceBoutIds) => {
33
- const colors = sourceBoutIds.map(boutId => getStationColor(plannedStationByBout, boutId));
34
- if (colors.some(color => !color)) return null;
35
- return new Set(colors).size === 1 ? colors[0] : null;
36
- };
37
-
38
- const connectorStrokeRules = [
39
- {
40
- matches: connector => ['child', 'single'].includes(connector.segmentRole),
41
- resolve: (connector, stations) => getStationColor(stations, connector.sourceBoutId)
42
- },
43
- {
44
- matches: connector => connector.segmentRole === 'merge',
45
- resolve: (connector, stations) => getSharedSourceColor(stations, connector.sourceBoutIds || [])
46
- },
47
- {
48
- matches: connector => connector.segmentRole === 'parent',
49
- resolve: (connector, stations) => getStationColor(stations, connector.targetBoutId)
50
- }
51
- ];
52
-
53
- export const addPlannedStrokesToConnectors = (connectors, plannedStationByBout) =>
54
- connectors.map(connector => ({
55
- ...connector,
56
- stroke: connectorStrokeRules.find(rule => rule.matches(connector))?.resolve(connector, plannedStationByBout) || null
57
- }));
1
+ const toKey = value => String(value ?? '');
2
+
3
+ const hasIdentity = value => value !== null && value !== undefined && String(value).length > 0;
4
+
5
+ export const createStationByRing = stations =>
6
+ Object.fromEntries(
7
+ (stations || []).filter(station => hasIdentity(station?.RingId)).map(station => [toKey(station.RingId), station])
8
+ );
9
+
10
+ export const createPlannedStationByBout = ({ assignments, stations }) => {
11
+ const stationByRing = createStationByRing(stations);
12
+
13
+ return Object.fromEntries(
14
+ (assignments || [])
15
+ .filter(assignment => hasIdentity(assignment?.DEBoutId))
16
+ .map(assignment => [toKey(assignment.DEBoutId), stationByRing[toKey(assignment.RingId)]])
17
+ .filter(([, station]) => station)
18
+ );
19
+ };
20
+
21
+ export const getPlannedStationForBout = (plannedStationByBout, bout) =>
22
+ plannedStationByBout[toKey(bout?.DEBoutId ?? bout?.BoutId)] || null;
23
+
24
+ export const isBoutSuggestedForViewer = ({ bout, plannedStationByBout, viewerPersonId }) => {
25
+ if (!hasIdentity(viewerPersonId)) return false;
26
+ const directorId = getPlannedStationForBout(plannedStationByBout, bout)?.Director?.PersonId;
27
+ return hasIdentity(directorId) && toKey(directorId) === toKey(viewerPersonId);
28
+ };
29
+
30
+ const getStationColor = (plannedStationByBout, boutId) => plannedStationByBout[toKey(boutId)]?.Color || null;
31
+
32
+ export const addPlannedStrokesToConnectors = (connectors, plannedStationByBout) =>
33
+ connectors.map(connector => ({
34
+ ...connector,
35
+ stroke: getStationColor(plannedStationByBout, connector.targetBoutId)
36
+ }));