@pie-element/fraction-model 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 (166) hide show
  1. package/dist/author/card-bar.d.ts +21 -0
  2. package/dist/author/card-bar.d.ts.map +1 -0
  3. package/dist/author/card-bar.js +40 -0
  4. package/dist/author/defaults.d.ts +114 -0
  5. package/dist/author/defaults.d.ts.map +1 -0
  6. package/dist/author/defaults.js +84 -0
  7. package/dist/author/index.d.ts +45 -0
  8. package/dist/author/index.d.ts.map +1 -0
  9. package/dist/author/index.js +88 -0
  10. package/dist/author/main.d.ts +26 -0
  11. package/dist/author/main.d.ts.map +1 -0
  12. package/dist/author/main.js +156 -0
  13. package/dist/author/model-options.d.ts +33 -0
  14. package/dist/author/model-options.d.ts.map +1 -0
  15. package/dist/author/model-options.js +85 -0
  16. package/dist/author/number-text-field.d.ts +16 -0
  17. package/dist/author/number-text-field.d.ts.map +1 -0
  18. package/dist/author/number-text-field.js +20 -0
  19. package/dist/controller/defaults.d.ts +22 -0
  20. package/dist/controller/defaults.d.ts.map +1 -0
  21. package/dist/controller/defaults.js +13 -0
  22. package/dist/controller/index.d.ts +24 -0
  23. package/dist/controller/index.d.ts.map +1 -0
  24. package/dist/controller/index.js +68 -0
  25. package/dist/delivery/answer-fraction.d.ts +28 -0
  26. package/dist/delivery/answer-fraction.d.ts.map +1 -0
  27. package/dist/delivery/answer-fraction.js +69 -0
  28. package/dist/delivery/fraction-model-chart.d.ts +12 -0
  29. package/dist/delivery/fraction-model-chart.d.ts.map +1 -0
  30. package/dist/delivery/fraction-model-chart.js +154 -0
  31. package/dist/delivery/index.d.ts +23 -0
  32. package/dist/delivery/index.d.ts.map +1 -0
  33. package/dist/delivery/index.js +54 -0
  34. package/dist/delivery/main.d.ts +39 -0
  35. package/dist/delivery/main.d.ts.map +1 -0
  36. package/dist/delivery/main.js +136 -0
  37. package/dist/index.d.ts +2 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.iife.d.ts +9 -0
  40. package/dist/index.iife.d.ts.map +1 -0
  41. package/dist/index.iife.js +179 -0
  42. package/dist/index.js +2 -0
  43. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_DataView.js +6 -0
  44. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Hash.js +16 -0
  45. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_ListCache.js +16 -0
  46. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Map.js +6 -0
  47. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_MapCache.js +16 -0
  48. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Promise.js +6 -0
  49. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Set.js +6 -0
  50. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Stack.js +13 -0
  51. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Symbol.js +5 -0
  52. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Uint8Array.js +5 -0
  53. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_WeakMap.js +6 -0
  54. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayEach.js +7 -0
  55. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayFilter.js +10 -0
  56. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayLikeKeys.js +15 -0
  57. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayPush.js +7 -0
  58. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_assignValue.js +10 -0
  59. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_assocIndexOf.js +8 -0
  60. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseAssign.js +8 -0
  61. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseAssignIn.js +8 -0
  62. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseAssignValue.js +12 -0
  63. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseClone.js +57 -0
  64. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseCreate.js +14 -0
  65. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseGetAllKeys.js +9 -0
  66. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseGetTag.js +10 -0
  67. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsArguments.js +9 -0
  68. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsMap.js +9 -0
  69. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsNative.js +11 -0
  70. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsSet.js +9 -0
  71. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsTypedArray.js +11 -0
  72. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseKeys.js +12 -0
  73. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseKeysIn.js +13 -0
  74. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseTimes.js +7 -0
  75. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseUnary.js +8 -0
  76. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneArrayBuffer.js +8 -0
  77. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneBuffer.js +10 -0
  78. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneDataView.js +8 -0
  79. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneRegExp.js +8 -0
  80. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneSymbol.js +8 -0
  81. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneTypedArray.js +8 -0
  82. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copyArray.js +8 -0
  83. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copyObject.js +14 -0
  84. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copySymbols.js +8 -0
  85. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copySymbolsIn.js +8 -0
  86. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_coreJsData.js +5 -0
  87. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_defineProperty.js +10 -0
  88. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_freeGlobal.js +4 -0
  89. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getAllKeys.js +9 -0
  90. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getAllKeysIn.js +9 -0
  91. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getMapData.js +8 -0
  92. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getNative.js +9 -0
  93. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getPrototype.js +5 -0
  94. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getRawTag.js +14 -0
  95. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getSymbols.js +10 -0
  96. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getSymbolsIn.js +11 -0
  97. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getTag.js +23 -0
  98. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getValue.js +6 -0
  99. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashClear.js +7 -0
  100. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashDelete.js +7 -0
  101. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashGet.js +13 -0
  102. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashHas.js +9 -0
  103. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashSet.js +9 -0
  104. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_initCloneArray.js +8 -0
  105. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_initCloneByTag.js +33 -0
  106. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_initCloneObject.js +9 -0
  107. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isIndex.js +8 -0
  108. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isKeyable.js +7 -0
  109. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isMasked.js +11 -0
  110. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isPrototype.js +8 -0
  111. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheClear.js +6 -0
  112. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheDelete.js +9 -0
  113. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheGet.js +8 -0
  114. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheHas.js +7 -0
  115. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheSet.js +8 -0
  116. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheClear.js +13 -0
  117. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheDelete.js +8 -0
  118. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheGet.js +7 -0
  119. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheHas.js +7 -0
  120. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheSet.js +8 -0
  121. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nativeCreate.js +5 -0
  122. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nativeKeys.js +5 -0
  123. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nativeKeysIn.js +8 -0
  124. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nodeUtil.js +9 -0
  125. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_objectToString.js +7 -0
  126. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_overArg.js +8 -0
  127. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_root.js +5 -0
  128. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackClear.js +7 -0
  129. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackDelete.js +7 -0
  130. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackGet.js +6 -0
  131. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackHas.js +6 -0
  132. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackSet.js +16 -0
  133. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_toSource.js +15 -0
  134. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/cloneDeep.js +8 -0
  135. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/eq.js +6 -0
  136. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArguments.js +10 -0
  137. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArray.js +4 -0
  138. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArrayLike.js +8 -0
  139. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isBuffer.js +6 -0
  140. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isEmpty.js +21 -0
  141. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isFunction.js +11 -0
  142. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isLength.js +7 -0
  143. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isMap.js +7 -0
  144. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isObject.js +7 -0
  145. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isObjectLike.js +6 -0
  146. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isSet.js +7 -0
  147. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isTypedArray.js +7 -0
  148. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/keys.js +9 -0
  149. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/keysIn.js +9 -0
  150. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/stubArray.js +6 -0
  151. package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/stubFalse.js +6 -0
  152. package/package.json +70 -0
  153. package/src/author/card-bar.tsx +67 -0
  154. package/src/author/defaults.ts +88 -0
  155. package/src/author/index.ts +187 -0
  156. package/src/author/main.tsx +243 -0
  157. package/src/author/model-options.tsx +158 -0
  158. package/src/author/number-text-field.tsx +42 -0
  159. package/src/controller/defaults.ts +23 -0
  160. package/src/controller/index.ts +207 -0
  161. package/src/delivery/answer-fraction.tsx +113 -0
  162. package/src/delivery/fraction-model-chart.tsx +261 -0
  163. package/src/delivery/index.ts +96 -0
  164. package/src/delivery/main.tsx +256 -0
  165. package/src/index.iife.ts +16 -0
  166. package/src/index.ts +1 -0
