@pie-element/rubric 8.1.2-next.5 → 8.1.3

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 (93) hide show
  1. package/CHANGELOG.json +257 -0
  2. package/CHANGELOG.md +1731 -0
  3. package/LICENSE.md +5 -0
  4. package/README.md +3 -0
  5. package/configure/CHANGELOG.json +197 -0
  6. package/configure/CHANGELOG.md +1571 -0
  7. package/configure/lib/defaults.js +70 -0
  8. package/configure/lib/defaults.js.map +1 -0
  9. package/configure/lib/index.js +135 -0
  10. package/configure/lib/index.js.map +1 -0
  11. package/configure/lib/main.js +103 -0
  12. package/configure/lib/main.js.map +1 -0
  13. package/configure/package.json +23 -0
  14. package/configure/src/__tests__/index.test.jsx +192 -0
  15. package/configure/src/defaults.js +43 -0
  16. package/configure/src/index.js +139 -0
  17. package/configure/src/main.jsx +87 -0
  18. package/controller/CHANGELOG.json +17 -0
  19. package/controller/CHANGELOG.md +901 -0
  20. package/controller/lib/defaults.js +15 -0
  21. package/controller/lib/defaults.js.map +1 -0
  22. package/controller/lib/index.js +46 -0
  23. package/controller/lib/index.js.map +1 -0
  24. package/controller/package.json +12 -0
  25. package/controller/src/__tests__/index.test.js +33 -0
  26. package/controller/src/defaults.js +8 -0
  27. package/controller/src/index.js +41 -0
  28. package/docs/config-schema.json +712 -0
  29. package/docs/config-schema.json.md +532 -0
  30. package/docs/demo/config.js +8 -0
  31. package/docs/demo/generate.js +8 -0
  32. package/docs/demo/index.html +2 -0
  33. package/docs/pie-schema.json +391 -0
  34. package/docs/pie-schema.json.md +281 -0
  35. package/lib/index.js +52 -0
  36. package/lib/index.js.map +1 -0
  37. package/lib/main.js +208 -0
  38. package/lib/main.js.map +1 -0
  39. package/lib/print.js +71 -0
  40. package/lib/print.js.map +1 -0
  41. package/module/configure.js +1 -0
  42. package/module/controller.js +73 -0
  43. package/module/demo.js +33 -0
  44. package/module/element.js +1 -0
  45. package/module/index.html +21 -0
  46. package/module/manifest.json +14 -0
  47. package/module/print-demo.js +71 -0
  48. package/module/print.html +18 -0
  49. package/module/print.js +1 -0
  50. package/package.json +25 -87
  51. package/src/__tests__/rubric-view.test.jsx +37 -0
  52. package/src/index.js +48 -0
  53. package/src/main.jsx +226 -0
  54. package/src/print.js +74 -0
  55. package/configure.js +0 -2
  56. package/controller.js +0 -1
  57. package/dist/author/defaults.d.ts +0 -71
  58. package/dist/author/defaults.js +0 -53
  59. package/dist/author/index.d.ts +0 -21
  60. package/dist/author/index.js +0 -72
  61. package/dist/author/main.d.ts +0 -14
  62. package/dist/author/main.js +0 -51
  63. package/dist/browser/author/index.js +0 -50284
  64. package/dist/browser/author/index.js.map +0 -1
  65. package/dist/browser/controller/index.js +0 -41
  66. package/dist/browser/controller/index.js.map +0 -1
  67. package/dist/browser/delivery/index.js +0 -34
  68. package/dist/browser/delivery/index.js.map +0 -1
  69. package/dist/browser/dist-B6elSZkE.js +0 -9091
  70. package/dist/browser/dist-B6elSZkE.js.map +0 -1
  71. package/dist/browser/dist-Bs_ywPM1.js +0 -102
  72. package/dist/browser/dist-Bs_ywPM1.js.map +0 -1
  73. package/dist/browser/main-C0Q1SfKi.js +0 -153
  74. package/dist/browser/main-C0Q1SfKi.js.map +0 -1
  75. package/dist/browser/print/index.js +0 -34
  76. package/dist/browser/print/index.js.map +0 -1
  77. package/dist/browser/rubric.css +0 -2
  78. package/dist/controller/defaults.d.ts +0 -17
  79. package/dist/controller/defaults.js +0 -21
  80. package/dist/controller/index.d.ts +0 -10
  81. package/dist/controller/index.js +0 -23
  82. package/dist/delivery/index.d.ts +0 -16
  83. package/dist/delivery/index.js +0 -33
  84. package/dist/delivery/main.d.ts +0 -34
  85. package/dist/delivery/main.js +0 -156
  86. package/dist/index.d.ts +0 -1
  87. package/dist/index.iife.d.ts +0 -8
  88. package/dist/index.iife.js +0 -145
  89. package/dist/index.js +0 -2
  90. package/dist/print/index.d.ts +0 -15
  91. package/dist/print/index.js +0 -34
  92. package/dist/runtime-support.d.ts +0 -12
  93. package/dist/runtime-support.js +0 -12
