@pie-element/ebsr 7.0.24-next.1 → 7.0.24-next.2
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 +125 -0
- package/configure/lib/defaults.js.map +1 -0
- package/configure/lib/index.js +207 -0
- package/configure/lib/index.js.map +1 -0
- package/configure/lib/main.js +284 -0
- package/configure/lib/main.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.json +1972 -0
- package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.md +1793 -0
- package/configure/node_modules/@pie-element/multiple-choice/LICENSE.md +5 -0
- package/configure/node_modules/@pie-element/multiple-choice/PRINT.md +35 -0
- package/configure/node_modules/@pie-element/multiple-choice/README.md +56 -0
- package/configure/node_modules/@pie-element/multiple-choice/choice.png +0 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.json +1387 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.md +1334 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js +104 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js +198 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js +599 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js +18 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/package.json +20 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.json +527 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.md +768 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js +18 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js +305 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js +36 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/package.json +15 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json +353 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json.md +277 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/config.js +8 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/generate.js +52 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/index.html +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/session.js +7 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json +338 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json.md +274 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js +298 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js +157 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js +174 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/index.js +151 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/main.js +97 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/main.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js +254 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/print.js +129 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/print.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js +35 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/configure.js +843 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/controller.js +20686 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/demo.js +77 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/element.js +2019 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/index.html +21 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/manifest.json +14 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/print-demo.js +115 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/print.html +18 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/print.js +1983 -0
- package/configure/node_modules/@pie-element/multiple-choice/package.json +34 -0
- package/configure/node_modules/@pie-lib/math-rendering/CHANGELOG.json +672 -0
- package/configure/node_modules/@pie-lib/math-rendering/CHANGELOG.md +427 -0
- package/configure/node_modules/@pie-lib/math-rendering/LICENSE.md +5 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/index.js +30 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/chtml.js +316 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/chtml.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/index.js +23 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/mml.js +123 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/mml.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/normalization.js +103 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/normalization.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/render-math.js +275 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/render-math.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/package.json +19 -0
- package/configure/node_modules/@pie-lib/math-rendering/playground/demo.html +872 -0
- package/configure/node_modules/@pie-lib/math-rendering/playground/demo.js +108 -0
- package/configure/node_modules/@pie-lib/math-rendering/playground/main.html +156 -0
- package/configure/node_modules/@pie-lib/math-rendering/playground/main.js +16 -0
- package/configure/node_modules/@pie-lib/math-rendering/playground/webpack.config.js +29 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/index.js +4 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/mstack/chtml.js +215 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/mstack/index.js +13 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/mstack/mml.js +24 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/normalization.js +69 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/render-math.js +234 -0
- package/configure/node_modules/@pie-lib/render-ui/CHANGELOG.json +937 -0
- package/configure/node_modules/@pie-lib/render-ui/CHANGELOG.md +602 -0
- package/configure/node_modules/@pie-lib/render-ui/LICENSE.md +5 -0
- package/configure/node_modules/@pie-lib/render-ui/README.md +33 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/collapsible/index.js +146 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/collapsible/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/color.js +134 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/color.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/feedback.js +160 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/feedback.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/has-text.js +24 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/has-text.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/html-and-math.js +102 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/html-and-math.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/index.js +104 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/input-container.js +60 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/input-container.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/preview-layout.js +133 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/preview-layout.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/preview-prompt.js +162 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/preview-prompt.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/purpose.js +28 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/purpose.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/readable.js +28 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/readable.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/response-indicators.js +160 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/response-indicators.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/withUndoReset.js +206 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/withUndoReset.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/package.json +30 -0
- package/configure/node_modules/@pie-lib/render-ui/src/collapsible/index.jsx +68 -0
- package/configure/node_modules/@pie-lib/render-ui/src/color.js +48 -0
- package/configure/node_modules/@pie-lib/render-ui/src/feedback.jsx +100 -0
- package/configure/node_modules/@pie-lib/render-ui/src/has-text.js +14 -0
- package/configure/node_modules/@pie-lib/render-ui/src/html-and-math.js +40 -0
- package/configure/node_modules/@pie-lib/render-ui/src/index.js +27 -0
- package/configure/node_modules/@pie-lib/render-ui/src/input-container.jsx +41 -0
- package/configure/node_modules/@pie-lib/render-ui/src/preview-layout.jsx +77 -0
- package/configure/node_modules/@pie-lib/render-ui/src/preview-prompt.jsx +90 -0
- package/configure/node_modules/@pie-lib/render-ui/src/purpose.jsx +19 -0
- package/configure/node_modules/@pie-lib/render-ui/src/readable.jsx +19 -0
- package/configure/node_modules/@pie-lib/render-ui/src/response-indicators.jsx +89 -0
- package/configure/node_modules/@pie-lib/render-ui/src/withUndoReset.jsx +118 -0
- package/controller/lib/defaults.js +28 -0
- package/controller/lib/defaults.js.map +1 -0
- package/controller/lib/index.js +471 -0
- package/controller/lib/index.js.map +1 -0
- package/controller/lib/utils.js +33 -0
- package/controller/lib/utils.js.map +1 -0
- package/lib/index.js +202 -0
- package/lib/index.js.map +1 -0
- package/lib/print.js +243 -0
- package/lib/print.js.map +1 -0
- package/package.json +1 -1
package/lib/index.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.isSessionComplete = exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
11
|
+
|
|
12
|
+
var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
+
|
|
18
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
19
|
+
|
|
20
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
+
|
|
22
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
23
|
+
|
|
24
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
25
|
+
|
|
26
|
+
var _piePlayerEvents = require("@pie-framework/pie-player-events");
|
|
27
|
+
|
|
28
|
+
var _multipleChoice = _interopRequireDefault(require("@pie-element/multiple-choice"));
|
|
29
|
+
|
|
30
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
31
|
+
|
|
32
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
33
|
+
|
|
34
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
35
|
+
|
|
36
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
37
|
+
|
|
38
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
39
|
+
|
|
40
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
41
|
+
|
|
42
|
+
var SESSION_CHANGED = _piePlayerEvents.SessionChangedEvent.TYPE;
|
|
43
|
+
var MC_TAG_NAME = 'ebsr-multiple-choice';
|
|
44
|
+
var log = (0, _debug["default"])('pie-elements:ebsr');
|
|
45
|
+
|
|
46
|
+
var EbsrMC = /*#__PURE__*/function (_MultipleChoice) {
|
|
47
|
+
(0, _inherits2["default"])(EbsrMC, _MultipleChoice);
|
|
48
|
+
|
|
49
|
+
var _super = _createSuper(EbsrMC);
|
|
50
|
+
|
|
51
|
+
function EbsrMC() {
|
|
52
|
+
(0, _classCallCheck2["default"])(this, EbsrMC);
|
|
53
|
+
return _super.apply(this, arguments);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (0, _createClass2["default"])(EbsrMC);
|
|
57
|
+
}(_multipleChoice["default"]);
|
|
58
|
+
|
|
59
|
+
var defineMultipleChoice = function defineMultipleChoice() {
|
|
60
|
+
if (!customElements.get(MC_TAG_NAME)) {
|
|
61
|
+
customElements.define(MC_TAG_NAME, EbsrMC);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
defineMultipleChoice();
|
|
66
|
+
|
|
67
|
+
var isNonEmptyArray = function isNonEmptyArray(a) {
|
|
68
|
+
return Array.isArray(a) && a.length > 0;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
var isSessionComplete = function isSessionComplete(session) {
|
|
72
|
+
var a = (0, _get["default"])(session, 'value.partA.value');
|
|
73
|
+
var b = (0, _get["default"])(session, 'value.partB.value');
|
|
74
|
+
return isNonEmptyArray(a) && isNonEmptyArray(b);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
exports.isSessionComplete = isSessionComplete;
|
|
78
|
+
|
|
79
|
+
var Ebsr = /*#__PURE__*/function (_HTMLElement) {
|
|
80
|
+
(0, _inherits2["default"])(Ebsr, _HTMLElement);
|
|
81
|
+
|
|
82
|
+
var _super2 = _createSuper(Ebsr);
|
|
83
|
+
|
|
84
|
+
function Ebsr() {
|
|
85
|
+
var _this;
|
|
86
|
+
|
|
87
|
+
(0, _classCallCheck2["default"])(this, Ebsr);
|
|
88
|
+
_this = _super2.call(this);
|
|
89
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onSessionUpdated", function (e) {
|
|
90
|
+
if (e.target === (0, _assertThisInitialized2["default"])(_this)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
e.stopImmediatePropagation();
|
|
96
|
+
var id = e.target.getAttribute('id');
|
|
97
|
+
|
|
98
|
+
if (id) {
|
|
99
|
+
var key = "part".concat(id.toUpperCase());
|
|
100
|
+
|
|
101
|
+
if (e.update) {
|
|
102
|
+
_this._model[key] = e.update;
|
|
103
|
+
} //TODO: accessing a private property here. The session event should contain the update in future to prevent this.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
_this.dispatchSessionChanged(e.srcElement._session, key);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
_this._model = {};
|
|
110
|
+
_this._session = {};
|
|
111
|
+
return _this;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
(0, _createClass2["default"])(Ebsr, [{
|
|
115
|
+
key: "model",
|
|
116
|
+
set: function set(m) {
|
|
117
|
+
var _this2 = this;
|
|
118
|
+
|
|
119
|
+
this._model = m;
|
|
120
|
+
customElements.whenDefined(MC_TAG_NAME).then(function () {
|
|
121
|
+
_this2.setPartModel(_this2.partA, 'partA');
|
|
122
|
+
|
|
123
|
+
_this2.setPartModel(_this2.partB, 'partB');
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
127
|
+
key: "session",
|
|
128
|
+
get: function get() {
|
|
129
|
+
return this._session;
|
|
130
|
+
},
|
|
131
|
+
set: function set(s) {
|
|
132
|
+
var _this3 = this;
|
|
133
|
+
|
|
134
|
+
this._session = s;
|
|
135
|
+
customElements.whenDefined(MC_TAG_NAME).then(function () {
|
|
136
|
+
_this3.setPartSession(_this3.partA, 'partA');
|
|
137
|
+
|
|
138
|
+
_this3.setPartSession(_this3.partB, 'partB');
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}, {
|
|
142
|
+
key: "setPartModel",
|
|
143
|
+
value: function setPartModel(part, key) {
|
|
144
|
+
if (this._model && this._model[key]) {
|
|
145
|
+
var mode = this._model.mode;
|
|
146
|
+
part.model = _objectSpread(_objectSpread({}, this._model[key]), {}, {
|
|
147
|
+
mode: mode,
|
|
148
|
+
keyMode: this._model[key].choicePrefix
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}, {
|
|
153
|
+
key: "setPartSession",
|
|
154
|
+
value: function setPartSession(part, key) {
|
|
155
|
+
if (this._session && this._model) {
|
|
156
|
+
var value = this._session.value;
|
|
157
|
+
part.session = value && value[key] ? value[key] : {
|
|
158
|
+
id: key
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}, {
|
|
163
|
+
key: "dispatchSessionChanged",
|
|
164
|
+
value: function dispatchSessionChanged(partSession, key) {
|
|
165
|
+
this._session.value = _objectSpread(_objectSpread({}, this._session.value), {}, (0, _defineProperty2["default"])({}, key, partSession));
|
|
166
|
+
log('[onSessionChanged] session: ', this._session);
|
|
167
|
+
var complete = isSessionComplete(this._session);
|
|
168
|
+
this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(this.tagName.toLowerCase(), complete));
|
|
169
|
+
}
|
|
170
|
+
}, {
|
|
171
|
+
key: "partA",
|
|
172
|
+
get: function get() {
|
|
173
|
+
return this.querySelector("".concat(MC_TAG_NAME, "#a"));
|
|
174
|
+
}
|
|
175
|
+
}, {
|
|
176
|
+
key: "partB",
|
|
177
|
+
get: function get() {
|
|
178
|
+
return this.querySelector("".concat(MC_TAG_NAME, "#b"));
|
|
179
|
+
}
|
|
180
|
+
}, {
|
|
181
|
+
key: "connectedCallback",
|
|
182
|
+
value: function connectedCallback() {
|
|
183
|
+
this._render();
|
|
184
|
+
|
|
185
|
+
this.addEventListener(SESSION_CHANGED, this.onSessionUpdated);
|
|
186
|
+
}
|
|
187
|
+
}, {
|
|
188
|
+
key: "disconnectedCallback",
|
|
189
|
+
value: function disconnectedCallback() {
|
|
190
|
+
this.removeEventListener(SESSION_CHANGED, this.onSessionUpdated);
|
|
191
|
+
}
|
|
192
|
+
}, {
|
|
193
|
+
key: "_render",
|
|
194
|
+
value: function _render() {
|
|
195
|
+
this.innerHTML = "\n <div>\n <".concat(MC_TAG_NAME, " id=\"a\"></").concat(MC_TAG_NAME, ">\n <").concat(MC_TAG_NAME, " id=\"b\"></").concat(MC_TAG_NAME, ">\n </div>\n ");
|
|
196
|
+
}
|
|
197
|
+
}]);
|
|
198
|
+
return Ebsr;
|
|
199
|
+
}( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));
|
|
200
|
+
|
|
201
|
+
exports["default"] = Ebsr;
|
|
202
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["SESSION_CHANGED","SessionChangedEvent","TYPE","MC_TAG_NAME","log","EbsrMC","MultipleChoice","defineMultipleChoice","customElements","get","define","isNonEmptyArray","a","Array","isArray","length","isSessionComplete","session","b","Ebsr","e","target","preventDefault","stopImmediatePropagation","id","getAttribute","key","toUpperCase","update","_model","dispatchSessionChanged","srcElement","_session","m","whenDefined","then","setPartModel","partA","partB","s","setPartSession","part","mode","model","keyMode","choicePrefix","value","partSession","complete","dispatchEvent","tagName","toLowerCase","querySelector","_render","addEventListener","onSessionUpdated","removeEventListener","innerHTML","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;;;AACA,IAAMA,eAAe,GAAGC,qCAAoBC,IAA5C;AACA,IAAMC,WAAW,GAAG,sBAApB;AACA,IAAMC,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A1B,EAAkC;AAChC,YAAQiB,KAAR,GAAkB,KAAKd,QAAvB,CAAQc,KAAR;AACAL,QAAAA,IAAI,CAACxB,OAAL,GAAe6B,KAAK,IAAIA,KAAK,CAACpB,GAAD,CAAd,GAAsBoB,KAAK,CAACpB,GAAD,CAA3B,GAAmC;AAAEF,UAAAA,EAAE,EAAEE;AAAN,SAAlD;AACD;AACF;;;WAED,gCAAuBqB,WAAvB,EAAoCrB,GAApC,EAAyC;AACvC,WAAKM,QAAL,CAAcc,KAAd,mCACK,KAAKd,QAAL,CAAcc,KADnB,4CAEGpB,GAFH,EAESqB,WAFT;AAKA3C,MAAAA,GAAG,CAAC,8BAAD,EAAiC,KAAK4B,QAAtC,CAAH;AACA,UAAMgB,QAAQ,GAAGhC,iBAAiB,CAAC,KAAKgB,QAAN,CAAlC;AACA,WAAKiB,aAAL,CACE,IAAIhD,oCAAJ,CAAwB,KAAKiD,OAAL,CAAaC,WAAb,EAAxB,EAAoDH,QAApD,CADF;AAGD;;;SAED,eAAY;AACV,aAAO,KAAKI,aAAL,WAAsBjD,WAAtB,QAAP;AACD;;;SAED,eAAY;AACV,aAAO,KAAKiD,aAAL,WAAsBjD,WAAtB,QAAP;AACD;;;WAED,6BAAoB;AAClB,WAAKkD,OAAL;;AACA,WAAKC,gBAAL,CAAsBtD,eAAtB,EAAuC,KAAKuD,gBAA5C;AACD;;;WAED,gCAAuB;AACrB,WAAKC,mBAAL,CAAyBxD,eAAzB,EAA0C,KAAKuD,gBAA/C;AACD;;;WAED,mBAAU;AACR,WAAKE,SAAL,qCAEOtD,WAFP,yBAE+BA,WAF/B,yBAGOA,WAHP,yBAG+BA,WAH/B;AAMD;;;kDA1G+BuD,W","sourcesContent":["import { SessionChangedEvent } from '@pie-framework/pie-player-events';\nimport MultipleChoice from '@pie-element/multiple-choice';\nimport get from 'lodash/get';\nimport debug from 'debug';\nconst SESSION_CHANGED = SessionChangedEvent.TYPE;\nconst MC_TAG_NAME = 'ebsr-multiple-choice';\nconst log = debug('pie-elements:ebsr');\n\nclass EbsrMC extends MultipleChoice {}\n\nconst defineMultipleChoice = () => {\n if (!customElements.get(MC_TAG_NAME)) {\n customElements.define(MC_TAG_NAME, EbsrMC);\n }\n};\n\ndefineMultipleChoice();\n\nconst isNonEmptyArray = (a) => Array.isArray(a) && a.length > 0;\n\nexport const isSessionComplete = (session) => {\n const a = get(session, 'value.partA.value');\n const b = get(session, 'value.partB.value');\n\n return isNonEmptyArray(a) && isNonEmptyArray(b);\n};\n\nexport default class Ebsr extends HTMLElement {\n constructor() {\n super();\n this._model = {};\n this._session = {};\n }\n\n onSessionUpdated = (e) => {\n if (e.target === this) {\n return;\n }\n\n e.preventDefault();\n e.stopImmediatePropagation();\n\n const id = e.target.getAttribute('id');\n\n if (id) {\n const key = `part${id.toUpperCase()}`;\n\n if (e.update) {\n this._model[key] = e.update;\n }\n //TODO: accessing a private property here. The session event should contain the update in future to prevent this.\n this.dispatchSessionChanged(e.srcElement._session, key);\n }\n };\n\n set model(m) {\n this._model = m;\n\n customElements.whenDefined(MC_TAG_NAME).then(() => {\n this.setPartModel(this.partA, 'partA');\n this.setPartModel(this.partB, 'partB');\n });\n }\n\n set session(s) {\n this._session = s;\n\n customElements.whenDefined(MC_TAG_NAME).then(() => {\n this.setPartSession(this.partA, 'partA');\n this.setPartSession(this.partB, 'partB');\n });\n }\n\n get session() {\n return this._session;\n }\n\n setPartModel(part, key) {\n if (this._model && this._model[key]) {\n const { mode } = this._model;\n\n part.model = {\n ...this._model[key],\n mode,\n keyMode: this._model[key].choicePrefix,\n };\n }\n }\n\n setPartSession(part, key) {\n if (this._session && this._model) {\n const { value } = this._session;\n part.session = value && value[key] ? value[key] : { id: key };\n }\n }\n\n dispatchSessionChanged(partSession, key) {\n this._session.value = {\n ...this._session.value,\n [key]: partSession,\n };\n\n log('[onSessionChanged] session: ', this._session);\n const complete = isSessionComplete(this._session);\n this.dispatchEvent(\n new SessionChangedEvent(this.tagName.toLowerCase(), complete)\n );\n }\n\n get partA() {\n return this.querySelector(`${MC_TAG_NAME}#a`);\n }\n\n get partB() {\n return this.querySelector(`${MC_TAG_NAME}#b`);\n }\n\n connectedCallback() {\n this._render();\n this.addEventListener(SESSION_CHANGED, this.onSessionUpdated);\n }\n\n disconnectedCallback() {\n this.removeEventListener(SESSION_CHANGED, this.onSessionUpdated);\n }\n\n _render() {\n this.innerHTML = `\n <div>\n <${MC_TAG_NAME} id=\"a\"></${MC_TAG_NAME}>\n <${MC_TAG_NAME} id=\"b\"></${MC_TAG_NAME}>\n </div>\n `;\n }\n}\n"],"file":"index.js"}
|
package/lib/print.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.isSessionComplete = exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
11
|
+
|
|
12
|
+
var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
+
|
|
18
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
19
|
+
|
|
20
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
21
|
+
|
|
22
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
23
|
+
|
|
24
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
25
|
+
|
|
26
|
+
var _react = _interopRequireDefault(require("react"));
|
|
27
|
+
|
|
28
|
+
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
29
|
+
|
|
30
|
+
var _multipleChoice = _interopRequireDefault(require("@pie-element/multiple-choice"));
|
|
31
|
+
|
|
32
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
33
|
+
|
|
34
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
35
|
+
|
|
36
|
+
var _piePlayerEvents = require("@pie-framework/pie-player-events");
|
|
37
|
+
|
|
38
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
39
|
+
|
|
40
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
41
|
+
|
|
42
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
43
|
+
|
|
44
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
45
|
+
|
|
46
|
+
var MC_TAG_NAME = 'ebsr-multiple-choice';
|
|
47
|
+
var SESSION_CHANGED = _piePlayerEvents.SessionChangedEvent.TYPE;
|
|
48
|
+
var log = (0, _debug["default"])('pie-element:ebsr:print');
|
|
49
|
+
/**
|
|
50
|
+
* Live in same package as main element - so we can access some of the shared comps!
|
|
51
|
+
*
|
|
52
|
+
* - update pslb to build print if src/print.js is there
|
|
53
|
+
* - update demo el
|
|
54
|
+
* - get configure/controller building
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
var preparePrintModel = function preparePrintModel(model, opts) {
|
|
58
|
+
var instr = opts.role === 'instructor';
|
|
59
|
+
model.prompt = model.promptEnabled !== false ? model.prompt : undefined;
|
|
60
|
+
model.teacherInstructions = instr && model.teacherInstructionsEnabled !== false ? model.teacherInstructions : undefined;
|
|
61
|
+
model.showTeacherInstructions = instr;
|
|
62
|
+
model.alwaysShowCorrect = instr;
|
|
63
|
+
model.mode = instr ? 'evaluate' : 'gather';
|
|
64
|
+
model.disabled = true;
|
|
65
|
+
model.animationsDisabled = true;
|
|
66
|
+
model.lockChoiceOrder = true;
|
|
67
|
+
model.choicesLayout = model.choicesLayout || 'vertical';
|
|
68
|
+
var choices = (0, _cloneDeep["default"])(model.choices);
|
|
69
|
+
model.choices = choices.map(function (c) {
|
|
70
|
+
c.rationale = instr && model.rationaleEnabled !== false ? c.rationale : undefined;
|
|
71
|
+
c.hideTick = instr;
|
|
72
|
+
c.feedback = undefined;
|
|
73
|
+
return c;
|
|
74
|
+
});
|
|
75
|
+
model.keyMode = model.choicePrefix || 'letters';
|
|
76
|
+
return model;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
var EbsrMC = /*#__PURE__*/function (_MultipleChoice) {
|
|
80
|
+
(0, _inherits2["default"])(EbsrMC, _MultipleChoice);
|
|
81
|
+
|
|
82
|
+
var _super = _createSuper(EbsrMC);
|
|
83
|
+
|
|
84
|
+
function EbsrMC() {
|
|
85
|
+
(0, _classCallCheck2["default"])(this, EbsrMC);
|
|
86
|
+
return _super.apply(this, arguments);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (0, _createClass2["default"])(EbsrMC);
|
|
90
|
+
}(_multipleChoice["default"]);
|
|
91
|
+
|
|
92
|
+
var defineMultipleChoice = function defineMultipleChoice() {
|
|
93
|
+
if (!customElements.get(MC_TAG_NAME)) {
|
|
94
|
+
customElements.define(MC_TAG_NAME, EbsrMC);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
defineMultipleChoice();
|
|
99
|
+
|
|
100
|
+
var isNonEmptyArray = function isNonEmptyArray(a) {
|
|
101
|
+
return Array.isArray(a) && a.length > 0;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
var isSessionComplete = function isSessionComplete(session) {
|
|
105
|
+
var a = (0, _get["default"])(session, 'value.partA.value');
|
|
106
|
+
var b = (0, _get["default"])(session, 'value.partB.value');
|
|
107
|
+
return isNonEmptyArray(a) && isNonEmptyArray(b);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
exports.isSessionComplete = isSessionComplete;
|
|
111
|
+
|
|
112
|
+
var Ebsr = /*#__PURE__*/function (_HTMLElement) {
|
|
113
|
+
(0, _inherits2["default"])(Ebsr, _HTMLElement);
|
|
114
|
+
|
|
115
|
+
var _super2 = _createSuper(Ebsr);
|
|
116
|
+
|
|
117
|
+
function Ebsr() {
|
|
118
|
+
var _this;
|
|
119
|
+
|
|
120
|
+
(0, _classCallCheck2["default"])(this, Ebsr);
|
|
121
|
+
_this = _super2.call(this);
|
|
122
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onSessionUpdated", function (e) {
|
|
123
|
+
if (e.target === (0, _assertThisInitialized2["default"])(_this)) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
e.stopImmediatePropagation();
|
|
129
|
+
var id = e.target.getAttribute('id');
|
|
130
|
+
|
|
131
|
+
if (id) {
|
|
132
|
+
var key = "part".concat(id.toUpperCase());
|
|
133
|
+
|
|
134
|
+
if (e.update) {
|
|
135
|
+
_this._model[key] = e.update;
|
|
136
|
+
} //TODO: accessing a private property here. The session event should contain the update in future to prevent this.
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
_this.dispatchSessionChanged(e.srcElement._session, key);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
_this._model = {};
|
|
143
|
+
_this._session = {};
|
|
144
|
+
_this._options = null;
|
|
145
|
+
return _this;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
(0, _createClass2["default"])(Ebsr, [{
|
|
149
|
+
key: "model",
|
|
150
|
+
set: function set(m) {
|
|
151
|
+
var _this2 = this;
|
|
152
|
+
|
|
153
|
+
this._model = m;
|
|
154
|
+
customElements.whenDefined(MC_TAG_NAME).then(function () {
|
|
155
|
+
_this2.setPartModel(_this2.partA, 'partA');
|
|
156
|
+
|
|
157
|
+
_this2.setPartModel(_this2.partB, 'partB');
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}, {
|
|
161
|
+
key: "session",
|
|
162
|
+
set: function set(s) {
|
|
163
|
+
var _this3 = this;
|
|
164
|
+
|
|
165
|
+
this._session = s;
|
|
166
|
+
customElements.whenDefined(MC_TAG_NAME).then(function () {
|
|
167
|
+
_this3.setPartSession(_this3.partA, 'partA');
|
|
168
|
+
|
|
169
|
+
_this3.setPartSession(_this3.partB, 'partB');
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}, {
|
|
173
|
+
key: "setPartModel",
|
|
174
|
+
value: function setPartModel(part, key) {
|
|
175
|
+
if (this._model && this._model[key]) {
|
|
176
|
+
part.model = _objectSpread(_objectSpread({}, preparePrintModel(this._model[key], this._options)), {}, {
|
|
177
|
+
keyMode: this._model[key].choicePrefix
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
if (!part._session) {
|
|
181
|
+
// for print, "set session" is not called,
|
|
182
|
+
// but ebsr needs sessions in order to render the elements,
|
|
183
|
+
// so we set it here it was not set already
|
|
184
|
+
part.session = {};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}, {
|
|
189
|
+
key: "options",
|
|
190
|
+
set: function set(o) {
|
|
191
|
+
this._options = o;
|
|
192
|
+
}
|
|
193
|
+
}, {
|
|
194
|
+
key: "setPartSession",
|
|
195
|
+
value: function setPartSession(part, key) {
|
|
196
|
+
if (this._session && this._model) {
|
|
197
|
+
var value = this._session.value;
|
|
198
|
+
part.session = value && value[key] ? value[key] : {
|
|
199
|
+
id: key
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}, {
|
|
204
|
+
key: "dispatchSessionChanged",
|
|
205
|
+
value: function dispatchSessionChanged(partSession, key) {
|
|
206
|
+
this._session.value = _objectSpread(_objectSpread({}, this._session.value), {}, (0, _defineProperty2["default"])({}, key, partSession));
|
|
207
|
+
log('[onSessionChanged] session: ', this._session);
|
|
208
|
+
var complete = isSessionComplete(this._session);
|
|
209
|
+
this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(this.tagName.toLowerCase(), complete));
|
|
210
|
+
}
|
|
211
|
+
}, {
|
|
212
|
+
key: "partA",
|
|
213
|
+
get: function get() {
|
|
214
|
+
return this.querySelector("".concat(MC_TAG_NAME, "#a"));
|
|
215
|
+
}
|
|
216
|
+
}, {
|
|
217
|
+
key: "partB",
|
|
218
|
+
get: function get() {
|
|
219
|
+
return this.querySelector("".concat(MC_TAG_NAME, "#b"));
|
|
220
|
+
}
|
|
221
|
+
}, {
|
|
222
|
+
key: "connectedCallback",
|
|
223
|
+
value: function connectedCallback() {
|
|
224
|
+
this._render();
|
|
225
|
+
|
|
226
|
+
this.addEventListener(SESSION_CHANGED, this.onSessionUpdated);
|
|
227
|
+
}
|
|
228
|
+
}, {
|
|
229
|
+
key: "disconnectedCallback",
|
|
230
|
+
value: function disconnectedCallback() {
|
|
231
|
+
this.removeEventListener(SESSION_CHANGED, this.onSessionUpdated);
|
|
232
|
+
}
|
|
233
|
+
}, {
|
|
234
|
+
key: "_render",
|
|
235
|
+
value: function _render() {
|
|
236
|
+
this.innerHTML = "\n <div>\n <".concat(MC_TAG_NAME, " id=\"a\"></").concat(MC_TAG_NAME, ">\n <").concat(MC_TAG_NAME, " id=\"b\"></").concat(MC_TAG_NAME, ">\n </div>\n ");
|
|
237
|
+
}
|
|
238
|
+
}]);
|
|
239
|
+
return Ebsr;
|
|
240
|
+
}( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));
|
|
241
|
+
|
|
242
|
+
exports["default"] = Ebsr;
|
|
243
|
+
//# sourceMappingURL=print.js.map
|
package/lib/print.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/print.js"],"names":["MC_TAG_NAME","SESSION_CHANGED","SessionChangedEvent","TYPE","log","preparePrintModel","model","opts","instr","role","prompt","promptEnabled","undefined","teacherInstructions","teacherInstructionsEnabled","showTeacherInstructions","alwaysShowCorrect","mode","disabled","animationsDisabled","lockChoiceOrder","choicesLayout","choices","map","c","rationale","rationaleEnabled","hideTick","feedback","keyMode","choicePrefix","EbsrMC","MultipleChoice","defineMultipleChoice","customElements","get","define","isNonEmptyArray","a","Array","isArray","length","isSessionComplete","session","b","Ebsr","e","target","preventDefault","stopImmediatePropagation","id","getAttribute","key","toUpperCase","update","_model","dispatchSessionChanged","srcElement","_session","_options","m","whenDefined","then","setPartModel","partA","partB","s","setPartSession","part","o","value","partSession","complete","dispatchEvent","tagName","toLowerCase","querySelector","_render","addEventListener","onSessionUpdated","removeEventListener","innerHTML","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;;;;;AACA,IAAMA,WAAW,GAAG,sB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AKE,SAAL,qCAEOjF,WAFP,yBAE+BA,WAF/B,yBAGOA,WAHP,yBAG+BA,WAH/B;AAMD;;;kDAhH+BkF,W","sourcesContent":["import React from 'react';\nimport cloneDeep from 'lodash/cloneDeep';\nimport MultipleChoice from '@pie-element/multiple-choice';\nimport debug from 'debug';\nimport get from 'lodash/get';\n\nimport {SessionChangedEvent} from '@pie-framework/pie-player-events';\nconst MC_TAG_NAME = 'ebsr-multiple-choice';\nconst SESSION_CHANGED = SessionChangedEvent.TYPE;\n\nconst log = debug('pie-element:ebsr:print');\n\n/**\n * Live in same package as main element - so we can access some of the shared comps!\n *\n * - update pslb to build print if src/print.js is there\n * - update demo el\n * - get configure/controller building\n */\n\nconst preparePrintModel = (model, opts) => {\n const instr = opts.role === 'instructor';\n\n model.prompt = model.promptEnabled !== false ? model.prompt : undefined;\n model.teacherInstructions = instr && model.teacherInstructionsEnabled !== false ? model.teacherInstructions : undefined;\n model.showTeacherInstructions = instr;\n model.alwaysShowCorrect = instr;\n model.mode = instr ? 'evaluate' : 'gather';\n\n model.disabled = true;\n model.animationsDisabled = true;\n model.lockChoiceOrder = true;\n model.choicesLayout = model.choicesLayout || 'vertical';\n\n const choices = cloneDeep(model.choices);\n\n model.choices = choices.map((c) => {\n c.rationale = instr && model.rationaleEnabled !== false ? c.rationale : undefined;\n c.hideTick = instr;\n c.feedback = undefined;\n return c;\n });\n\n model.keyMode = model.choicePrefix || 'letters';\n\n return model;\n};\n\nclass EbsrMC extends MultipleChoice {}\n\nconst defineMultipleChoice = () => {\n if (!customElements.get(MC_TAG_NAME)) {\n customElements.define(MC_TAG_NAME, EbsrMC);\n }\n};\n\ndefineMultipleChoice();\n\nconst isNonEmptyArray = (a) => Array.isArray(a) && a.length > 0;\n\nexport const isSessionComplete = (session) => {\n const a = get(session, 'value.partA.value');\n const b = get(session, 'value.partB.value');\n\n return isNonEmptyArray(a) && isNonEmptyArray(b);\n};\n\nexport default class Ebsr extends HTMLElement {\n constructor() {\n super();\n this._model = {};\n this._session = {};\n this._options = null;\n }\n\n onSessionUpdated = (e) => {\n if (e.target === this) {\n return;\n }\n\n e.preventDefault();\n e.stopImmediatePropagation();\n\n const id = e.target.getAttribute('id');\n\n if (id) {\n const key = `part${id.toUpperCase()}`;\n\n if (e.update) {\n this._model[key] = e.update;\n }\n //TODO: accessing a private property here. The session event should contain the update in future to prevent this.\n this.dispatchSessionChanged(e.srcElement._session, key);\n }\n };\n\n set model(m) {\n this._model = m;\n\n customElements.whenDefined(MC_TAG_NAME).then(() => {\n this.setPartModel(this.partA, 'partA');\n this.setPartModel(this.partB, 'partB');\n });\n }\n\n set session(s) {\n this._session = s;\n\n customElements.whenDefined(MC_TAG_NAME).then(() => {\n this.setPartSession(this.partA, 'partA');\n this.setPartSession(this.partB, 'partB');\n });\n }\n\n setPartModel(part, key) {\n if (this._model && this._model[key]) {\n\n part.model = {\n ...preparePrintModel(this._model[key], this._options),\n keyMode: this._model[key].choicePrefix,\n };\n\n if (!part._session) {\n // for print, \"set session\" is not called,\n // but ebsr needs sessions in order to render the elements,\n // so we set it here it was not set already\n part.session = {};\n }\n }\n }\n\n set options(o) {\n this._options = o;\n }\n\n setPartSession(part, key) {\n if (this._session && this._model) {\n const { value } = this._session;\n part.session = value && value[key] ? value[key] : { id: key };\n }\n }\n\n dispatchSessionChanged(partSession, key) {\n this._session.value = {\n ...this._session.value,\n [key]: partSession,\n };\n\n log('[onSessionChanged] session: ', this._session);\n const complete = isSessionComplete(this._session);\n this.dispatchEvent(\n new SessionChangedEvent(this.tagName.toLowerCase(), complete)\n );\n }\n\n get partA() {\n return this.querySelector(`${MC_TAG_NAME}#a`);\n }\n\n get partB() {\n return this.querySelector(`${MC_TAG_NAME}#b`);\n }\n\n connectedCallback() {\n this._render();\n this.addEventListener(SESSION_CHANGED, this.onSessionUpdated);\n }\n\n disconnectedCallback() {\n this.removeEventListener(SESSION_CHANGED, this.onSessionUpdated);\n }\n\n _render() {\n this.innerHTML = `\n <div>\n <${MC_TAG_NAME} id=\"a\"></${MC_TAG_NAME}>\n <${MC_TAG_NAME} id=\"b\"></${MC_TAG_NAME}>\n </div>\n `;\n }\n}\n"],"file":"print.js"}
|