@pie-element/multi-trait-rubric 0.1.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.
Files changed (188) hide show
  1. package/dist/author/common.d.ts +91 -0
  2. package/dist/author/common.d.ts.map +1 -0
  3. package/dist/author/common.js +275 -0
  4. package/dist/author/defaults.d.ts +154 -0
  5. package/dist/author/defaults.d.ts.map +1 -0
  6. package/dist/author/defaults.js +113 -0
  7. package/dist/author/index.d.ts +23 -0
  8. package/dist/author/index.d.ts.map +1 -0
  9. package/dist/author/index.js +89 -0
  10. package/dist/author/main.d.ts +44 -0
  11. package/dist/author/main.d.ts.map +1 -0
  12. package/dist/author/main.js +249 -0
  13. package/dist/author/modals.d.ts +95 -0
  14. package/dist/author/modals.d.ts.map +1 -0
  15. package/dist/author/modals.js +171 -0
  16. package/dist/author/scale.d.ts +47 -0
  17. package/dist/author/scale.d.ts.map +1 -0
  18. package/dist/author/scale.js +280 -0
  19. package/dist/author/trait.d.ts +71 -0
  20. package/dist/author/trait.d.ts.map +1 -0
  21. package/dist/author/trait.js +202 -0
  22. package/dist/author/traitsHeader.d.ts +29 -0
  23. package/dist/author/traitsHeader.d.ts.map +1 -0
  24. package/dist/author/traitsHeader.js +172 -0
  25. package/dist/author/utils.d.ts +11 -0
  26. package/dist/author/utils.d.ts.map +1 -0
  27. package/dist/author/utils.js +41 -0
  28. package/dist/controller/defaults.d.ts +21 -0
  29. package/dist/controller/defaults.d.ts.map +1 -0
  30. package/dist/controller/defaults.js +14 -0
  31. package/dist/controller/index.d.ts +27 -0
  32. package/dist/controller/index.d.ts.map +1 -0
  33. package/dist/controller/index.js +57 -0
  34. package/dist/controller/utils.d.ts +10 -0
  35. package/dist/controller/utils.d.ts.map +1 -0
  36. package/dist/controller/utils.js +4 -0
  37. package/dist/delivery/index.d.ts +18 -0
  38. package/dist/delivery/index.d.ts.map +1 -0
  39. package/dist/delivery/index.js +37 -0
  40. package/dist/delivery/main.d.ts +16 -0
  41. package/dist/delivery/main.d.ts.map +1 -0
  42. package/dist/delivery/main.js +95 -0
  43. package/dist/delivery/scale.d.ts +18 -0
  44. package/dist/delivery/scale.d.ts.map +1 -0
  45. package/dist/delivery/scale.js +175 -0
  46. package/dist/delivery/trait.d.ts +28 -0
  47. package/dist/delivery/trait.d.ts.map +1 -0
  48. package/dist/delivery/trait.js +44 -0
  49. package/dist/index.d.ts +2 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.iife.d.ts +9 -0
  52. package/dist/index.iife.d.ts.map +1 -0
  53. package/dist/index.iife.js +145 -0
  54. package/dist/index.js +2 -0
  55. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_DataView.js +6 -0
  56. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Hash.js +16 -0
  57. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_ListCache.js +16 -0
  58. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Map.js +6 -0
  59. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_MapCache.js +16 -0
  60. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Promise.js +6 -0
  61. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Set.js +6 -0
  62. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Stack.js +13 -0
  63. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Symbol.js +5 -0
  64. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Uint8Array.js +5 -0
  65. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_WeakMap.js +6 -0
  66. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayEach.js +7 -0
  67. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayFilter.js +10 -0
  68. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayLikeKeys.js +15 -0
  69. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayPush.js +7 -0
  70. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_assignValue.js +10 -0
  71. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_assocIndexOf.js +8 -0
  72. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseAssign.js +8 -0
  73. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseAssignIn.js +8 -0
  74. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseAssignValue.js +12 -0
  75. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseClone.js +57 -0
  76. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseCreate.js +14 -0
  77. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseGetAllKeys.js +9 -0
  78. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseGetTag.js +10 -0
  79. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsArguments.js +9 -0
  80. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsMap.js +9 -0
  81. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsNative.js +11 -0
  82. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsSet.js +9 -0
  83. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsTypedArray.js +11 -0
  84. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseKeys.js +12 -0
  85. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseKeysIn.js +13 -0
  86. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseTimes.js +7 -0
  87. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseTrim.js +8 -0
  88. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseUnary.js +8 -0
  89. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneArrayBuffer.js +8 -0
  90. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneBuffer.js +10 -0
  91. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneDataView.js +8 -0
  92. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneRegExp.js +8 -0
  93. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneSymbol.js +8 -0
  94. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneTypedArray.js +8 -0
  95. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copyArray.js +8 -0
  96. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copyObject.js +14 -0
  97. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copySymbols.js +8 -0
  98. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copySymbolsIn.js +8 -0
  99. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_coreJsData.js +5 -0
  100. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_defineProperty.js +10 -0
  101. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_freeGlobal.js +4 -0
  102. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getAllKeys.js +9 -0
  103. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getAllKeysIn.js +9 -0
  104. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getMapData.js +8 -0
  105. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getNative.js +9 -0
  106. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getPrototype.js +5 -0
  107. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getRawTag.js +14 -0
  108. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getSymbols.js +10 -0
  109. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getSymbolsIn.js +11 -0
  110. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getTag.js +23 -0
  111. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getValue.js +6 -0
  112. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashClear.js +7 -0
  113. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashDelete.js +7 -0
  114. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashGet.js +13 -0
  115. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashHas.js +9 -0
  116. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashSet.js +9 -0
  117. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_initCloneArray.js +8 -0
  118. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_initCloneByTag.js +33 -0
  119. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_initCloneObject.js +9 -0
  120. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isIndex.js +8 -0
  121. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isKeyable.js +7 -0
  122. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isMasked.js +11 -0
  123. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isPrototype.js +8 -0
  124. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheClear.js +6 -0
  125. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheDelete.js +9 -0
  126. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheGet.js +8 -0
  127. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheHas.js +7 -0
  128. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheSet.js +8 -0
  129. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheClear.js +13 -0
  130. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheDelete.js +8 -0
  131. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheGet.js +7 -0
  132. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheHas.js +7 -0
  133. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheSet.js +8 -0
  134. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nativeCreate.js +5 -0
  135. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nativeKeys.js +5 -0
  136. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nativeKeysIn.js +8 -0
  137. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nodeUtil.js +9 -0
  138. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_objectToString.js +7 -0
  139. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_overArg.js +8 -0
  140. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_root.js +5 -0
  141. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackClear.js +7 -0
  142. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackDelete.js +7 -0
  143. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackGet.js +6 -0
  144. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackHas.js +6 -0
  145. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackSet.js +16 -0
  146. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_toSource.js +15 -0
  147. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_trimmedEndIndex.js +8 -0
  148. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/cloneDeep.js +8 -0
  149. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/debounce.js +50 -0
  150. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/eq.js +6 -0
  151. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArguments.js +10 -0
  152. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArray.js +4 -0
  153. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArrayLike.js +8 -0
  154. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isBuffer.js +6 -0
  155. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isEmpty.js +21 -0
  156. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isFunction.js +11 -0
  157. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isLength.js +7 -0
  158. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isMap.js +7 -0
  159. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isObject.js +7 -0
  160. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isObjectLike.js +6 -0
  161. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isSet.js +7 -0
  162. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isSymbol.js +9 -0
  163. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isTypedArray.js +7 -0
  164. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/keys.js +9 -0
  165. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/keysIn.js +9 -0
  166. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/now.js +7 -0
  167. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/stubArray.js +6 -0
  168. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/stubFalse.js +6 -0
  169. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/toNumber.js +19 -0
  170. package/package.json +70 -0
  171. package/src/author/common.tsx +473 -0
  172. package/src/author/defaults.tsx +157 -0
  173. package/src/author/index.ts +174 -0
  174. package/src/author/main.tsx +407 -0
  175. package/src/author/modals.tsx +254 -0
  176. package/src/author/scale.tsx +453 -0
  177. package/src/author/trait.tsx +305 -0
  178. package/src/author/traitsHeader.tsx +301 -0
  179. package/src/author/utils.ts +83 -0
  180. package/src/controller/defaults.ts +21 -0
  181. package/src/controller/index.ts +137 -0
  182. package/src/controller/utils.ts +13 -0
  183. package/src/delivery/index.ts +61 -0
  184. package/src/delivery/main.tsx +140 -0
  185. package/src/delivery/scale.tsx +313 -0
  186. package/src/delivery/trait.tsx +86 -0
  187. package/src/index.iife.ts +16 -0
  188. package/src/index.ts +1 -0