@@ -0,0 +1,139 @@
1
+ import { ModelUpdatedEvent, InsertImageEvent, DeleteImageEvent } from '@pie-framework/pie-configure-events';
2
+ import React from 'react';
3
+ import { createRoot } from 'react-dom/client';
4
+ import debug from 'debug';
5
+
6
+ import Main from './main';
7
+ import defaults from './defaults';
8
+
9
+ const modelWithDefaults = (m) => ({ ...defaults.model, ...m });
10
+
11
+ const configurationWithDefaults = (c) => ({ ...defaults.configuration, ...c });
12
+
13
+ export default class RubricElement extends HTMLElement {
14
+ constructor() {
15
+ super();
16
+ this._root = null;
17
+ debug.log('constructor called');
18
+ this._model = modelWithDefaults();
19
+ this._configuration = configurationWithDefaults();
20
+ this.onModelChanged = this.onModelChanged.bind(this);
21
+ this.onConfigurationChanged = this.onConfigurationChanged.bind(this);
22
+ }
23
+
24
+ updateModelAccordingToReceivedProps = (nextModel) => {
25
+ const currentModel = { ...this._model };
26
+
27
+ if (!nextModel) {
28
+ return currentModel;
29
+ }
30
+
31
+ const validatedModel = { ...nextModel };
32
+
33
+ // excludeZero should be false and disabled when maxPoints is 1
34
+ if (validatedModel.maxPoints === 1) {
35
+ validatedModel.excludeZero = false;
36
+ }
37
+
38
+ const { maxPoints, excludeZero } = validatedModel || {};
39
+
40
+ validatedModel.points = validatedModel.points ? [...validatedModel.points] : [];
41
+ validatedModel.sampleAnswers = validatedModel.sampleAnswers ? [...validatedModel.sampleAnswers] : [];
42
+
43
+ const howManyPointsShouldHave = excludeZero ? maxPoints : maxPoints + 1;
44
+ const howManyPointsDoesItHave = validatedModel.points.length;
45
+
46
+ const excludeZeroChanged = currentModel?.excludeZero !== nextModel?.excludeZero;
47
+ const maxPointsChanged = currentModel?.maxPoints !== nextModel?.maxPoints;
48
+
49
+ if (howManyPointsDoesItHave < howManyPointsShouldHave) {
50
+ if (excludeZeroChanged && !excludeZero) {
51
+ validatedModel.points = ['', ...validatedModel.points];
52
+ validatedModel.sampleAnswers = [null, ...validatedModel.sampleAnswers];
53
+ }
54
+
55
+ if (maxPointsChanged) {
56
+ for (let i = 0; i < howManyPointsShouldHave - howManyPointsDoesItHave; i++) {
57
+ validatedModel.points.push('');
58
+ validatedModel.sampleAnswers.push(null);
59
+ }
60
+ }
61
+ } else if (howManyPointsDoesItHave > howManyPointsShouldHave) {
62
+ if (excludeZeroChanged && excludeZero) {
63
+ validatedModel.points = validatedModel.points.slice(1);
64
+ validatedModel.sampleAnswers = validatedModel.sampleAnswers.slice(1);
65
+ }
66
+
67
+ if (maxPointsChanged) {
68
+ validatedModel.points = validatedModel.points.slice(0, howManyPointsShouldHave);
69
+ validatedModel.sampleAnswers = validatedModel.sampleAnswers.slice(0, howManyPointsShouldHave);
70
+ }
71
+ }
72
+
73
+ return validatedModel;
74
+ };
75
+
76
+ set model(m) {
77
+ this._model = this.updateModelAccordingToReceivedProps(modelWithDefaults(m));
78
+ this._render();
79
+ }
80
+
81
+ set configuration(c) {
82
+ this._configuration = configurationWithDefaults(c);
83
+ this._render();
84
+ }
85
+
86
+ onModelChanged(m) {
87
+ this._model = this.updateModelAccordingToReceivedProps(m);
88
+ this._render();
89
+ this.dispatchEvent(new ModelUpdatedEvent(this._model, false));
90
+ }
91
+
92
+ onConfigurationChanged = (c) => {
93
+ this._configuration = configurationWithDefaults(c);
94
+
95
+ if (this._model) {
96
+ this.onModelChanged(this._model);
97
+ }
98
+
99
+ this._render();
100
+ };
101
+
102
+ insertImage(handler) {
103
+ this.dispatchEvent(new InsertImageEvent(handler));
104
+ }
105
+
106
+ onDeleteImage(src, done) {
107
+ this.dispatchEvent(new DeleteImageEvent(src, done));
108
+ }
109
+
110
+ connectedCallback() {
111
+ this._render();
112
+ }
113
+
114
+ _render() {
115
+ if (this._model) {
116
+ let element = React.createElement(Main, {
117
+ model: this._model,
118
+ configuration: this._configuration,
119
+ onModelChanged: this.onModelChanged,
120
+ onConfigurationChanged: this.onConfigurationChanged,
121
+ imageSupport: {
122
+ add: this.insertImage.bind(this),
123
+ delete: this.onDeleteImage.bind(this),
124
+ },
125
+ });
126
+
127
+ if (!this._root) {
128
+ this._root = createRoot(this);
129
+ }
130
+ this._root.render(element);
131
+ }
132
+ }
133
+
134
+ disconnectedCallback() {
135
+ if (this._root) {
136
+ this._root.unmount();
137
+ }
138
+ }
139
+ }
@@ -0,0 +1,87 @@
1
+ import React from 'react';
2
+ import { Authoring } from '@pie-lib/rubric';
3
+ import { styled } from '@mui/material/styles';
4
+ import { layout, settings } from '@pie-lib/config-ui';
5
+
6
+ const { Panel, toggle } = settings;
7
+
8
+ const StyledDiv = styled('div')(({ theme, width }) => ({
9
+ maxWidth: width,
10
+ fontFamily: 'Cerebri Sans',
11
+ fontSize: theme.typography.fontSize,
12
+ }));
13
+
14
+ class Main extends React.Component {
15
+ verifyRubriclessModel = (m, config) => {
16
+ const { rubricless = false } = config || {};
17
+ return rubricless ? (({ points, sampleAnswers, ...rest }) => rest)(m) : m;
18
+ };
19
+
20
+ render() {
21
+ const { model, configuration, onConfigurationChanged, onModelChanged, imageSupport } = this.props || {};
22
+ const {
23
+ baseInputConfiguration = {},
24
+ contentDimensions = {},
25
+ settingsPanelDisabled,
26
+ showExcludeZero = {},
27
+ showMaxPoint = {},
28
+ mathMlOptions = {},
29
+ rubricless = false,
30
+ rubriclessInstruction,
31
+ width,
32
+ } = configuration || {};
33
+
34
+ // ensure to eliminate points and sampleAnswers in case of rubricless
35
+ const value = this.verifyRubriclessModel(model, configuration);
36
+ const { extraCSSRules } = model;
37
+
38
+ const panelProperties = {
39
+ excludeZeroEnabled: showExcludeZero.settings && toggle(showExcludeZero.label),
40
+ maxPointsEnabled: showMaxPoint.settings && toggle(showMaxPoint.label),
41
+ rubriclessInstructionEnabled: rubricless && rubriclessInstruction.settings && toggle(rubriclessInstruction.label),
42
+ };
43
+
44
+ const getPluginProps = (props) => {
45
+ return Object.assign(
46
+ {
47
+ ...baseInputConfiguration,
48
+ },
49
+ props || {},
50
+ );
51
+ };
52
+
53
+ return (
54
+ <layout.ConfigLayout
55
+ extraCSSRules={extraCSSRules}
56
+ dimensions={contentDimensions}
57
+ hideSettings={settingsPanelDisabled}
58
+ settings={
59
+ <Panel
60
+ model={model}
61
+ onChangeModel={onModelChanged}
62
+ configuration={configuration}
63
+ onChangeConfiguration={onConfigurationChanged}
64
+ pluginOpts={getPluginProps(rubriclessInstruction?.inputConfiguration)}
65
+ groups={{
66
+ Properties: panelProperties,
67
+ }}
68
+ imageSupport={imageSupport}
69
+ />
70
+ } >
71
+ <StyledDiv width={width}>
72
+ <Authoring
73
+ value={value}
74
+ config={configuration}
75
+ onChange={onModelChanged}
76
+ mathMlOptions={mathMlOptions}
77
+ rubricless={rubricless}
78
+ pluginOpts={baseInputConfiguration}
79
+ imageSupport={imageSupport}
80
+ />
81
+ </StyledDiv>
82
+ </layout.ConfigLayout>
83
+ );
84
+ }
85
+ }
86
+
87
+ export default Main;
@@ -0,0 +1,17 @@
1
+ [
2
+ {
3
+ "type": "fix",
4
+ "scope": null,
5
+ "subject": "bump all packages to avoid tag conflict",
6
+ "merge": null,
7
+ "header": "fix: bump all packages to avoid tag conflict",
8
+ "body": null,
9
+ "footer": null,
10
+ "notes": [],
11
+ "hash": "d9ec9a8689f0a391594b5e2f4ea958c6dc9f6d7b",
12
+ "gitTags": " (develop)",
13
+ "committerDate": "2020-04-10 20:01:37 +0100",
14
+ "isTagged": true,
15
+ "tag": "@pie-element/rubric-controller@1.1.1"
16
+ }
17
+ ]