@@ -0,0 +1,158 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-elements/packages/fraction-model/configure/src/model-options.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
+ import { MiniField } from './number-text-field.js';
14
+ import { styled } from '@mui/material/styles';
15
+ import Select from '@mui/material/Select';
16
+ import MenuItem from '@mui/material/MenuItem';
17
+ import CardBar from './card-bar.js';
18
+ import { Checkbox } from '@pie-lib/config-ui';
19
+ import { cloneDeep } from 'lodash-es';
20
+
21
+ const GroupInline: any = styled('div')({
22
+ alignItems: 'center',
23
+ display: 'flex',
24
+ gap: '20px',
25
+ });
26
+
27
+ const Group: any = styled('div')({
28
+ margin: '12px 0',
29
+ });
30
+
31
+ const InputLabel: any = styled('label')({
32
+ display: 'block',
33
+ marginBottom: '4px',
34
+ });
35
+
36
+ const StyledSelect: any = styled(Select)({
37
+ width: '80px',
38
+ alignItems: 'center',
39
+ height: '40px',
40
+ verticalAlign: 'top',
41
+ marginBottom: '8px',
42
+ '& .MuiSelect-select': {
43
+ paddingLeft: '10px',
44
+ },
45
+ });
46
+
47
+ const CheckboxContainer: any = styled('div')({
48
+ marginLeft: '-15px',
49
+ });
50
+
51
+ const CheckboxLabel: any = styled('span')({
52
+ verticalAlign: 'middle',
53
+ });
54
+
55
+ export class ModelOptions extends React.Component {
56
+ static propTypes = {
57
+ model: PropTypes.object.isRequired,
58
+ onChange: PropTypes.func,
59
+ modelOptions: PropTypes.object.isRequired,
60
+ };
61
+
62
+ constructor(props) {
63
+ super(props);
64
+ this.changeMaxModel = this.change.bind(this, 'max');
65
+ this.changePartModel = this.change.bind(this, 'part');
66
+ this.studentConfig = this.change.bind(this, 'student-config');
67
+ }
68
+
69
+ /**
70
+ * Function to trigger when DOM elements value change for Number type
71
+ * @param {string} key contains key of element
72
+ * @param {object} event contains event object
73
+ * @param {string} value contains value of DOM element
74
+ */
75
+ change(key, event, value) {
76
+ const { model, onChange } = this.props;
77
+ const oldModel = cloneDeep(model);
78
+ let newModel = cloneDeep(model);
79
+ let showDiag = false;
80
+ if (key === 'max') {
81
+ newModel.maxModelSelected = value;
82
+ showDiag = true;
83
+ } else if (key === 'part') {
84
+ newModel.partsPerModel = value;
85
+ showDiag = true;
86
+ } else if (key === 'student-config') {
87
+ newModel.allowedStudentConfig = value;
88
+ showDiag = false;
89
+ }
90
+ onChange(oldModel, newModel, showDiag);
91
+ }
92
+
93
+ /**
94
+ * Function to trigger on change of dropdown value model type
95
+ * @param {string} value contains selection value
96
+ */
97
+ handleSelect: any = (value) => {
98
+ const { model, onChange } = this.props;
99
+ model.modelTypeSelected = value?.target.value;
100
+ onChange(model, { ...model }, false);
101
+ };
102
+
103
+ render() {
104
+ const { model, modelOptions } = this.props;
105
+ const { maxOfModel, partsPerModel, modelTypeChoices } = modelOptions;
106
+
107
+ return (
108
+ <div>
109
+ <CardBar header="Configure Fraction Model"></CardBar>
110
+ <br />
111
+ <GroupInline>
112
+ <Group>
113
+ <InputLabel>Model Type</InputLabel>
114
+ <StyledSelect
115
+ onChange={this.handleSelect}
116
+ value={model.modelTypeSelected}
117
+ MenuProps={{
118
+ transitionDuration: { enter: 225, exit: 195 }
119
+ }}
120
+ >
121
+ {modelTypeChoices.map((choice, index) => (
122
+ <MenuItem key={'item_' + index} value={choice.value}>
123
+ {choice.label}
124
+ </MenuItem>
125
+ ))}
126
+ </StyledSelect>
127
+ </Group>
128
+ <Group>
129
+ <InputLabel>Max # of Models</InputLabel>
130
+ <MiniField
131
+ min={maxOfModel.min}
132
+ max={maxOfModel.max}
133
+ value={model.maxModelSelected}
134
+ name="max-model"
135
+ onChange={this.changeMaxModel}
136
+ />
137
+ </Group>
138
+ <Group>
139
+ <InputLabel>Parts per Model</InputLabel>
140
+ <MiniField
141
+ min={partsPerModel.min}
142
+ max={partsPerModel.max}
143
+ value={model.partsPerModel}
144
+ name="model-parts"
145
+ onChange={this.changePartModel}
146
+ />
147
+ </Group>
148
+ </GroupInline>
149
+ <CheckboxContainer>
150
+ <Checkbox onChange={this.studentConfig} checked={model.allowedStudentConfig} label={''} />
151
+ <CheckboxLabel>Allow student to configure number of models and parts per model</CheckboxLabel>
152
+ </CheckboxContainer>
153
+ </div>
154
+ );
155
+ }
156
+ }
157
+
158
+ export default ModelOptions;
@@ -0,0 +1,42 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-elements/packages/fraction-model/configure/src/number-text-field.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 { NumberTextField as NTF } from '@pie-lib/config-ui';
12
+ import React from 'react';
13
+ import { styled } from '@mui/material/styles';
14
+
15
+ const StyledNTF: any = styled(NTF)(({ theme }) => ({
16
+ marginLeft: theme.spacing(1),
17
+ }));
18
+
19
+ const MiniStyledNTF: any = styled(NTF)({
20
+ maxWidth: '120px',
21
+ width: '120px',
22
+ marginTop: '0',
23
+ '& [class^="MuiInputBase-root"]': {
24
+ height: 40,
25
+ fontSize: '14px',
26
+ },
27
+ });
28
+
29
+ export class NumberTextField extends React.Component {
30
+ static propTypes = {};
31
+
32
+ render() {
33
+ const props = { ...this.props };
34
+ return <StyledNTF {...props} variant="outlined" />;
35
+ }
36
+ }
37
+
38
+ export const MiniField = React.forwardRef((props, ref) => (
39
+ <MiniStyledNTF {...props} ref={ref} variant="outlined" />
40
+ ));
41
+
42
+ export default NumberTextField;
@@ -0,0 +1,23 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-elements/packages/fraction-model/controller/src/defaults.js
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
+ // Should be exactly the same as configure/defaults.js
12
+ export default {
13
+ model: {
14
+ correctResponse: [],
15
+ title: '',
16
+ prompt: '',
17
+ modelTypeSelected: 'bar',
18
+ maxModelSelected: 1,
19
+ partsPerModel: 5,
20
+ allowedStudentConfig: false,
21
+ showGraphLabels: false,
22
+ },
23
+ };
@@ -0,0 +1,207 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-elements/packages/fraction-model/controller/src/index.js
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 { isEmpty } from 'lodash-es';
12
+ import defaults from './defaults.js';
13
+
14
+ /*
15
+ * Function to check the correctness of the response
16
+ * @param {model} model contains the model object
17
+ * @param {answers} answers contains the answers object
18
+ * @param {env} env contains the environment object
19
+ * @returns {string} returns the correctness of the response
20
+ * */
21
+ export const getResponseCorrectness = (model, answers, env = {}) => {
22
+ let correct;
23
+ if (model.allowedStudentConfig) {
24
+ correct = !!(
25
+ answers.partsPerModel === model.partsPerModel &&
26
+ partialFillCheck(answers.response, model.partsPerModel) &&
27
+ numeratorCheck(model.correctResponse, answers.response)
28
+ );
29
+ } else {
30
+ correct = !!(
31
+ partialFillCheck(answers.response, model.partsPerModel) && numeratorCheck(model.correctResponse, answers.response)
32
+ );
33
+ }
34
+ return correct ? 'correct' : 'incorrect';
35
+ };
36
+
37
+ /*
38
+ * Function to get the correctness of the response
39
+ * @param {question} question contains the question object
40
+ * @param {env} env contains the environment object
41
+ * @param {answers} answers contains the answers object
42
+ * @returns {string} returns the correctness
43
+ * */
44
+ const getCorrectness = (question, env, answers = {}) => {
45
+ if (env.mode === 'evaluate') {
46
+ return getResponseCorrectness(question, answers, env);
47
+ }
48
+ };
49
+
50
+ /*
51
+ * Function to get the outcome score
52
+ * @param {question} question contains the question object
53
+ * @param {env} env contains the environment object
54
+ * @param {answers} answers contains the answers object
55
+ * @returns {number} returns the score
56
+ * */
57
+ const getOutComeScore = (question, env, answers = {}) => {
58
+ const correctness = getCorrectness(question, env, answers);
59
+ return correctness === 'correct' ? 1 : 0;
60
+ };
61
+
62
+ /*
63
+ * Function to check outcome of the session
64
+ * @param {model} model contains the model object
65
+ * @param {session} session contains the session object
66
+ * @param {env} env contains the environment object
67
+ * @returns {Promise} returns the score
68
+ */
69
+ export const outcome = (model, session, env) =>
70
+ new Promise((resolve) => {
71
+ if (!session || isEmpty(session)) {
72
+ resolve({ score: 0, empty: true });
73
+ } else {
74
+ if (env.mode !== 'evaluate') {
75
+ resolve({ score: undefined, completed: undefined });
76
+ } else {
77
+ resolve({ score: getOutComeScore(model, env, session.answers) });
78
+ }
79
+ }
80
+ });
81
+
82
+ /*
83
+ * Function to check if the numerator of the response matches the numerator of the correct response
84
+ * @param {correctResponse} correctResponse contains the correct response object
85
+ * @param {response} response contains the response object
86
+ * @returns {boolean} returns true if the numerators match
87
+ * */
88
+ const numeratorCheck = (correctResponse, response) => {
89
+ let correctNumerator = 0;
90
+ let responseNumerator = 0;
91
+ for (let i = 0; i < correctResponse.length; i++) {
92
+ correctNumerator += correctResponse[i].value;
93
+ }
94
+ for (let i = 0; i < response.length; i++) {
95
+ responseNumerator += response[i].value;
96
+ }
97
+ return correctNumerator === responseNumerator;
98
+ };
99
+
100
+ /*
101
+ * Function to check if the response contains more than one partially-filled model
102
+ * @param {response} response contains the response object
103
+ * @param {partsPerModel} partsPerModel contains the number of parts per model
104
+ * */
105
+ const partialFillCheck = (response, partsPerModel) => {
106
+ if (response.length > 0) {
107
+ let partialModelCount = 0;
108
+ response.forEach((selection) => {
109
+ if (selection.value !== partsPerModel) {
110
+ partialModelCount++;
111
+ }
112
+ });
113
+ return partialModelCount <= 1;
114
+ } else {
115
+ return false;
116
+ }
117
+ };
118
+
119
+ /*
120
+ * Function to create a default model
121
+ * @param {model} model contains the model object
122
+ * */
123
+ export const createDefaultModel = (model = {}) => ({
124
+ ...defaults.model,
125
+ ...model,
126
+ });
127
+
128
+ /*
129
+ * Return the model object
130
+ * */
131
+ export const model = (question, session, env) => {
132
+ return new Promise((resolve) => {
133
+ session = session || {};
134
+ const model = createDefaultModel(question);
135
+ let correctness, score;
136
+ if ((!session || isEmpty(session)) && env.mode === 'evaluate') {
137
+ correctness = 'unanswered';
138
+ score = '0%';
139
+ } else {
140
+ correctness = getCorrectness(model, env, session && session.answers);
141
+ score = `${getOutComeScore(model, env, session && session.answers) * 100}%`;
142
+ }
143
+ const correctInfo = {
144
+ score,
145
+ correctness,
146
+ };
147
+ const out = {
148
+ env,
149
+ ...model,
150
+ view: env.mode === 'view' || env.mode === 'evaluate',
151
+ };
152
+ if (env.mode === 'evaluate') {
153
+ Object.assign(out, {
154
+ correctness: correctInfo,
155
+ });
156
+ }
157
+ resolve(out);
158
+ });
159
+ };
160
+
161
+ /*
162
+ * Function to create a correct response session
163
+ * @param {model} model contains the model object
164
+ * @param {env} env contains the environment object
165
+ * @returns {Promise} returns the correct response session
166
+ * */
167
+ export const createCorrectResponseSession = (model, env) => {
168
+ return new Promise((resolve) => {
169
+ if (env.mode !== 'evaluate' && env.role === 'instructor') {
170
+ const { correctResponse, maxModelSelected, partsPerModel } = model;
171
+ resolve({
172
+ answers: {
173
+ response: correctResponse,
174
+ noOfModel: maxModelSelected,
175
+ partsPerModel,
176
+ },
177
+ id: '1',
178
+ });
179
+ } else {
180
+ resolve(null);
181
+ }
182
+ });
183
+ };
184
+
185
+ /*
186
+ * Function to validate the model
187
+ * @param {model} model contains the model object
188
+ * @param {config} config contains the config object
189
+ * */
190
+ export const validate = (model = {}, config = {}) => {
191
+ const errors = {};
192
+ if (model.correctResponse.length === 0) {
193
+ errors.correctResponse = 'To save the item, at least one section must be marked as correct.';
194
+ }
195
+ if (model.correctResponse.length > 0) {
196
+ let partialModelCount = 0;
197
+ model.correctResponse.forEach((selection) => {
198
+ if (selection.value !== model.partsPerModel) {
199
+ partialModelCount++;
200
+ }
201
+ });
202
+ if (partialModelCount > 1) {
203
+ errors.correctResponse = 'The correct answer should include no more than one partially-filled model';
204
+ }
205
+ }
206
+ return errors;
207
+ };
@@ -0,0 +1,113 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-elements/packages/fraction-model/src/answer-fraction.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
+ import { styled } from '@mui/material/styles';
14
+ import { TextField } from '@mui/material';
15
+
16
+ const GroupInline: any = styled('div')({
17
+ alignItems: 'center',
18
+ display: 'flex',
19
+ gap: '20px',
20
+ });
21
+
22
+ const Group: any = styled('div')({
23
+ margin: '12px 0',
24
+ });
25
+
26
+ const InputLabel: any = styled('label')({
27
+ display: 'block',
28
+ marginBottom: '4px',
29
+ });
30
+
31
+ const StyledTextField: any = styled(TextField)({
32
+ width: '120px',
33
+ maxHeight: '40px',
34
+ '& [class^="MuiInputBase-root"]': {
35
+ height: 40,
36
+ fontSize: '14px',
37
+ },
38
+ });
39
+
40
+ export class AnswerFraction extends React.Component {
41
+ static propTypes = {
42
+ model: PropTypes.object.isRequired,
43
+ disabled: PropTypes.bool.isRequired,
44
+ showCorrect: PropTypes.bool.isRequired,
45
+ onAnswerChange: PropTypes.func.isRequired,
46
+ answers: PropTypes.object.isRequired,
47
+ };
48
+
49
+ /**
50
+ * Function to trigger when value change from number selection
51
+ * @param {string} key contains event change object
52
+ * @returns updated answer change object
53
+ */
54
+ onValueChange = (key) => (event) => {
55
+ let value = parseInt(event?.target?.value);
56
+ const { model, onAnswerChange, answers } = this.props;
57
+ const newAnswers = { ...answers };
58
+ const min = 1;
59
+ const max = (key === 'noOfModel') ? model.maxModelSelected : 9;
60
+ if(value > max) {
61
+ value = max;
62
+ } else if(value < min) {
63
+ value = min;
64
+ }
65
+ newAnswers[key] = value;
66
+ onAnswerChange(newAnswers);
67
+ };
68
+
69
+ render() {
70
+ const { model, showCorrect, answers, disabled } = this.props;
71
+
72
+ return (
73
+ <div>
74
+ {model.allowedStudentConfig && (
75
+ <GroupInline>
76
+ <Group>
77
+ <InputLabel htmlFor={'preview_number-of-models'}>
78
+ Number of Models
79
+ </InputLabel>
80
+ <StyledTextField
81
+ id="preview_number-of-models"
82
+ inputProps={{ min: 1, max: model.maxModelSelected }}
83
+ name="preview_number-of-models"
84
+ onChange={this.onValueChange('noOfModel')}
85
+ type="number"
86
+ variant="outlined"
87
+ disabled={disabled}
88
+ value={showCorrect ? model.maxModelSelected : answers.noOfModel}
89
+ />
90
+ </Group>
91
+ <Group>
92
+ <InputLabel htmlFor={'preview_parts-per-model'}>
93
+ Parts per Model
94
+ </InputLabel>
95
+ <StyledTextField
96
+ id="preview_parts-per-model"
97
+ inputProps={{ min: 1, max: 9 }}
98
+ name="preview_parts-per-model"
99
+ onChange={this.onValueChange('partsPerModel')}
100
+ type="number"
101
+ variant="outlined"
102
+ disabled={disabled}
103
+ value={showCorrect ? model.partsPerModel : answers.partsPerModel}
104
+ />
105
+ </Group>
106
+ </GroupInline>
107
+ )}
108
+ </div>
109
+ );
110
+ }
111
+ }
112
+
113
+ export default AnswerFraction;