@pie-element/ebsr 6.6.3-next.579 → 6.6.3-next.749

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.
@@ -85,6 +85,11 @@
85
85
  "type": "boolean",
86
86
  "title": "rationaleEnabled"
87
87
  },
88
+ "spellCheckEnabled": {
89
+ "description": "Indicates if spellcheck is enabled for the author. Default value is true",
90
+ "type": "boolean",
91
+ "title": "spellCheckEnabled"
92
+ },
88
93
  "studentInstructionsEnabled": {
89
94
  "description": "Indicates if Student Instructions are enabled",
90
95
  "type": "boolean",
@@ -109,6 +114,7 @@
109
114
  "feedbackEnabled",
110
115
  "prompt",
111
116
  "rationaleEnabled",
117
+ "spellCheckEnabled",
112
118
  "studentInstructionsEnabled",
113
119
  "teacherInstructionsEnabled"
114
120
  ]
@@ -195,6 +201,11 @@
195
201
  "type": "boolean",
196
202
  "title": "rationaleEnabled"
197
203
  },
204
+ "spellCheckEnabled": {
205
+ "description": "Indicates if spellcheck is enabled for the author. Default value is true",
206
+ "type": "boolean",
207
+ "title": "spellCheckEnabled"
208
+ },
198
209
  "studentInstructionsEnabled": {
199
210
  "description": "Indicates if Student Instructions are enabled",
200
211
  "type": "boolean",
@@ -219,6 +230,7 @@
219
230
  "feedbackEnabled",
220
231
  "prompt",
221
232
  "rationaleEnabled",
233
+ "spellCheckEnabled",
222
234
  "studentInstructionsEnabled",
223
235
  "teacherInstructionsEnabled"
224
236
  ]
@@ -387,6 +399,22 @@
387
399
  }
388
400
  }
389
401
  },
402
+ "spellCheck": {
403
+ "title": "ConfigureProp",
404
+ "type": "object",
405
+ "properties": {
406
+ "settings": {
407
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
408
+ "type": "boolean",
409
+ "title": "settings"
410
+ },
411
+ "label": {
412
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
413
+ "type": "string",
414
+ "title": "label"
415
+ }
416
+ }
417
+ },
390
418
  "rationale": {
391
419
  "title": "ConfigureProp",
392
420
  "type": "object",
@@ -567,6 +595,11 @@
567
595
  "type": "boolean",
568
596
  "title": "rationaleEnabled"
569
597
  },
598
+ "spellCheckEnabled": {
599
+ "description": "Indicates if spellcheck is enabled for the author. Default value is true",
600
+ "type": "boolean",
601
+ "title": "spellCheckEnabled"
602
+ },
570
603
  "studentInstructionsEnabled": {
571
604
  "description": "Indicates if Student Instructions are enabled",
572
605
  "type": "boolean",
@@ -591,6 +624,7 @@
591
624
  "feedbackEnabled",
592
625
  "prompt",
593
626
  "rationaleEnabled",
627
+ "spellCheckEnabled",
594
628
  "studentInstructionsEnabled",
595
629
  "teacherInstructionsEnabled"
596
630
  ]
@@ -68,6 +68,10 @@ Indicates if Feedback is enabled
68
68
 
69
69
  Indicates if Rationale are enabled
70
70
 
71
+ ## `spellCheckEnabled` (boolean, required)
72
+
73
+ Indicates if spellcheck is enabled for the author. Default value is true
74
+
71
75
  ## `studentInstructionsEnabled` (boolean, required)
72
76
 
73
77
  Indicates if Student Instructions are enabled
@@ -148,6 +152,10 @@ Indicates if Feedback is enabled
148
152
 
149
153
  Indicates if Rationale are enabled
150
154
 
155
+ ## `spellCheckEnabled` (boolean, required)
156
+
157
+ Indicates if spellcheck is enabled for the author. Default value is true
158
+
151
159
  ## `studentInstructionsEnabled` (boolean, required)
152
160
 
153
161
  Indicates if Student Instructions are enabled
@@ -290,6 +298,18 @@ Indicates if the item has to be displayed in the Settings Panel
290
298
 
291
299
  Indicates the label for the item that has to be displayed in the Settings Panel
292
300
 
301
+ ### `spellCheck` (object)
302
+
303
+ Properties of the `spellCheck` object:
304
+
305
+ #### `settings` (boolean)
306
+
307
+ Indicates if the item has to be displayed in the Settings Panel
308
+
309
+ #### `label` (string)
310
+
311
+ Indicates the label for the item that has to be displayed in the Settings Panel
312
+
293
313
  ### `rationale` (object)
294
314
 
295
315
  Properties of the `rationale` object:
@@ -428,6 +448,10 @@ Indicates if Feedback is enabled
428
448
 
429
449
  Indicates if Rationale are enabled
430
450
 
451
+ ### `spellCheckEnabled` (boolean, required)
452
+
453
+ Indicates if spellcheck is enabled for the author. Default value is true
454
+
431
455
  ### `studentInstructionsEnabled` (boolean, required)
432
456
 
433
457
  Indicates if Student Instructions are enabled
package/lib/index.js CHANGED
@@ -5,9 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports["default"] = exports.isSessionComplete = void 0;
9
-
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
8
+ exports.isSessionComplete = exports["default"] = void 0;
11
9
 
12
10
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
13
11
 
@@ -15,6 +13,8 @@ var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/w
15
13
 
16
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
15
 
16
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
+
18
18
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
19
19
 
20
20
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
@@ -31,9 +31,9 @@ var _get = _interopRequireDefault(require("lodash/get"));
31
31
 
32
32
  var _debug = _interopRequireDefault(require("debug"));
33
33
 
34
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
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
35
 
36
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
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
37
 
38
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
39
 
@@ -53,7 +53,7 @@ var EbsrMC = /*#__PURE__*/function (_MultipleChoice) {
53
53
  return _super.apply(this, arguments);
54
54
  }
55
55
 
56
- return EbsrMC;
56
+ return (0, _createClass2["default"])(EbsrMC);
57
57
  }(_multipleChoice["default"]);
58
58
 
59
59
  var defineMultipleChoice = function defineMultipleChoice() {
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' : model.mode;
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
@@ -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":";;;;;;;;;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ACD;;;WAED,gCAAuB;AACrB,WAAKC,mBAAL,CAAyB/E,eAAzB,EAA0C,KAAK8E,gBAA/C;AACD;;;WAED,mBAAU;AACR,WAAKE,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' : model.mode;\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"}