@@ -0,0 +1,453 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-elements/packages/multi-trait-rubric/configure/src/scale.jsx
4
+ * @auto-generated
5
+ *
6
+ * This file is automatically synced from pie-elements and converted to TypeScript.
7
+ * Manual edits will be overwritten on next sync.
8
+ * To make changes, edit the upstream JavaScript file and run sync again.
9
+ */
10
+
11
+ import React from 'react';
12
+ import PropTypes from 'prop-types';
13
+
14
+ import { styled } from '@mui/material/styles';
15
+ import ArrowBackIosIcon from '@mui/icons-material/ArrowBackIos';
16
+ import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
17
+
18
+ import { DragProvider } from '@pie-lib/drag';
19
+
20
+ import TraitsHeader from './traitsHeader.js';
21
+ import TraitTile from './trait.js';
22
+ import { Arrow, BlockWidth, DragHandleSpace, MultiTraitButton, PrimaryBlockWidth } from './common.js';
23
+ import { DecreaseMaxPoints, DeleteScale, DeleteTrait, InfoDialog } from './modals.js';
24
+
25
+ const AdjustedBlockWidth = BlockWidth + 2 * 8; // 8 is padding
26
+
27
+ const ScaleWrapper: any = styled('div')(({ theme }) => ({
28
+ display: 'flex',
29
+ flexDirection: 'column',
30
+ wordBreak: 'break-word',
31
+ position: 'relative',
32
+ marginBottom: theme.spacing(2.5),
33
+ }));
34
+
35
+ export class Scale extends React.Component {
36
+ state = {
37
+ showDecreaseMaxPointsDialog: false,
38
+ showDeleteScaleDialog: false,
39
+ showDeleteTraitDialog: false,
40
+ currentPosition: 0,
41
+ showRight: null,
42
+ showLeft: null,
43
+ showInfoDialog: false,
44
+ infoDialogText: '',
45
+ };
46
+
47
+ set = (newState) => this.setState(newState);
48
+
49
+ componentDidMount() {
50
+ if (this.state.showRight === null && this.secondaryBlockRef) {
51
+ this.setState({ showRight: this.getMaxScroll() });
52
+ }
53
+ }
54
+
55
+ componentDidUpdate(prevProps) {
56
+ if (
57
+ prevProps.scale.maxPoints !== this.props.scale.maxPoints ||
58
+ prevProps.showDescription !== this.props.showDescription ||
59
+ prevProps.excludeZero !== this.props.excludeZero
60
+ ) {
61
+ this.setState({ showRight: this.getMaxScroll() });
62
+ }
63
+ }
64
+
65
+ UNSAFE_componentWillReceiveProps(nextProps) {
66
+ if (
67
+ nextProps.excludeZero !== this.props.excludeZero ||
68
+ nextProps.showStandards !== this.props.showStandards ||
69
+ nextProps.showDescription !== this.props.showDescription
70
+ ) {
71
+ this.setState({
72
+ currentPosition: 0,
73
+ showLeft: false,
74
+ showRight: this.getMaxScroll(),
75
+ });
76
+ }
77
+ }
78
+
79
+ // Max Points
80
+ updateMaxPointsFieldValue: any = ({ target }) => {
81
+ const { scale, scaleIndex, onScaleChanged } = this.props || {};
82
+ const { maxPoints } = scale;
83
+
84
+ const numberValue = parseInt(target.value, 10);
85
+
86
+ this.setState({
87
+ currentPosition: 0,
88
+ showLeft: false,
89
+ showRight: this.getMaxScroll(),
90
+ });
91
+
92
+ if (numberValue < maxPoints) {
93
+ this.showDecreaseMaxPointsModal({ newMaxPoints: numberValue });
94
+ } else {
95
+ onScaleChanged(scaleIndex, { maxPoints: numberValue });
96
+ }
97
+ };
98
+
99
+ showDecreaseMaxPointsModal = ({ newMaxPoints }) => this.set({ showDecreaseMaxPointsDialog: true, newMaxPoints });
100
+
101
+ hideDecreaseMaxPointsModal = () => this.set({ showDecreaseMaxPointsDialog: false, newMaxPoints: undefined });
102
+
103
+ changeMaxPoints: any = () => {
104
+ const { newMaxPoints } = this.state || {};
105
+ const { scaleIndex, onScaleChanged } = this.props || {};
106
+
107
+ if (newMaxPoints) {
108
+ onScaleChanged(scaleIndex, { maxPoints: newMaxPoints });
109
+ }
110
+
111
+ this.hideDecreaseMaxPointsModal();
112
+ };
113
+
114
+ // Delete Scale
115
+ showDeleteScaleModal = () => this.set({ showDeleteScaleDialog: true });
116
+
117
+ hideDeleteScaleModal = () => this.set({ showDeleteScaleDialog: false });
118
+
119
+ deleteScale: any = () => {
120
+ const { scaleIndex, onScaleRemoved } = this.props || {};
121
+
122
+ this.hideDeleteScaleModal();
123
+
124
+ onScaleRemoved(scaleIndex);
125
+ };
126
+
127
+ // Delete Trait
128
+ showDeleteTraitModal = (traitToDeleteIndex) => this.set({ showDeleteTraitDialog: true, traitToDeleteIndex });
129
+
130
+ hideDeleteTraitModal = () => this.set({ showDeleteTraitDialog: false, traitToDeleteIndex: undefined });
131
+
132
+ onTraitRemoved: any = () => {
133
+ const { traitToDeleteIndex } = this.state;
134
+ const { scale, scaleIndex, onScaleChanged, minNoOfTraits } = this.props || {};
135
+ let { traits, traitLabel } = scale || {};
136
+
137
+ if (traitToDeleteIndex < 0 || traitToDeleteIndex >= traits.length) return;
138
+
139
+ if (traits.length === minNoOfTraits) {
140
+ this.set({
141
+ infoDialogText: `There can't be less than ${minNoOfTraits} ${(traitLabel || 'trait').toLowerCase()}s.`,
142
+ showInfoDialog: true,
143
+ });
144
+
145
+ return false;
146
+ }
147
+
148
+ traits = [...traits.slice(0, traitToDeleteIndex), ...traits.slice(traitToDeleteIndex + 1)];
149
+
150
+ onScaleChanged(scaleIndex, { traits });
151
+
152
+ this.hideDeleteTraitModal();
153
+ };
154
+
155
+ onTraitAdded: any = () => {
156
+ const { scale, scaleIndex, onScaleChanged, maxNoOfTraits } = this.props || {};
157
+ const { traits, scorePointsLabels } = scale || {};
158
+
159
+ if (traits.length === maxNoOfTraits) {
160
+ this.set({
161
+ infoDialogText: `There can't be more than ${maxNoOfTraits} scales.`,
162
+ showInfoDialog: true,
163
+ });
164
+
165
+ return false;
166
+ }
167
+
168
+ traits.push({
169
+ name: '',
170
+ description: '',
171
+ standards: [],
172
+ scorePointsDescriptors: Array.from({ length: scorePointsLabels.length }, () => ''),
173
+ });
174
+
175
+ onScaleChanged(scaleIndex, { traits });
176
+ };
177
+
178
+ onTraitChanged: any = (traitIndex, trait) => {
179
+ const { scale, scaleIndex, onScaleChanged } = this.props || {};
180
+ const { traits } = scale || {};
181
+
182
+ if (traitIndex >= 0 && traitIndex < traits.length) {
183
+ traits[traitIndex] = trait;
184
+
185
+ onScaleChanged(scaleIndex, { traits });
186
+ }
187
+ };
188
+
189
+ onTraitDropped: any = (event) => {
190
+ const { active, over } = event;
191
+
192
+ if (!over || !active) return;
193
+
194
+ const activeData = active.data.current;
195
+ const overData = over.data.current;
196
+
197
+ if (activeData?.type === 'trait' && overData?.type === 'trait') {
198
+ const oldIndex = activeData.index;
199
+ const newIndex = overData.index;
200
+
201
+ if (oldIndex === newIndex) return;
202
+
203
+ const { scale, scaleIndex, onScaleChanged } = this.props || {};
204
+ const { traits } = scale || {};
205
+
206
+ const cup = traits[oldIndex];
207
+ const remainingTraits = traits.filter((item, index) => index !== oldIndex);
208
+ const newTraits = [...remainingTraits.slice(0, newIndex), cup, ...remainingTraits.slice(newIndex)];
209
+
210
+ onScaleChanged(scaleIndex, { traits: newTraits });
211
+ }
212
+ };
213
+
214
+ decreasePosition: any = () => {
215
+ const { currentPosition } = this.state;
216
+ const decreasedPosition = Math.max(currentPosition - AdjustedBlockWidth, 0);
217
+ const maxScroll = this.getMaxScroll();
218
+
219
+ this.setState({
220
+ currentPosition: decreasedPosition,
221
+ showRight: decreasedPosition < maxScroll,
222
+ showLeft: decreasedPosition > 0,
223
+ });
224
+ };
225
+
226
+ getMaxScroll: any = () => {
227
+ if (!this.secondaryBlockRef) return 0;
228
+
229
+ // block count * BlockWidth
230
+ // the header may have slightly larger scrollWidth due to inner component styling (borders, padding),
231
+ // so we use the minimum to keep header and trait rows aligned.
232
+ const headerScrollWidth = this.secondaryBlockRef.scrollWidth;
233
+ const numberOfBlocks = this.getNumberOfBlocks();
234
+ const expectedContentWidth = numberOfBlocks * BlockWidth;
235
+ const scrollWidth = Math.min(headerScrollWidth, expectedContentWidth);
236
+
237
+ return Math.max(0, scrollWidth - this.secondaryBlockRef.offsetWidth);
238
+ };
239
+
240
+ getNumberOfBlocks: any = () => {
241
+ const { scale, showStandards, showDescription, excludeZero } = this.props;
242
+ const { maxPoints } = scale || {};
243
+ const scorePointCount = maxPoints - (excludeZero ? 1 : 0) + 1;
244
+
245
+ return (showStandards ? 1 : 0) + (showDescription ? 1 : 0) + scorePointCount;
246
+ };
247
+
248
+ increasePosition: any = () => {
249
+ const { currentPosition } = this.state;
250
+ const maxScroll = this.getMaxScroll();
251
+ const increasedPosition = Math.min(currentPosition + AdjustedBlockWidth, maxScroll);
252
+
253
+ this.setState({
254
+ currentPosition: increasedPosition,
255
+ showRight: increasedPosition < maxScroll,
256
+ showLeft: increasedPosition > 0,
257
+ });
258
+ };
259
+
260
+ render() {
261
+ const {
262
+ errors,
263
+ scale,
264
+ scaleIndex,
265
+ showStandards,
266
+ onScaleChanged,
267
+ excludeZero,
268
+ showDescription,
269
+ showLevelTagInput,
270
+ showScorePointLabels,
271
+ enableDragAndDrop,
272
+ spellCheck,
273
+ width,
274
+ uploadSoundSupport,
275
+ maxPointsEnabled,
276
+ mathMlOptions = {},
277
+ maxMaxPoints,
278
+ expandedPluginProps = {},
279
+ labelPluginProps = {},
280
+ imageSupport = {},
281
+ } = this.props || {};
282
+
283
+ const { maxPoints, scorePointsLabels, traitLabel, traits } = scale || {};
284
+
285
+ const {
286
+ showDecreaseMaxPointsDialog,
287
+ showDeleteScaleDialog,
288
+ showDeleteTraitDialog,
289
+ currentPosition,
290
+ showRight,
291
+ showLeft,
292
+ showInfoDialog,
293
+ infoDialogText,
294
+ } = this.state;
295
+
296
+ const { traitsErrors, scorePointsErrors } = errors || {};
297
+ const currentScaleTraitsErrors = (traitsErrors && traitsErrors[scaleIndex]) || {};
298
+ const currentScalePointsLabelsErrors = (scorePointsErrors && scorePointsErrors[scaleIndex]) || {};
299
+
300
+ const scorePointsValues = [];
301
+ const secondaryBlockWidth = parseInt(width) - DragHandleSpace - PrimaryBlockWidth || 320; // 320 is minWidth
302
+
303
+ // determining the score points values
304
+ for (let pointValue = maxPoints; pointValue >= excludeZero ? 1 : 0; pointValue -= 1) {
305
+ scorePointsValues.push(pointValue);
306
+ }
307
+
308
+ return (
309
+ <DragProvider onDragEnd={this.onTraitDropped}>
310
+ <ScaleWrapper
311
+ key={`scale-${scaleIndex}`}
312
+ ref={(ref) => {
313
+ this.scaleWrapper = ref;
314
+ }}
315
+ >
316
+ <TraitsHeader
317
+ setSecondaryBlockRef={(ref) => {
318
+ if (ref) {
319
+ this.secondaryBlockRef = ref;
320
+ }
321
+ }}
322
+ key={'header-key'}
323
+ errors={currentScalePointsLabelsErrors}
324
+ traitLabel={traitLabel}
325
+ scorePointsValues={scorePointsValues}
326
+ scorePointsLabels={scorePointsLabels}
327
+ onScaleChange={(params) => onScaleChanged(scaleIndex, params)}
328
+ onTraitLabelChange={(label) => onScaleChanged(scaleIndex, { traitLabel: label })}
329
+ showStandards={showStandards}
330
+ showDescription={showDescription}
331
+ showLevelTagInput={showLevelTagInput}
332
+ showScorePointLabels={showScorePointLabels}
333
+ maxPoints={maxPoints}
334
+ updateMaxPointsFieldValue={this.updateMaxPointsFieldValue}
335
+ scaleIndex={scaleIndex}
336
+ showDeleteScaleModal={this.showDeleteScaleModal}
337
+ currentPosition={currentPosition}
338
+ secondaryBlockWidth={secondaryBlockWidth}
339
+ spellCheck={spellCheck}
340
+ uploadSoundSupport={uploadSoundSupport}
341
+ maxPointsEnabled={maxPointsEnabled}
342
+ mathMlOptions={mathMlOptions}
343
+ maxMaxPoints={maxMaxPoints}
344
+ expandedPluginProps={expandedPluginProps}
345
+ labelPluginProps={labelPluginProps}
346
+ imageSupport={imageSupport}
347
+ />
348
+
349
+ {traits.map((trait, index) => (
350
+ <TraitTile
351
+ key={index}
352
+ index={index}
353
+ error={currentScaleTraitsErrors && currentScaleTraitsErrors[index]}
354
+ trait={trait}
355
+ traitLabel={traitLabel || 'Trait'}
356
+ scorePointsValues={scorePointsValues}
357
+ scorePointsLabels={scorePointsLabels}
358
+ onTraitRemoved={() => this.showDeleteTraitModal(index)}
359
+ onTraitChanged={(trait) => this.onTraitChanged(index, trait)}
360
+ showStandards={showStandards}
361
+ showDescription={showDescription}
362
+ maxPoints={maxPoints}
363
+ currentPosition={currentPosition}
364
+ enableDragAndDrop={enableDragAndDrop}
365
+ secondaryBlockWidth={secondaryBlockWidth}
366
+ spellCheck={spellCheck}
367
+ uploadSoundSupport={uploadSoundSupport}
368
+ mathMlOptions={mathMlOptions}
369
+ expandedPluginProps={expandedPluginProps}
370
+ labelPluginProps={labelPluginProps}
371
+ imageSupport={imageSupport}
372
+ />
373
+ ))}
374
+
375
+ <Arrow
376
+ width={`${AdjustedBlockWidth / 2}px`}
377
+ show={showLeft}
378
+ onClick={this.decreasePosition}
379
+ left={`${PrimaryBlockWidth}px`}
380
+ showLevelTagInput={showLevelTagInput}
381
+ >
382
+ <ArrowBackIosIcon />
383
+ </Arrow>
384
+ <Arrow
385
+ width={`${AdjustedBlockWidth / 2}px`}
386
+ show={showRight}
387
+ onClick={this.increasePosition}
388
+ showLevelTagInput={showLevelTagInput}
389
+ >
390
+ <ArrowForwardIosIcon />
391
+ </Arrow>
392
+
393
+ <MultiTraitButton onClick={this.onTraitAdded}>
394
+ <div dangerouslySetInnerHTML={{ __html: `Add ${traitLabel || ' Trait'}` }} />
395
+ </MultiTraitButton>
396
+
397
+ <DecreaseMaxPoints
398
+ open={!!showDecreaseMaxPointsDialog}
399
+ deleteScorePoints={this.changeMaxPoints}
400
+ cancel={this.hideDecreaseMaxPointsModal}
401
+ />
402
+
403
+ <DeleteScale
404
+ open={!!showDeleteScaleDialog}
405
+ scaleIndex={scaleIndex}
406
+ deleteScale={this.deleteScale}
407
+ cancel={this.hideDeleteScaleModal}
408
+ />
409
+
410
+ <DeleteTrait
411
+ open={!!showDeleteTraitDialog}
412
+ deleteTrait={this.onTraitRemoved}
413
+ cancel={this.hideDeleteTraitModal}
414
+ traitLabel={traitLabel.toLowerCase()}
415
+ />
416
+ <InfoDialog open={showInfoDialog} text={infoDialogText} onClose={() => this.set({ showInfoDialog: false })} />
417
+ </ScaleWrapper>
418
+ </DragProvider>
419
+ );
420
+ }
421
+ }
422
+
423
+ Scale.propTypes = {
424
+ errors: PropTypes.object,
425
+ scale: PropTypes.shape({
426
+ maxPoints: PropTypes.number,
427
+ scorePointsLabels: PropTypes.arrayOf(PropTypes.string),
428
+ traitLabel: PropTypes.string,
429
+ traits: PropTypes.arrayOf(
430
+ PropTypes.shape({
431
+ name: PropTypes.string,
432
+ standards: PropTypes.arrayOf(PropTypes.string),
433
+ scorePointsDescriptors: PropTypes.arrayOf(PropTypes.string),
434
+ description: PropTypes.string,
435
+ }),
436
+ ),
437
+ }),
438
+ width: PropTypes.string,
439
+ excludeZero: PropTypes.bool,
440
+ scaleIndex: PropTypes.number,
441
+ onScaleChanged: PropTypes.func,
442
+ onScaleRemoved: PropTypes.func,
443
+ showStandards: PropTypes.bool,
444
+ showLevelTagInput: PropTypes.bool,
445
+ showDescription: PropTypes.bool,
446
+ uploadSoundSupport: PropTypes.object,
447
+ showScorePointLabels: PropTypes.bool,
448
+ enableDragAndDrop: PropTypes.bool,
449
+ expandedPluginProps: PropTypes.object,
450
+ labelPluginProps: PropTypes.object,
451
+ };
452
+
453
+ export default Scale;