@pie-element/categorize 11.3.4-next.0 → 12.0.0-beta.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.
- package/configure/lib/defaults.js +2 -5
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/design/builder.js +15 -33
- package/configure/lib/design/builder.js.map +1 -1
- package/configure/lib/design/buttons.js +41 -95
- package/configure/lib/design/buttons.js.map +1 -1
- package/configure/lib/design/categories/RowLabel.js +32 -45
- package/configure/lib/design/categories/RowLabel.js.map +1 -1
- package/configure/lib/design/categories/alternateResponses.js +96 -251
- package/configure/lib/design/categories/alternateResponses.js.map +1 -1
- package/configure/lib/design/categories/category.js +135 -208
- package/configure/lib/design/categories/category.js.map +1 -1
- package/configure/lib/design/categories/choice-preview.js +61 -126
- package/configure/lib/design/categories/choice-preview.js.map +1 -1
- package/configure/lib/design/categories/droppable-placeholder.js +73 -165
- package/configure/lib/design/categories/droppable-placeholder.js.map +1 -1
- package/configure/lib/design/categories/index.js +195 -384
- package/configure/lib/design/categories/index.js.map +1 -1
- package/configure/lib/design/choices/choice.js +155 -264
- package/configure/lib/design/choices/choice.js.map +1 -1
- package/configure/lib/design/choices/config.js +42 -98
- package/configure/lib/design/choices/config.js.map +1 -1
- package/configure/lib/design/choices/index.js +148 -236
- package/configure/lib/design/choices/index.js.map +1 -1
- package/configure/lib/design/header.js +57 -111
- package/configure/lib/design/header.js.map +1 -1
- package/configure/lib/design/index.js +631 -476
- package/configure/lib/design/index.js.map +1 -1
- package/configure/lib/design/input-header.js +93 -149
- package/configure/lib/design/input-header.js.map +1 -1
- package/configure/lib/design/utils.js +4 -15
- package/configure/lib/design/utils.js.map +1 -1
- package/configure/lib/index.js +120 -183
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/main.js +30 -74
- package/configure/lib/main.js.map +1 -1
- package/configure/lib/utils.js +22 -32
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +15 -15
- package/controller/lib/defaults.js +2 -5
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +237 -318
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js +28 -65
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +5 -5
- package/lib/categorize/categories.js +106 -164
- package/lib/categorize/categories.js.map +1 -1
- package/lib/categorize/category.js +73 -123
- package/lib/categorize/category.js.map +1 -1
- package/lib/categorize/choice.js +118 -245
- package/lib/categorize/choice.js.map +1 -1
- package/lib/categorize/choices.js +66 -131
- package/lib/categorize/choices.js.map +1 -1
- package/lib/categorize/droppable-placeholder.js +46 -103
- package/lib/categorize/droppable-placeholder.js.map +1 -1
- package/lib/categorize/grid-content.js +39 -87
- package/lib/categorize/grid-content.js.map +1 -1
- package/lib/categorize/index.js +341 -317
- package/lib/categorize/index.js.map +1 -1
- package/lib/index.js +285 -306
- package/lib/index.js.map +1 -1
- package/package.json +16 -14
package/lib/index.js
CHANGED
|
@@ -1,337 +1,316 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
|
-
exports
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
-
|
|
16
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
17
|
-
|
|
18
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
19
|
-
|
|
20
|
-
var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
|
|
21
|
-
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
22
9
|
var _react = _interopRequireDefault(require("react"));
|
|
23
|
-
|
|
24
|
-
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
25
|
-
|
|
10
|
+
var _client = require("react-dom/client");
|
|
26
11
|
var _mathRendering = require("@pie-lib/math-rendering");
|
|
27
|
-
|
|
28
12
|
var _renderUi = require("@pie-lib/render-ui");
|
|
29
|
-
|
|
30
13
|
var _piePlayerEvents = require("@pie-framework/pie-player-events");
|
|
31
|
-
|
|
32
14
|
var _categorize = _interopRequireDefault(require("./categorize"));
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
function Categorize() {
|
|
44
|
-
(0, _classCallCheck2["default"])(this, Categorize);
|
|
45
|
-
return _super.apply(this, arguments);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
(0, _createClass2["default"])(Categorize, [{
|
|
49
|
-
key: "model",
|
|
50
|
-
set: function set(m) {
|
|
51
|
-
this._model = m;
|
|
52
|
-
this.eliminateBlindAnswersFromSession();
|
|
53
|
-
this.dispatchEvent(new _piePlayerEvents.ModelSetEvent(this.tagName.toLowerCase(), this.isComplete(), !!this._model)); // reset the audioInitialized to false since the model changed, and we might need to reinitialize the audio
|
|
54
|
-
|
|
55
|
-
this._audioInitialized = false;
|
|
56
|
-
this.render();
|
|
57
|
-
}
|
|
58
|
-
}, {
|
|
59
|
-
key: "isComplete",
|
|
60
|
-
value: function isComplete() {
|
|
61
|
-
var _ref = this._model || {},
|
|
62
|
-
autoplayAudioEnabled = _ref.autoplayAudioEnabled,
|
|
63
|
-
choices = _ref.choices,
|
|
64
|
-
completeAudioEnabled = _ref.completeAudioEnabled,
|
|
65
|
-
hasUnplacedChoices = _ref.hasUnplacedChoices,
|
|
66
|
-
possibleResponses = _ref.possibleResponses,
|
|
67
|
-
responseAreasToBeFilled = _ref.responseAreasToBeFilled;
|
|
68
|
-
|
|
69
|
-
var elementContext = this; // check audio completion if audio settings are enabled and audio actually exists
|
|
70
|
-
|
|
71
|
-
if (autoplayAudioEnabled && completeAudioEnabled && !this.audioComplete) {
|
|
72
|
-
if (elementContext) {
|
|
73
|
-
var audio = elementContext.querySelector('audio');
|
|
74
|
-
var isInsidePrompt = audio && audio.closest('#preview-prompt'); // only require audio completion if audio exists and is inside the prompt
|
|
75
|
-
|
|
76
|
-
if (audio && isInsidePrompt) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
15
|
+
class Categorize extends HTMLElement {
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
(0, _defineProperty2.default)(this, "_scheduleMathRender", () => {
|
|
19
|
+
if (this._mathRenderPending) return;
|
|
20
|
+
this._mathRenderPending = true;
|
|
21
|
+
requestAnimationFrame(() => {
|
|
22
|
+
if (this._mathObserver && !this._mathObserverPaused) {
|
|
23
|
+
this._mathObserver.disconnect();
|
|
79
24
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
var filledResponseAreas = answers.filter(function (answer) {
|
|
94
|
-
return answer.choices.length;
|
|
95
|
-
}).length; // check if an answer choice was added to at least as many response areas
|
|
96
|
-
// as the number of populated response areas in the correct answer
|
|
97
|
-
|
|
98
|
-
var areResponseAreasFilled = filledResponseAreas >= responseAreasToBeFilled; // check if multiple placements are allowed
|
|
99
|
-
|
|
100
|
-
var duplicatesAllowed = (choices || []).some(function (choice) {
|
|
101
|
-
return choice.categoryCount === 0;
|
|
25
|
+
(0, _mathRendering.renderMath)(this);
|
|
26
|
+
this._mathRenderPending = false;
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
if (this._mathObserver && !this._mathObserverPaused) {
|
|
29
|
+
this._mathObserver.observe(this, {
|
|
30
|
+
childList: true,
|
|
31
|
+
subtree: true,
|
|
32
|
+
characterData: false
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}, 50);
|
|
102
36
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (hasUnplacedChoices) {
|
|
111
|
-
return areResponseAreasFilled;
|
|
37
|
+
});
|
|
38
|
+
(0, _defineProperty2.default)(this, "pauseMathObserver", () => {
|
|
39
|
+
if (this._mathObserver) {
|
|
40
|
+
this._mathObserver.disconnect();
|
|
41
|
+
this._mathObserverPaused = true;
|
|
112
42
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return requiredAnswersPlaced;
|
|
125
|
-
}
|
|
126
|
-
}, {
|
|
127
|
-
key: "session",
|
|
128
|
-
get: function get() {
|
|
129
|
-
return this._session;
|
|
130
|
-
},
|
|
131
|
-
set: function set(s) {
|
|
132
|
-
if (s && !s.answers) {
|
|
133
|
-
s.answers = [];
|
|
43
|
+
});
|
|
44
|
+
(0, _defineProperty2.default)(this, "resumeMathObserver", () => {
|
|
45
|
+
if (this._mathObserverPaused) {
|
|
46
|
+
this._mathObserverPaused = false;
|
|
47
|
+
if (this._mathObserver) {
|
|
48
|
+
this._mathObserver.observe(this, {
|
|
49
|
+
childList: true,
|
|
50
|
+
subtree: true,
|
|
51
|
+
characterData: false
|
|
52
|
+
});
|
|
53
|
+
}
|
|
134
54
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
55
|
+
});
|
|
56
|
+
this._root = null;
|
|
57
|
+
this._mathObserver = null;
|
|
58
|
+
this._mathRenderPending = false;
|
|
59
|
+
}
|
|
60
|
+
_initMathObserver() {
|
|
61
|
+
if (this._mathObserver) return;
|
|
62
|
+
this._mathObserver = new MutationObserver(() => {
|
|
63
|
+
this._scheduleMathRender();
|
|
64
|
+
});
|
|
65
|
+
this._mathObserver.observe(this, {
|
|
66
|
+
childList: true,
|
|
67
|
+
subtree: true,
|
|
68
|
+
characterData: false
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
_disconnectMathObserver() {
|
|
72
|
+
if (this._mathObserver) {
|
|
73
|
+
this._mathObserver.disconnect();
|
|
74
|
+
this._mathObserver = null;
|
|
138
75
|
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (
|
|
162
|
-
|
|
76
|
+
}
|
|
77
|
+
set model(m) {
|
|
78
|
+
this._model = m;
|
|
79
|
+
this.eliminateBlindAnswersFromSession();
|
|
80
|
+
this.dispatchEvent(new _piePlayerEvents.ModelSetEvent(this.tagName.toLowerCase(), this.isComplete(), !!this._model));
|
|
81
|
+
// reset the audioInitialized to false since the model changed, and we might need to reinitialize the audio
|
|
82
|
+
this._audioInitialized = false;
|
|
83
|
+
this.render();
|
|
84
|
+
}
|
|
85
|
+
isComplete() {
|
|
86
|
+
const {
|
|
87
|
+
autoplayAudioEnabled,
|
|
88
|
+
choices,
|
|
89
|
+
completeAudioEnabled,
|
|
90
|
+
hasUnplacedChoices,
|
|
91
|
+
possibleResponses,
|
|
92
|
+
responseAreasToBeFilled
|
|
93
|
+
} = this._model || {};
|
|
94
|
+
const elementContext = this;
|
|
95
|
+
|
|
96
|
+
// check audio completion if audio settings are enabled and audio actually exists
|
|
97
|
+
if (autoplayAudioEnabled && completeAudioEnabled && !this.audioComplete) {
|
|
98
|
+
if (elementContext) {
|
|
99
|
+
const audio = elementContext.querySelector('audio');
|
|
100
|
+
const isInsidePrompt = audio && audio.closest('#preview-prompt');
|
|
101
|
+
|
|
102
|
+
// only require audio completion if audio exists and is inside the prompt
|
|
103
|
+
if (audio && isInsidePrompt) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
163
106
|
}
|
|
164
107
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
value: function changeAnswers(answers) {
|
|
168
|
-
this._session.answers = answers;
|
|
169
|
-
this._session.selector = 'Mouse';
|
|
170
|
-
this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(this.tagName.toLowerCase(), this.isComplete()));
|
|
171
|
-
this.render();
|
|
108
|
+
if (!this._session || !this._session.answers) {
|
|
109
|
+
return false;
|
|
172
110
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
111
|
+
const {
|
|
112
|
+
answers
|
|
113
|
+
} = this._session;
|
|
114
|
+
if (!Array.isArray(answers)) {
|
|
115
|
+
return false;
|
|
177
116
|
}
|
|
178
|
-
}, {
|
|
179
|
-
key: "_createAudioInfoToast",
|
|
180
|
-
value: function _createAudioInfoToast() {
|
|
181
|
-
var info = document.createElement('div');
|
|
182
|
-
info.id = 'play-audio-info';
|
|
183
|
-
Object.assign(info.style, {
|
|
184
|
-
position: 'absolute',
|
|
185
|
-
top: 0,
|
|
186
|
-
width: '100%',
|
|
187
|
-
height: '100%',
|
|
188
|
-
display: 'flex',
|
|
189
|
-
justifyContent: 'center',
|
|
190
|
-
alignItems: 'center',
|
|
191
|
-
background: 'white',
|
|
192
|
-
zIndex: '1000',
|
|
193
|
-
cursor: 'pointer'
|
|
194
|
-
});
|
|
195
|
-
var img = document.createElement('img');
|
|
196
|
-
img.src = _renderUi.EnableAudioAutoplayImage;
|
|
197
|
-
img.alt = 'Click anywhere to enable audio autoplay';
|
|
198
|
-
img.width = 500;
|
|
199
|
-
img.height = 300;
|
|
200
|
-
info.appendChild(img);
|
|
201
|
-
return info;
|
|
202
|
-
}
|
|
203
|
-
}, {
|
|
204
|
-
key: "connectedCallback",
|
|
205
|
-
value: function connectedCallback() {
|
|
206
|
-
var _this = this;
|
|
207
|
-
|
|
208
|
-
// Observation: audio in Chrome will have the autoplay attribute,
|
|
209
|
-
// while other browsers will not have the autoplay attribute and will need a user interaction to play the audio
|
|
210
|
-
// This workaround fixes the issue of audio being cached and played on any user interaction in Safari and Firefox
|
|
211
|
-
var observer = new MutationObserver(function (mutationsList, observer) {
|
|
212
|
-
mutationsList.forEach(function (mutation) {
|
|
213
|
-
if (mutation.type === 'childList') {
|
|
214
|
-
if (_this._audioInitialized) return;
|
|
215
117
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
118
|
+
// filter answers by category and count the ones with content
|
|
119
|
+
const filledResponseAreas = answers.filter(answer => answer.choices.length).length;
|
|
120
|
+
// check if an answer choice was added to at least as many response areas
|
|
121
|
+
// as the number of populated response areas in the correct answer
|
|
122
|
+
const areResponseAreasFilled = filledResponseAreas >= responseAreasToBeFilled;
|
|
123
|
+
// check if multiple placements are allowed
|
|
124
|
+
const duplicatesAllowed = (choices || []).some(choice => choice.categoryCount === 0);
|
|
125
|
+
if (duplicatesAllowed) {
|
|
126
|
+
// an answer choice can be used multiple times
|
|
127
|
+
return areResponseAreasFilled;
|
|
128
|
+
}
|
|
225
129
|
|
|
226
|
-
|
|
130
|
+
// any correct answer have any unplaced answer choices (by the author)
|
|
131
|
+
if (hasUnplacedChoices) {
|
|
132
|
+
return areResponseAreasFilled;
|
|
133
|
+
}
|
|
134
|
+
const allAnswersIds = answers.map(answer => answer.choices).flat();
|
|
227
135
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
audio.play();
|
|
231
|
-
container.removeChild(info);
|
|
232
|
-
}
|
|
136
|
+
// check if any correct answer have any unplaced answer choices (by the student)
|
|
137
|
+
const requiredAnswersPlaced = (possibleResponses || []).some(response => response.every(val => allAnswersIds.includes(val)));
|
|
233
138
|
|
|
139
|
+
// true - all choices (required for a correct response) were placed into a response area
|
|
140
|
+
return requiredAnswersPlaced;
|
|
141
|
+
}
|
|
142
|
+
set session(s) {
|
|
143
|
+
if (s && !s.answers) {
|
|
144
|
+
s.answers = [];
|
|
145
|
+
}
|
|
146
|
+
this._session = s;
|
|
147
|
+
this.render();
|
|
148
|
+
}
|
|
149
|
+
get session() {
|
|
150
|
+
return this._session;
|
|
151
|
+
}
|
|
152
|
+
eliminateBlindAnswersFromSession() {
|
|
153
|
+
const {
|
|
154
|
+
answers = []
|
|
155
|
+
} = this._session || {};
|
|
156
|
+
const {
|
|
157
|
+
choices = []
|
|
158
|
+
} = this._model || {};
|
|
159
|
+
const mappedChoices = choices.map(c => c.id) || [];
|
|
160
|
+
const filteredAnswers = answers.map(answer => {
|
|
161
|
+
const answerChoices = answer?.choices || [];
|
|
162
|
+
answer.choices = answerChoices.filter(c => mappedChoices.includes(c));
|
|
163
|
+
return answer;
|
|
164
|
+
});
|
|
165
|
+
if (filteredAnswers.length > 0) {
|
|
166
|
+
this.changeAnswers(filteredAnswers);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
changeAnswers(answers) {
|
|
170
|
+
this._session.answers = answers;
|
|
171
|
+
this._session.selector = 'Mouse';
|
|
172
|
+
this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(this.tagName.toLowerCase(), this.isComplete()));
|
|
173
|
+
this.render();
|
|
174
|
+
}
|
|
175
|
+
onShowCorrectToggle() {
|
|
176
|
+
(0, _mathRendering.renderMath)(this);
|
|
177
|
+
}
|
|
178
|
+
_createAudioInfoToast() {
|
|
179
|
+
const info = document.createElement('div');
|
|
180
|
+
info.id = 'play-audio-info';
|
|
181
|
+
Object.assign(info.style, {
|
|
182
|
+
position: 'absolute',
|
|
183
|
+
top: 0,
|
|
184
|
+
width: '100%',
|
|
185
|
+
height: '100%',
|
|
186
|
+
display: 'flex',
|
|
187
|
+
justifyContent: 'center',
|
|
188
|
+
alignItems: 'center',
|
|
189
|
+
background: 'white',
|
|
190
|
+
zIndex: '1000',
|
|
191
|
+
cursor: 'pointer'
|
|
192
|
+
});
|
|
193
|
+
const img = document.createElement('img');
|
|
194
|
+
img.src = _renderUi.EnableAudioAutoplayImage;
|
|
195
|
+
img.alt = 'Click anywhere to enable audio autoplay';
|
|
196
|
+
img.width = 500;
|
|
197
|
+
img.height = 300;
|
|
198
|
+
info.appendChild(img);
|
|
199
|
+
return info;
|
|
200
|
+
}
|
|
201
|
+
connectedCallback() {
|
|
202
|
+
this._initMathObserver();
|
|
203
|
+
|
|
204
|
+
// Observation: audio in Chrome will have the autoplay attribute,
|
|
205
|
+
// while other browsers will not have the autoplay attribute and will need a user interaction to play the audio
|
|
206
|
+
// This workaround fixes the issue of audio being cached and played on any user interaction in Safari and Firefox
|
|
207
|
+
const observer = new MutationObserver((mutationsList, observer) => {
|
|
208
|
+
mutationsList.forEach(mutation => {
|
|
209
|
+
if (mutation.type === 'childList') {
|
|
210
|
+
if (this._audioInitialized) return;
|
|
211
|
+
const audio = this.querySelector('audio');
|
|
212
|
+
const isInsidePrompt = audio && audio.closest('#preview-prompt');
|
|
213
|
+
if (!this._model) return;
|
|
214
|
+
if (!this._model.autoplayAudioEnabled) return;
|
|
215
|
+
if (audio && !isInsidePrompt) return;
|
|
216
|
+
if (!audio) return;
|
|
217
|
+
const info = this._createAudioInfoToast();
|
|
218
|
+
const container = this.querySelector('#main-container');
|
|
219
|
+
const enableAudio = () => {
|
|
220
|
+
if (this.querySelector('#play-audio-info')) {
|
|
221
|
+
audio.play();
|
|
222
|
+
container.removeChild(info);
|
|
223
|
+
}
|
|
224
|
+
document.removeEventListener('click', enableAudio);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// if the audio is paused, it means the user has not interacted with the page yet and the audio will not play
|
|
228
|
+
// FIX FOR SAFARI: play with a slight delay to check if autoplay was blocked
|
|
229
|
+
setTimeout(() => {
|
|
230
|
+
if (audio.paused && !this.querySelector('#play-audio-info')) {
|
|
231
|
+
// add info message as a toast to enable audio playback
|
|
232
|
+
container.appendChild(info);
|
|
233
|
+
document.addEventListener('click', enableAudio);
|
|
234
|
+
} else {
|
|
234
235
|
document.removeEventListener('click', enableAudio);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
_this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(_this.tagName.toLowerCase(), _this.isComplete()));
|
|
280
|
-
|
|
281
|
-
audio.removeEventListener('ended', handleEnded);
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
audio.addEventListener('ended', handleEnded); // store references to remove later
|
|
285
|
-
|
|
286
|
-
_this._audio = audio;
|
|
287
|
-
_this._handlePlaying = handlePlaying;
|
|
288
|
-
_this._handleEnded = handleEnded;
|
|
289
|
-
_this._enableAudio = enableAudio; // set to true to prevent multiple initializations
|
|
290
|
-
|
|
291
|
-
_this._audioInitialized = true;
|
|
292
|
-
observer.disconnect();
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
observer.observe(this, {
|
|
297
|
-
childList: true,
|
|
298
|
-
subtree: true
|
|
236
|
+
}
|
|
237
|
+
}, 500);
|
|
238
|
+
|
|
239
|
+
// we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering
|
|
240
|
+
const handlePlaying = () => {
|
|
241
|
+
//timestamp when auto-played audio started playing
|
|
242
|
+
this._session.audioStartTime = this._session.audioStartTime || new Date().getTime();
|
|
243
|
+
const info = this.querySelector('#play-audio-info');
|
|
244
|
+
if (info) {
|
|
245
|
+
container.removeChild(info);
|
|
246
|
+
}
|
|
247
|
+
audio.removeEventListener('playing', handlePlaying);
|
|
248
|
+
};
|
|
249
|
+
audio.addEventListener('playing', handlePlaying);
|
|
250
|
+
|
|
251
|
+
// we need to listen for the ended event to update the isComplete state
|
|
252
|
+
const handleEnded = () => {
|
|
253
|
+
//timestamp when auto-played audio completed playing
|
|
254
|
+
this._session.audioEndTime = this._session.audioEndTime || new Date().getTime();
|
|
255
|
+
let {
|
|
256
|
+
audioStartTime,
|
|
257
|
+
audioEndTime,
|
|
258
|
+
waitTime
|
|
259
|
+
} = this._session;
|
|
260
|
+
if (!waitTime && audioStartTime && audioEndTime) {
|
|
261
|
+
// waitTime is elapsed time the user waited for auto-played audio to finish
|
|
262
|
+
this._session.waitTime = audioEndTime - audioStartTime;
|
|
263
|
+
}
|
|
264
|
+
this.audioComplete = true;
|
|
265
|
+
this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(this.tagName.toLowerCase(), this.isComplete()));
|
|
266
|
+
audio.removeEventListener('ended', handleEnded);
|
|
267
|
+
};
|
|
268
|
+
audio.addEventListener('ended', handleEnded);
|
|
269
|
+
|
|
270
|
+
// store references to remove later
|
|
271
|
+
this._audio = audio;
|
|
272
|
+
this._handlePlaying = handlePlaying;
|
|
273
|
+
this._handleEnded = handleEnded;
|
|
274
|
+
this._enableAudio = enableAudio;
|
|
275
|
+
// set to true to prevent multiple initializations
|
|
276
|
+
this._audioInitialized = true;
|
|
277
|
+
observer.disconnect();
|
|
278
|
+
}
|
|
299
279
|
});
|
|
280
|
+
});
|
|
281
|
+
observer.observe(this, {
|
|
282
|
+
childList: true,
|
|
283
|
+
subtree: true
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
disconnectedCallback() {
|
|
287
|
+
this._disconnectMathObserver();
|
|
288
|
+
document.removeEventListener('click', this._enableAudio);
|
|
289
|
+
if (this._audio) {
|
|
290
|
+
this._audio.removeEventListener('playing', this._handlePlaying);
|
|
291
|
+
this._audio.removeEventListener('ended', this._handleEnded);
|
|
292
|
+
this._audio = null;
|
|
300
293
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
value: function disconnectedCallback() {
|
|
304
|
-
document.removeEventListener('click', this._enableAudio);
|
|
305
|
-
|
|
306
|
-
if (this._audio) {
|
|
307
|
-
this._audio.removeEventListener('playing', this._handlePlaying);
|
|
308
|
-
|
|
309
|
-
this._audio.removeEventListener('ended', this._handleEnded);
|
|
310
|
-
|
|
311
|
-
this._audio = null;
|
|
312
|
-
}
|
|
294
|
+
if (this._root) {
|
|
295
|
+
this._root.unmount();
|
|
313
296
|
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
_reactDom["default"].render(el, this, function () {
|
|
328
|
-
(0, _mathRendering.renderMath)(_this2);
|
|
329
|
-
});
|
|
297
|
+
}
|
|
298
|
+
render() {
|
|
299
|
+
if (this._model && this._session) {
|
|
300
|
+
const el = /*#__PURE__*/_react.default.createElement(_categorize.default, {
|
|
301
|
+
model: this._model,
|
|
302
|
+
session: this._session,
|
|
303
|
+
onAnswersChange: this.changeAnswers.bind(this),
|
|
304
|
+
onShowCorrectToggle: this.onShowCorrectToggle.bind(this),
|
|
305
|
+
pauseMathObserver: this.pauseMathObserver,
|
|
306
|
+
resumeMathObserver: this.resumeMathObserver
|
|
307
|
+
});
|
|
308
|
+
if (!this._root) {
|
|
309
|
+
this._root = (0, _client.createRoot)(this);
|
|
330
310
|
}
|
|
311
|
+
this._root.render(el);
|
|
331
312
|
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
exports["default"] = Categorize;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
exports.default = Categorize;
|
|
337
316
|
//# sourceMappingURL=index.js.map
|