@pie-element/multi-trait-rubric 8.1.1-next.0 → 8.1.1-next.29

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 (202) hide show
  1. package/CHANGELOG.json +1 -0
  2. package/CHANGELOG.md +1580 -0
  3. package/LICENSE.md +5 -0
  4. package/README.md +55 -0
  5. package/configure/CHANGELOG.json +1 -0
  6. package/configure/CHANGELOG.md +1475 -0
  7. package/configure/lib/common.js +424 -0
  8. package/configure/lib/common.js.map +1 -0
  9. package/configure/lib/defaults.js +184 -0
  10. package/configure/lib/defaults.js.map +1 -0
  11. package/configure/lib/index.js +157 -0
  12. package/configure/lib/index.js.map +1 -0
  13. package/configure/lib/main.js +454 -0
  14. package/configure/lib/main.js.map +1 -0
  15. package/configure/lib/modals.js +206 -0
  16. package/configure/lib/modals.js.map +1 -0
  17. package/configure/lib/scale.js +478 -0
  18. package/configure/lib/scale.js.map +1 -0
  19. package/configure/lib/trait.js +275 -0
  20. package/configure/lib/trait.js.map +1 -0
  21. package/configure/lib/traitsHeader.js +235 -0
  22. package/configure/lib/traitsHeader.js.map +1 -0
  23. package/configure/lib/utils.js +87 -0
  24. package/configure/lib/utils.js.map +1 -0
  25. package/configure/package.json +24 -0
  26. package/controller/CHANGELOG.json +1 -0
  27. package/controller/CHANGELOG.md +907 -0
  28. package/controller/lib/defaults.js +18 -0
  29. package/controller/lib/defaults.js.map +1 -0
  30. package/controller/lib/index.js +158 -0
  31. package/controller/lib/index.js.map +1 -0
  32. package/controller/lib/utils.js +11 -0
  33. package/controller/lib/utils.js.map +1 -0
  34. package/controller/package.json +14 -0
  35. package/docs/config-schema.json +1628 -0
  36. package/docs/config-schema.json.md +1202 -0
  37. package/docs/demo/config.js +8 -0
  38. package/docs/demo/generate.js +117 -0
  39. package/docs/demo/index.html +1 -0
  40. package/docs/demo/session.js +6 -0
  41. package/docs/pie-schema.json +861 -0
  42. package/docs/pie-schema.json.md +614 -0
  43. package/lib/index.js +54 -0
  44. package/lib/index.js.map +1 -0
  45. package/lib/main.js +123 -0
  46. package/lib/main.js.map +1 -0
  47. package/lib/scale.js +248 -0
  48. package/lib/scale.js.map +1 -0
  49. package/lib/trait.js +83 -0
  50. package/lib/trait.js.map +1 -0
  51. package/package.json +15 -57
  52. package/dist/author/common.d.ts +0 -90
  53. package/dist/author/common.js +0 -275
  54. package/dist/author/defaults.d.ts +0 -153
  55. package/dist/author/defaults.js +0 -113
  56. package/dist/author/index.d.ts +0 -22
  57. package/dist/author/index.js +0 -89
  58. package/dist/author/main.d.ts +0 -43
  59. package/dist/author/main.js +0 -249
  60. package/dist/author/modals.d.ts +0 -94
  61. package/dist/author/modals.js +0 -171
  62. package/dist/author/scale.d.ts +0 -46
  63. package/dist/author/scale.js +0 -280
  64. package/dist/author/trait.d.ts +0 -70
  65. package/dist/author/trait.js +0 -202
  66. package/dist/author/traitsHeader.d.ts +0 -28
  67. package/dist/author/traitsHeader.js +0 -172
  68. package/dist/author/utils.d.ts +0 -10
  69. package/dist/author/utils.js +0 -41
  70. package/dist/controller/defaults.d.ts +0 -20
  71. package/dist/controller/defaults.js +0 -14
  72. package/dist/controller/index.d.ts +0 -26
  73. package/dist/controller/index.js +0 -57
  74. package/dist/controller/utils.d.ts +0 -9
  75. package/dist/controller/utils.js +0 -4
  76. package/dist/delivery/index.d.ts +0 -17
  77. package/dist/delivery/index.js +0 -37
  78. package/dist/delivery/main.d.ts +0 -15
  79. package/dist/delivery/main.js +0 -95
  80. package/dist/delivery/scale.d.ts +0 -17
  81. package/dist/delivery/scale.js +0 -175
  82. package/dist/delivery/trait.d.ts +0 -27
  83. package/dist/delivery/trait.js +0 -44
  84. package/dist/index.d.ts +0 -1
  85. package/dist/index.iife.d.ts +0 -8
  86. package/dist/index.iife.js +0 -145
  87. package/dist/index.js +0 -2
  88. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_DataView.js +0 -6
  89. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Hash.js +0 -16
  90. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_ListCache.js +0 -16
  91. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Map.js +0 -6
  92. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_MapCache.js +0 -16
  93. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Promise.js +0 -6
  94. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Set.js +0 -6
  95. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Stack.js +0 -14
  96. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Symbol.js +0 -5
  97. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Uint8Array.js +0 -5
  98. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_WeakMap.js +0 -6
  99. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayEach.js +0 -7
  100. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayFilter.js +0 -10
  101. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayLikeKeys.js +0 -15
  102. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayPush.js +0 -7
  103. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_assignValue.js +0 -10
  104. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_assocIndexOf.js +0 -8
  105. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseAssign.js +0 -8
  106. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseAssignIn.js +0 -8
  107. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseAssignValue.js +0 -12
  108. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseClone.js +0 -57
  109. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseCreate.js +0 -14
  110. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseGetAllKeys.js +0 -9
  111. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseGetTag.js +0 -10
  112. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsArguments.js +0 -9
  113. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsMap.js +0 -9
  114. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsNative.js +0 -11
  115. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsSet.js +0 -9
  116. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsTypedArray.js +0 -11
  117. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseKeys.js +0 -12
  118. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseKeysIn.js +0 -13
  119. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseTimes.js +0 -7
  120. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseTrim.js +0 -8
  121. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseUnary.js +0 -8
  122. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneArrayBuffer.js +0 -8
  123. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneBuffer.js +0 -10
  124. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneDataView.js +0 -8
  125. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneRegExp.js +0 -8
  126. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneSymbol.js +0 -8
  127. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_cloneTypedArray.js +0 -8
  128. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_copyArray.js +0 -8
  129. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_copyObject.js +0 -14
  130. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_copySymbols.js +0 -8
  131. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_copySymbolsIn.js +0 -8
  132. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_coreJsData.js +0 -5
  133. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_defineProperty.js +0 -10
  134. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_freeGlobal.js +0 -4
  135. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getAllKeys.js +0 -9
  136. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getAllKeysIn.js +0 -9
  137. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getMapData.js +0 -8
  138. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getNative.js +0 -9
  139. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getPrototype.js +0 -5
  140. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getRawTag.js +0 -14
  141. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getSymbols.js +0 -10
  142. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getSymbolsIn.js +0 -11
  143. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getTag.js +0 -23
  144. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getValue.js +0 -6
  145. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashClear.js +0 -7
  146. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashDelete.js +0 -7
  147. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashGet.js +0 -13
  148. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashHas.js +0 -9
  149. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_hashSet.js +0 -9
  150. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_initCloneArray.js +0 -8
  151. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_initCloneByTag.js +0 -33
  152. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_initCloneObject.js +0 -9
  153. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isIndex.js +0 -8
  154. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isKeyable.js +0 -7
  155. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isMasked.js +0 -11
  156. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isPrototype.js +0 -8
  157. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheClear.js +0 -6
  158. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheDelete.js +0 -9
  159. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheGet.js +0 -8
  160. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheHas.js +0 -7
  161. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_listCacheSet.js +0 -8
  162. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheClear.js +0 -13
  163. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheDelete.js +0 -8
  164. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheGet.js +0 -7
  165. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheHas.js +0 -7
  166. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_mapCacheSet.js +0 -8
  167. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nativeCreate.js +0 -5
  168. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nativeKeys.js +0 -5
  169. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nativeKeysIn.js +0 -8
  170. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nodeUtil.js +0 -9
  171. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_objectToString.js +0 -7
  172. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_overArg.js +0 -8
  173. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_root.js +0 -5
  174. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackClear.js +0 -7
  175. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackDelete.js +0 -7
  176. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackGet.js +0 -6
  177. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackHas.js +0 -6
  178. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_stackSet.js +0 -16
  179. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_toSource.js +0 -15
  180. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_trimmedEndIndex.js +0 -8
  181. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/cloneDeep.js +0 -8
  182. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/debounce.js +0 -50
  183. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/eq.js +0 -6
  184. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isArguments.js +0 -10
  185. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isArray.js +0 -4
  186. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isArrayLike.js +0 -8
  187. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isBuffer.js +0 -6
  188. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isEmpty.js +0 -21
  189. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isFunction.js +0 -11
  190. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isLength.js +0 -7
  191. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isMap.js +0 -7
  192. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isObject.js +0 -7
  193. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isObjectLike.js +0 -6
  194. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isSet.js +0 -7
  195. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isSymbol.js +0 -9
  196. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isTypedArray.js +0 -7
  197. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/keys.js +0 -9
  198. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/keysIn.js +0 -9
  199. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/now.js +0 -7
  200. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/stubArray.js +0 -6
  201. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/stubFalse.js +0 -6
  202. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/toNumber.js +0 -19
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _pieConfigureEvents = require("@pie-framework/pie-configure-events");
10
+ var _react = _interopRequireDefault(require("react"));
11
+ var _client = require("react-dom/client");
12
+ var _main = _interopRequireDefault(require("./main"));
13
+ var _defaults = _interopRequireDefault(require("./defaults"));
14
+ var _utils = require("./utils");
15
+ var _modals = require("./modals");
16
+ const modelWithDefaults = m => ({
17
+ ..._defaults.default.model,
18
+ ...m
19
+ });
20
+ const configurationWithDefaults = c => ({
21
+ ..._defaults.default.configuration,
22
+ ...c
23
+ });
24
+ class MultiTraitRubricElement extends HTMLElement {
25
+ constructor() {
26
+ super();
27
+ (0, _defineProperty2.default)(this, "updateModelAccordingToReceivedProps", m => {
28
+ const currentModel = {
29
+ ...this._model
30
+ };
31
+ if (!m) {
32
+ return currentModel;
33
+ }
34
+ const validatedModel = {
35
+ ...m
36
+ };
37
+ const {
38
+ scales,
39
+ excludeZero
40
+ } = validatedModel || {};
41
+ (scales || []).forEach(scale => {
42
+ if (!scale) {
43
+ scale = {
44
+ scorePointsLabels: [],
45
+ traits: []
46
+ };
47
+ }
48
+ const {
49
+ maxPoints
50
+ } = scale || {};
51
+ scale.scorePointsLabels = [...(scale.scorePointsLabels || [])];
52
+ scale.traits = [...(scale.traits || [])];
53
+ const howManyScorePointLabelsShouldHave = excludeZero ? maxPoints : maxPoints + 1;
54
+ const howManyScorePointLabelsItHas = scale.scorePointsLabels.length;
55
+ if (howManyScorePointLabelsItHas !== howManyScorePointLabelsShouldHave) {
56
+ if (howManyScorePointLabelsItHas < howManyScorePointLabelsShouldHave) {
57
+ for (let i = 0; i < howManyScorePointLabelsShouldHave - howManyScorePointLabelsItHas; i++) {
58
+ scale.scorePointsLabels.push('');
59
+ }
60
+ } else {
61
+ scale.scorePointsLabels = scale.scorePointsLabels.slice(0, howManyScorePointLabelsShouldHave);
62
+ }
63
+ }
64
+ (scale.traits || []).forEach(trait => {
65
+ if (!trait) {
66
+ trait = {
67
+ scorePointsDescriptors: []
68
+ };
69
+ }
70
+ trait.scorePointsDescriptors = [...(trait.scorePointsDescriptors || [])];
71
+ const howManyScorePointDescriptorsItHas = trait.scorePointsDescriptors.length;
72
+ if (howManyScorePointDescriptorsItHas !== howManyScorePointLabelsShouldHave) {
73
+ if (howManyScorePointDescriptorsItHas < howManyScorePointLabelsShouldHave) {
74
+ for (let i = 0; i < howManyScorePointLabelsShouldHave - howManyScorePointDescriptorsItHas; i++) {
75
+ trait.scorePointsDescriptors.push('');
76
+ }
77
+ } else {
78
+ trait.scorePointsDescriptors = trait.scorePointsDescriptors.slice(0, howManyScorePointLabelsShouldHave);
79
+ }
80
+ }
81
+ });
82
+ });
83
+ if (validatedModel.excludeZero) {
84
+ // check if any scale has maxPoints set to 1
85
+ const shouldAddColumn0 = validatedModel.scales.some(scale => scale.maxPoints === 1);
86
+ if (shouldAddColumn0) {
87
+ // excludeZero should be false and disabled when maxPoints is 1
88
+ validatedModel.excludeZero = false;
89
+ // add column 0 for all scales
90
+ validatedModel.scales = (0, _utils.addOrRemoveScaleColumn)(scales, _modals.excludeZeroTypes.add0);
91
+ }
92
+ }
93
+ return validatedModel;
94
+ });
95
+ (0, _defineProperty2.default)(this, "onModelChanged", m => {
96
+ this._model = this.updateModelAccordingToReceivedProps(modelWithDefaults(m));
97
+ this._render();
98
+ this.dispatchEvent(new _pieConfigureEvents.ModelUpdatedEvent(this._model, false));
99
+ });
100
+ (0, _defineProperty2.default)(this, "onConfigurationChanged", c => {
101
+ this._configuration = configurationWithDefaults(c);
102
+ this._render();
103
+ });
104
+ this._root = null;
105
+ this._model = modelWithDefaults();
106
+ this._configuration = configurationWithDefaults();
107
+ }
108
+ set model(m) {
109
+ this._model = this.updateModelAccordingToReceivedProps(modelWithDefaults(m));
110
+ this._render();
111
+ }
112
+ set configuration(c) {
113
+ this._configuration = configurationWithDefaults(c);
114
+ this._render();
115
+ }
116
+ insertSound(handler) {
117
+ this.dispatchEvent(new _pieConfigureEvents.InsertSoundEvent(handler));
118
+ }
119
+ onDeleteSound(src, done) {
120
+ this.dispatchEvent(new _pieConfigureEvents.DeleteSoundEvent(src, done));
121
+ }
122
+ insertImage(handler) {
123
+ this.dispatchEvent(new _pieConfigureEvents.InsertImageEvent(handler));
124
+ }
125
+ onDeleteImage(src, done) {
126
+ this.dispatchEvent(new _pieConfigureEvents.DeleteImageEvent(src, done));
127
+ }
128
+ _render() {
129
+ if (this._model) {
130
+ let element = /*#__PURE__*/_react.default.createElement(_main.default, {
131
+ model: this._model,
132
+ configuration: this._configuration,
133
+ onModelChanged: this.onModelChanged,
134
+ onConfigurationChanged: this.onConfigurationChanged,
135
+ uploadSoundSupport: {
136
+ add: this.insertSound.bind(this),
137
+ delete: this.onDeleteSound.bind(this)
138
+ },
139
+ imageSupport: {
140
+ add: this.insertImage.bind(this),
141
+ delete: this.onDeleteImage.bind(this)
142
+ }
143
+ });
144
+ if (!this._root) {
145
+ this._root = (0, _client.createRoot)(this);
146
+ }
147
+ this._root.render(element);
148
+ }
149
+ }
150
+ disconnectedCallback() {
151
+ if (this._root) {
152
+ this._root.unmount();
153
+ }
154
+ }
155
+ }
156
+ exports.default = MultiTraitRubricElement;
157
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_pieConfigureEvents","require","_react","_interopRequireDefault","_client","_main","_defaults","_utils","_modals","modelWithDefaults","m","defaults","model","configurationWithDefaults","c","configuration","MultiTraitRubricElement","HTMLElement","constructor","_defineProperty2","default","currentModel","_model","validatedModel","scales","excludeZero","forEach","scale","scorePointsLabels","traits","maxPoints","howManyScorePointLabelsShouldHave","howManyScorePointLabelsItHas","length","i","push","slice","trait","scorePointsDescriptors","howManyScorePointDescriptorsItHas","shouldAddColumn0","some","addOrRemoveScaleColumn","excludeZeroTypes","add0","updateModelAccordingToReceivedProps","_render","dispatchEvent","ModelUpdatedEvent","_configuration","_root","insertSound","handler","InsertSoundEvent","onDeleteSound","src","done","DeleteSoundEvent","insertImage","InsertImageEvent","onDeleteImage","DeleteImageEvent","element","React","createElement","Main","onModelChanged","onConfigurationChanged","uploadSoundSupport","add","bind","delete","imageSupport","createRoot","render","disconnectedCallback","unmount","exports"],"sources":["../src/index.js"],"sourcesContent":["import {\n ModelUpdatedEvent,\n InsertSoundEvent,\n DeleteSoundEvent,\n InsertImageEvent,\n DeleteImageEvent,\n} from '@pie-framework/pie-configure-events';\n\nimport React from 'react';\nimport { createRoot } from 'react-dom/client';\n\nimport Main from './main';\nimport defaults from './defaults';\nimport { addOrRemoveScaleColumn } from './utils';\nimport { excludeZeroTypes } from './modals';\n\nconst modelWithDefaults = (m) => ({ ...defaults.model, ...m });\nconst configurationWithDefaults = (c) => ({ ...defaults.configuration, ...c });\n\nexport default class MultiTraitRubricElement extends HTMLElement {\n constructor() {\n super();\n this._root = null;\n this._model = modelWithDefaults();\n this._configuration = configurationWithDefaults();\n }\n\n updateModelAccordingToReceivedProps = (m) => {\n const currentModel = { ...this._model };\n\n if (!m) {\n return currentModel;\n }\n\n const validatedModel = { ...m };\n const { scales, excludeZero } = validatedModel || {};\n\n (scales || []).forEach((scale) => {\n if (!scale) {\n scale = { scorePointsLabels: [], traits: [] };\n }\n\n const { maxPoints } = scale || {};\n\n scale.scorePointsLabels = [...(scale.scorePointsLabels || [])];\n scale.traits = [...(scale.traits || [])];\n\n const howManyScorePointLabelsShouldHave = excludeZero ? maxPoints : maxPoints + 1;\n const howManyScorePointLabelsItHas = scale.scorePointsLabels.length;\n\n if (howManyScorePointLabelsItHas !== howManyScorePointLabelsShouldHave) {\n if (howManyScorePointLabelsItHas < howManyScorePointLabelsShouldHave) {\n for (let i = 0; i < howManyScorePointLabelsShouldHave - howManyScorePointLabelsItHas; i++) {\n scale.scorePointsLabels.push('');\n }\n } else {\n scale.scorePointsLabels = scale.scorePointsLabels.slice(0, howManyScorePointLabelsShouldHave);\n }\n }\n\n (scale.traits || []).forEach((trait) => {\n if (!trait) {\n trait = { scorePointsDescriptors: [] };\n }\n\n trait.scorePointsDescriptors = [...(trait.scorePointsDescriptors || [])];\n\n const howManyScorePointDescriptorsItHas = trait.scorePointsDescriptors.length;\n\n if (howManyScorePointDescriptorsItHas !== howManyScorePointLabelsShouldHave) {\n if (howManyScorePointDescriptorsItHas < howManyScorePointLabelsShouldHave) {\n for (let i = 0; i < howManyScorePointLabelsShouldHave - howManyScorePointDescriptorsItHas; i++) {\n trait.scorePointsDescriptors.push('');\n }\n } else {\n trait.scorePointsDescriptors = trait.scorePointsDescriptors.slice(0, howManyScorePointLabelsShouldHave);\n }\n }\n });\n });\n\n if (validatedModel.excludeZero) {\n // check if any scale has maxPoints set to 1\n const shouldAddColumn0 = validatedModel.scales.some((scale) => scale.maxPoints === 1);\n\n if (shouldAddColumn0) {\n // excludeZero should be false and disabled when maxPoints is 1\n validatedModel.excludeZero = false;\n // add column 0 for all scales\n validatedModel.scales = addOrRemoveScaleColumn(scales, excludeZeroTypes.add0);\n }\n }\n\n return validatedModel;\n };\n\n set model(m) {\n this._model = this.updateModelAccordingToReceivedProps(modelWithDefaults(m));\n this._render();\n }\n\n set configuration(c) {\n this._configuration = configurationWithDefaults(c);\n this._render();\n }\n\n onModelChanged = (m) => {\n this._model = this.updateModelAccordingToReceivedProps(modelWithDefaults(m));\n this._render();\n this.dispatchEvent(new ModelUpdatedEvent(this._model, false));\n };\n\n onConfigurationChanged = (c) => {\n this._configuration = configurationWithDefaults(c);\n\n this._render();\n };\n\n insertSound(handler) {\n this.dispatchEvent(new InsertSoundEvent(handler));\n }\n\n onDeleteSound(src, done) {\n this.dispatchEvent(new DeleteSoundEvent(src, done));\n }\n\n insertImage(handler) {\n this.dispatchEvent(new InsertImageEvent(handler));\n }\n\n onDeleteImage(src, done) {\n this.dispatchEvent(new DeleteImageEvent(src, done));\n }\n\n _render() {\n if (this._model) {\n let element = React.createElement(Main, {\n model: this._model,\n configuration: this._configuration,\n onModelChanged: this.onModelChanged,\n onConfigurationChanged: this.onConfigurationChanged,\n uploadSoundSupport: {\n add: this.insertSound.bind(this),\n delete: this.onDeleteSound.bind(this),\n },\n imageSupport: {\n add: this.insertImage.bind(this),\n delete: this.onDeleteImage.bind(this),\n },\n });\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(element);\n }\n }\n\n disconnectedCallback() {\n if (this._root) {\n this._root.unmount();\n }\n }\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AAQA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEA,IAAAI,KAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,SAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,MAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AAEA,MAAMQ,iBAAiB,GAAIC,CAAC,KAAM;EAAE,GAAGC,iBAAQ,CAACC,KAAK;EAAE,GAAGF;AAAE,CAAC,CAAC;AAC9D,MAAMG,yBAAyB,GAAIC,CAAC,KAAM;EAAE,GAAGH,iBAAQ,CAACI,aAAa;EAAE,GAAGD;AAAE,CAAC,CAAC;AAE/D,MAAME,uBAAuB,SAASC,WAAW,CAAC;EAC/DC,WAAWA,CAAA,EAAG;IACZ,KAAK,CAAC,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA,+CAM6BV,CAAC,IAAK;MAC3C,MAAMW,YAAY,GAAG;QAAE,GAAG,IAAI,CAACC;MAAO,CAAC;MAEvC,IAAI,CAACZ,CAAC,EAAE;QACN,OAAOW,YAAY;MACrB;MAEA,MAAME,cAAc,GAAG;QAAE,GAAGb;MAAE,CAAC;MAC/B,MAAM;QAAEc,MAAM;QAAEC;MAAY,CAAC,GAAGF,cAAc,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;QAClCiB,cAAc,EAAE,IAAI,CAACA,cAAc;QACnCC,sBAAsB,EAAE,IAAI,CAACA,sBAAsB;QACnDC,kBAAkB,EAAE;UAClBC,GAAG,EAAE,IAAI,CAAClB,WAAW,CAACmB,IAAI,CAAC,IAAI,CAAC;UAChCC,MAAM,EAAE,IAAI,CAACjB,aAAa,CAACgB,IAAI,CAAC,IAAI;QACtC,CAAC;QACDE,YAAY,EAAE;UACZH,GAAG,EAAE,IAAI,CAACX,WAAW,CAACY,IAAI,CAAC,IAAI,CAAC;UAChCC,MAAM,EAAE,IAAI,CAACX,aAAa,CAACU,IAAI,CAAC,IAAI;QACtC;MACF,CAAC,CAAC;MAEF,IAAI,CAAC,IAAI,CAACpB,KAAK,EAAE;QACf,IAAI,CAACA,KAAK,GAAG,IAAAuB,kBAAU,EAAC,IAAI,CAAC;MAC/B;MACA,IAAI,CAACvB,KAAK,CAACwB,MAAM,CAACZ,OAAO,CAAC;IAC5B;EACF;EAEAa,oBAAoBA,CAAA,EAAG;IACrB,IAAI,IAAI,CAACzB,KAAK,EAAE;MACd,IAAI,CAACA,KAAK,CAAC0B,OAAO,CAAC,CAAC;IACtB;EACF;AACF;AAACC,OAAA,CAAAzD,OAAA,GAAAJ,uBAAA","ignoreList":[]}
@@ -0,0 +1,454 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.Main = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _react = _interopRequireDefault(require("react"));
11
+ var _propTypes = _interopRequireDefault(require("prop-types"));
12
+ var _lodashEs = require("lodash-es");
13
+ var _styles = require("@mui/material/styles");
14
+ var _configUi = require("@pie-lib/config-ui");
15
+ var _scale = _interopRequireDefault(require("./scale"));
16
+ var _common = require("./common");
17
+ var _modals = require("./modals");
18
+ var _utils = require("./utils");
19
+ const {
20
+ Panel,
21
+ toggle
22
+ } = _configUi.settings;
23
+ const MIN_WIDTH = '650px';
24
+ const StyledDiv = (0, _styles.styled)('div')(({
25
+ theme
26
+ }) => ({
27
+ fontFamily: 'Cerebri Sans',
28
+ fontSize: theme.typography.fontSize + 2,
29
+ // current font size is 14px, so this will make it 16px
30
+ padding: '16px 0'
31
+ }));
32
+ const ShowModal = ({
33
+ showExcludeZeroDialog,
34
+ excludeZero,
35
+ changeExcludeZero,
36
+ cancel
37
+ }) => {
38
+ if (showExcludeZeroDialog && !excludeZero) {
39
+ return /*#__PURE__*/_react.default.createElement(_modals.ExcludeZeroDialog, {
40
+ open: showExcludeZeroDialog && !excludeZero,
41
+ changeExcludeZero: changeExcludeZero,
42
+ cancel: cancel
43
+ });
44
+ } else if (showExcludeZeroDialog && excludeZero) {
45
+ return /*#__PURE__*/_react.default.createElement(_modals.IncludeZeroDialog, {
46
+ open: showExcludeZeroDialog && excludeZero,
47
+ changeExcludeZero: changeExcludeZero,
48
+ cancel: cancel
49
+ });
50
+ } else {
51
+ return null;
52
+ }
53
+ };
54
+ ShowModal.propTypes = {
55
+ showExcludeZeroDialog: _propTypes.default.bool,
56
+ excludeZero: _propTypes.default.bool,
57
+ changeExcludeZero: _propTypes.default.func,
58
+ cancel: _propTypes.default.func
59
+ };
60
+ class Main extends _react.default.Component {
61
+ constructor(props) {
62
+ super(props);
63
+ (0, _defineProperty2.default)(this, "state", {
64
+ showDecreaseMaxPointsDialog: false,
65
+ showDeleteScaleDialog: false,
66
+ showDeleteTraitDialog: false,
67
+ showExcludeZeroDialog: false,
68
+ showInfoDialog: false,
69
+ infoDialogText: '',
70
+ adjustedWidth: MIN_WIDTH,
71
+ initialUpdateCompleted: false // flag to track the initial update of the div width
72
+ });
73
+ (0, _defineProperty2.default)(this, "updateDivWidthDebounced", (0, _lodashEs.debounce)(() => this.updateDivWidth(), 50));
74
+ (0, _defineProperty2.default)(this, "onScaleAdded", () => {
75
+ const {
76
+ model,
77
+ onModelChanged,
78
+ configuration
79
+ } = this.props;
80
+ let {
81
+ scales,
82
+ excludeZero
83
+ } = model || {};
84
+ const {
85
+ maxNoOfScales
86
+ } = configuration || {};
87
+ let {
88
+ defaultTraitLabel
89
+ } = configuration || '';
90
+ if (!scales.length) {
91
+ scales = [];
92
+ }
93
+
94
+ // if no default trait label is defined, take the trait label of the first scale
95
+ defaultTraitLabel = typeof defaultTraitLabel === 'string' ? defaultTraitLabel : scales[0]?.traitLabel || '';
96
+ if (scales.length === maxNoOfScales) {
97
+ this.set({
98
+ infoDialogText: `There can't be more than ${maxNoOfScales} scales.`,
99
+ showInfoDialog: true
100
+ });
101
+ return false;
102
+ }
103
+ scales.push({
104
+ maxPoints: 1,
105
+ scorePointsLabels: excludeZero ? [''] : ['', ''],
106
+ traitLabel: defaultTraitLabel,
107
+ traits: []
108
+ });
109
+ onModelChanged({
110
+ ...model,
111
+ scales
112
+ });
113
+ });
114
+ (0, _defineProperty2.default)(this, "onScaleChanged", (scaleIndex, params) => {
115
+ const {
116
+ model,
117
+ onModelChanged
118
+ } = this.props;
119
+ let scales = (0, _lodashEs.cloneDeep)((model || {}).scales);
120
+ if (scaleIndex < 0 || scaleIndex >= scales.length || (0, _lodashEs.isEmpty)(params)) return false;
121
+ Object.keys(params).forEach(key => {
122
+ scales[scaleIndex][key] = params[key];
123
+ });
124
+ if (model.excludeZero && params.maxPoints === 1) {
125
+ // excludeZero should be false and disabled when maxPoints is 1 for any scale
126
+ model.excludeZero = false;
127
+ scales = (0, _utils.addOrRemoveScaleColumn)(scales, _modals.excludeZeroTypes.add0);
128
+ }
129
+ onModelChanged({
130
+ ...model,
131
+ scales
132
+ });
133
+ });
134
+ (0, _defineProperty2.default)(this, "onScaleRemoved", scaleIndex => {
135
+ const {
136
+ model,
137
+ onModelChanged,
138
+ configuration
139
+ } = this.props;
140
+ let {
141
+ scales
142
+ } = model || {};
143
+ const {
144
+ minNoOfScales
145
+ } = configuration || {};
146
+ if (scaleIndex < 0 || scaleIndex >= scales.length) return false;
147
+ if (scales.length === minNoOfScales) {
148
+ this.set({
149
+ infoDialogText: `There can't be less than ${minNoOfScales} scales.`,
150
+ showInfoDialog: true
151
+ });
152
+ return false;
153
+ }
154
+ scales = [...scales.slice(0, scaleIndex), ...scales.slice(scaleIndex + 1)];
155
+ onModelChanged({
156
+ ...model,
157
+ scales
158
+ });
159
+ });
160
+ (0, _defineProperty2.default)(this, "onHalfScoringChanged", () => {
161
+ const {
162
+ model,
163
+ onModelChanged
164
+ } = this.props;
165
+ let {
166
+ halfScoring
167
+ } = model || {};
168
+ onModelChanged({
169
+ ...model,
170
+ halfScoring: !halfScoring
171
+ });
172
+ });
173
+ (0, _defineProperty2.default)(this, "onVisibleToStudentChanged", () => {
174
+ const {
175
+ model,
176
+ onModelChanged
177
+ } = this.props;
178
+ let {
179
+ visibleToStudent
180
+ } = model || {};
181
+ onModelChanged({
182
+ ...model,
183
+ visibleToStudent: !visibleToStudent
184
+ });
185
+ });
186
+ (0, _defineProperty2.default)(this, "set", newState => this.setState(newState));
187
+ (0, _defineProperty2.default)(this, "changeShowScorePointLabels", () => {
188
+ const {
189
+ model,
190
+ onModelChanged
191
+ } = this.props || {};
192
+ let {
193
+ pointLabels
194
+ } = model || {};
195
+ pointLabels = !pointLabels;
196
+ onModelChanged({
197
+ ...model,
198
+ pointLabels
199
+ });
200
+ });
201
+ (0, _defineProperty2.default)(this, "changeShowDescription", () => {
202
+ const {
203
+ model,
204
+ onModelChanged
205
+ } = this.props || {};
206
+ let {
207
+ description
208
+ } = model || {};
209
+ description = !description;
210
+ onModelChanged({
211
+ ...model,
212
+ description
213
+ });
214
+ });
215
+ (0, _defineProperty2.default)(this, "changeShowStandards", () => {
216
+ const {
217
+ model,
218
+ onModelChanged
219
+ } = this.props || {};
220
+ let {
221
+ standards
222
+ } = model || {};
223
+ standards = !standards;
224
+ onModelChanged({
225
+ ...model,
226
+ standards
227
+ });
228
+ });
229
+ // Exclude Zero
230
+ (0, _defineProperty2.default)(this, "showToggleExcludeZeroModal", () => this.set({
231
+ showExcludeZeroDialog: true
232
+ }));
233
+ (0, _defineProperty2.default)(this, "hideToggleExcludeZeroModal", () => {
234
+ this.set({
235
+ showExcludeZeroDialog: false
236
+ });
237
+ });
238
+ (0, _defineProperty2.default)(this, "onCloseInfoDialog", () => this.set({
239
+ showInfoDialog: false
240
+ }));
241
+ (0, _defineProperty2.default)(this, "changeExcludeZero", excludeZeroType => {
242
+ const {
243
+ model,
244
+ onModelChanged
245
+ } = this.props || {};
246
+ const {
247
+ scales
248
+ } = model || {};
249
+ let {
250
+ excludeZero
251
+ } = model || {};
252
+ if (!scales || !scales.length) return;
253
+ excludeZero = !excludeZero;
254
+ const newScales = (0, _utils.addOrRemoveScaleColumn)(scales, excludeZeroType);
255
+ onModelChanged({
256
+ ...model,
257
+ scales: newScales,
258
+ excludeZero
259
+ });
260
+ this.hideToggleExcludeZeroModal();
261
+ });
262
+ (0, _defineProperty2.default)(this, "onModelChanged", (updatedModel, updatedProperty) => {
263
+ const {
264
+ onModelChanged
265
+ } = this.props || {};
266
+ if (updatedProperty === 'excludeZero') {
267
+ this.showToggleExcludeZeroModal();
268
+ } else {
269
+ onModelChanged(updatedModel);
270
+ }
271
+ });
272
+ this.divRef = /*#__PURE__*/_react.default.createRef();
273
+ this.updateDivWidth = this.updateDivWidth.bind(this);
274
+ }
275
+ componentDidMount() {
276
+ window.addEventListener('resize', this.updateDivWidthDebounced);
277
+ window.addEventListener('load', this.updateDivWidth);
278
+
279
+ // delay updateDivWidth to avoid having this.divRef.current = null at first load
280
+ setTimeout(this.updateDivWidth, 0);
281
+ }
282
+ componentWillUnmount() {
283
+ window.removeEventListener('resize', this.updateDivWidthDebounced);
284
+ window.removeEventListener('load', this.updateDivWidth);
285
+ }
286
+ componentDidUpdate() {
287
+ if (!this.state.initialUpdateCompleted) {
288
+ this.updateDivWidth();
289
+ this.setState({
290
+ initialUpdateCompleted: true
291
+ });
292
+ }
293
+ }
294
+ updateDivWidth() {
295
+ if (this.divRef && this.divRef.current) {
296
+ const divWidth = this.divRef.current.offsetWidth;
297
+ if (divWidth !== this.state.adjustedWidth) {
298
+ this.set({
299
+ adjustedWidth: divWidth
300
+ });
301
+ }
302
+ }
303
+ }
304
+ render() {
305
+ const {
306
+ model,
307
+ configuration,
308
+ onConfigurationChanged,
309
+ uploadSoundSupport,
310
+ imageSupport
311
+ } = this.props || {};
312
+ const {
313
+ addScale,
314
+ baseInputConfiguration = {},
315
+ dragAndDrop,
316
+ contentDimensions = {},
317
+ showDescription,
318
+ showExcludeZero,
319
+ showLevelTagInput,
320
+ showStandards,
321
+ showHalfScoring,
322
+ showMaxPoint,
323
+ showScorePointLabels,
324
+ showVisibleToStudent,
325
+ spellCheck = {},
326
+ settingsPanelDisabled,
327
+ maxNoOfTraits,
328
+ minNoOfTraits,
329
+ width,
330
+ mathMlOptions = {},
331
+ maxMaxPoints,
332
+ expandedInput = {},
333
+ labelInput = {}
334
+ } = configuration || {};
335
+ const {
336
+ errors,
337
+ extraCSSRules,
338
+ scales,
339
+ excludeZero,
340
+ description,
341
+ pointLabels,
342
+ standards,
343
+ spellCheckEnabled,
344
+ maxPointsEnabled,
345
+ addScaleEnabled
346
+ } = model || {};
347
+ const {
348
+ showExcludeZeroDialog,
349
+ showInfoDialog,
350
+ infoDialogText,
351
+ adjustedWidth
352
+ } = this.state || {};
353
+
354
+ // excludeZero should be false and disabled when maxPoints is 1 for any scale
355
+ const disabledExcludeZero = scales?.some(scale => scale.maxPoints === 1);
356
+ const panelSettings = {
357
+ standards: showStandards.settings && toggle(showStandards.label),
358
+ 'showLevelTagInput.enabled': showLevelTagInput.settings && toggle(showLevelTagInput.label, true),
359
+ visibleToStudent: showVisibleToStudent.settings && toggle(showVisibleToStudent.label),
360
+ excludeZero: showExcludeZero.settings && toggle(showExcludeZero.label, false, disabledExcludeZero),
361
+ halfScoring: showHalfScoring.settings && toggle(showHalfScoring.label),
362
+ 'dragAndDrop.enabled': dragAndDrop.settings && toggle(dragAndDrop.label, true)
363
+ };
364
+ const panelProperties = {
365
+ description: showDescription.settings && toggle(showDescription.label),
366
+ pointLabels: showScorePointLabels.settings && toggle(showScorePointLabels.label),
367
+ spellCheckEnabled: spellCheck.settings && toggle(spellCheck.label),
368
+ maxPointsEnabled: showMaxPoint.settings && toggle(showMaxPoint.label),
369
+ addScaleEnabled: addScale.settings && toggle(addScale.label)
370
+ };
371
+ const getPluginProps = props => {
372
+ return Object.assign({
373
+ ...baseInputConfiguration
374
+ }, props || {});
375
+ };
376
+ return /*#__PURE__*/_react.default.createElement(_configUi.layout.ConfigLayout, {
377
+ extraCSSRules: extraCSSRules,
378
+ dimensions: contentDimensions,
379
+ hideSettings: settingsPanelDisabled,
380
+ settings: /*#__PURE__*/_react.default.createElement(Panel, {
381
+ model: model,
382
+ onChangeModel: this.onModelChanged,
383
+ configuration: configuration,
384
+ onChangeConfiguration: onConfigurationChanged,
385
+ groups: {
386
+ Settings: panelSettings,
387
+ Properties: panelProperties
388
+ },
389
+ modal: /*#__PURE__*/_react.default.createElement(ShowModal, {
390
+ showExcludeZeroDialog: showExcludeZeroDialog,
391
+ excludeZero: excludeZero,
392
+ changeExcludeZero: this.changeExcludeZero,
393
+ cancel: this.hideToggleExcludeZeroModal
394
+ })
395
+ })
396
+ }, /*#__PURE__*/_react.default.createElement("div", {
397
+ style: {
398
+ width: '100%'
399
+ },
400
+ ref: this.divRef
401
+ }), /*#__PURE__*/_react.default.createElement(StyledDiv, {
402
+ style: {
403
+ width: width || adjustedWidth
404
+ }
405
+ }, (scales || []).map((scale, scaleIndex) => /*#__PURE__*/_react.default.createElement(_scale.default, (0, _extends2.default)({
406
+ key: `scale-${scaleIndex}`,
407
+ scale: scale,
408
+ scaleIndex: scaleIndex,
409
+ errors: errors,
410
+ onScaleRemoved: this.onScaleRemoved,
411
+ onScaleChanged: this.onScaleChanged,
412
+ showStandards: standards,
413
+ showScorePointLabels: pointLabels,
414
+ showDescription: description,
415
+ showLevelTagInput: showLevelTagInput.enabled,
416
+ excludeZero: excludeZero,
417
+ enableDragAndDrop: dragAndDrop.enabled,
418
+ spellCheck: spellCheckEnabled,
419
+ width: adjustedWidth,
420
+ uploadSoundSupport: uploadSoundSupport,
421
+ maxPointsEnabled: maxPointsEnabled,
422
+ maxNoOfTraits: maxNoOfTraits,
423
+ minNoOfTraits: minNoOfTraits,
424
+ imageSupport: imageSupport
425
+ }, this.props, {
426
+ mathMlOptions: mathMlOptions,
427
+ maxMaxPoints: maxMaxPoints,
428
+ expandedPluginProps: getPluginProps(expandedInput?.inputConfiguration),
429
+ labelPluginProps: getPluginProps(labelInput?.inputConfiguration)
430
+ }))), addScaleEnabled && /*#__PURE__*/_react.default.createElement(_common.MultiTraitButton, {
431
+ onClick: this.onScaleAdded
432
+ }, "Add Scale")), /*#__PURE__*/_react.default.createElement(_modals.InfoDialog, {
433
+ open: showInfoDialog,
434
+ text: infoDialogText,
435
+ onClose: () => this.set({
436
+ showInfoDialog: false
437
+ })
438
+ }));
439
+ }
440
+ }
441
+ exports.Main = Main;
442
+ Main.propTypes = {
443
+ model: _propTypes.default.object,
444
+ uploadSoundSupport: _propTypes.default.object,
445
+ configuration: _propTypes.default.object,
446
+ onModelChanged: _propTypes.default.func,
447
+ onConfigurationChanged: _propTypes.default.func,
448
+ imageSupport: _propTypes.default.shape({
449
+ add: _propTypes.default.func.isRequired,
450
+ delete: _propTypes.default.func.isRequired
451
+ })
452
+ };
453
+ var _default = exports.default = Main;
454
+ //# sourceMappingURL=main.js.map