@pie-element/passage 2.15.0 → 2.15.1-next.12

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.
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@pie-element/passage-configure",
3
+ "private": true,
4
+ "version": "1.0.0",
5
+ "description": "",
6
+ "main": "lib/index.js",
7
+ "module": "src/index.js",
8
+ "author": "pie framework developers",
9
+ "license": "ISC",
10
+ "dependencies": {
11
+ "@material-ui/core": "^3.9.2",
12
+ "@pie-framework/pie-configure-events": "^1.3.0",
13
+ "@pie-lib/pie-toolbox": "1.21.0",
14
+ "lodash": "^4.17.15",
15
+ "prop-types": "^15.6.2",
16
+ "react": "^16.8.1",
17
+ "react-dom": "^16.8.1"
18
+ }
19
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _default = {
8
+ teacherInstructionsEnabled: false,
9
+ titleEnabled: true,
10
+ subtitleEnabled: true,
11
+ textEnabled: true,
12
+ authorEnabled: true,
13
+ passages: [{
14
+ teacherInstructions: '',
15
+ title: '',
16
+ subtitle: '',
17
+ author: '',
18
+ text: ''
19
+ }]
20
+ };
21
+ exports["default"] = _default;
22
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/defaults.js"],"names":["teacherInstructionsEnabled","titleEnabled","subtitleEnabled","textEnabled","authorEnabled","passages","teacherInstructions","title","subtitle","author","text"],"mappings":";;;;;;eAAe;AACbA,EAAAA,0BAA0B,EAAE,KADf;AAEbC,EAAAA,YAAY,EAAE,IAFD;AAGbC,EAAAA,eAAe,EAAE,IAHJ;AAIbC,EAAAA,WAAW,EAAE,IAJA;AAKbC,EAAAA,aAAa,EAAE,IALF;AAMbC,EAAAA,QAAQ,EAAE,CACR;AACEC,IAAAA,mBAAmB,EAAE,EADvB;AAEEC,IAAAA,KAAK,EAAE,EAFT;AAGEC,IAAAA,QAAQ,EAAE,EAHZ;AAIEC,IAAAA,MAAM,EAAE,EAJV;AAKEC,IAAAA,IAAI,EAAE;AALR,GADQ;AANG,C","sourcesContent":["export default {\n teacherInstructionsEnabled: false,\n titleEnabled: true,\n subtitleEnabled: true,\n textEnabled: true,\n authorEnabled: true,\n passages: [\n {\n teacherInstructions: '',\n title: '',\n subtitle: '',\n author: '',\n text: '',\n }\n ],\n};\n"],"file":"defaults.js"}
@@ -5,43 +5,73 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ exports.createDefaultModel = createDefaultModel;
8
9
  exports.model = model;
10
+ exports.validate = exports.normalize = void 0;
9
11
 
10
12
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
13
 
12
14
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
15
 
16
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
+
14
18
  var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
15
19
 
20
+ var _defaults = _interopRequireDefault(require("./defaults"));
21
+
22
+ 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; }
23
+
24
+ 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; }
25
+
26
+ var getContent = function getContent(html) {
27
+ return (html || '').replace(/(<(?!img|iframe)([^>]+)>)/gi, '');
28
+ };
29
+
30
+ function createDefaultModel() {
31
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
32
+ return new Promise(function (resolve) {
33
+ resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
34
+ });
35
+ }
36
+
37
+ var normalize = function normalize(question) {
38
+ return _objectSpread(_objectSpread({}, _defaults["default"]), question);
39
+ };
16
40
  /**
17
41
  *
18
42
  * @param {*} question
19
43
  * @param {*} session
20
44
  * @param {*} env
21
45
  */
46
+
47
+
48
+ exports.normalize = normalize;
49
+
22
50
  function model(_x, _x2, _x3) {
23
51
  return _model.apply(this, arguments);
24
52
  }
25
53
 
26
54
  function _model() {
27
55
  _model = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(question, session, env) {
28
- var _ref, role, mode, response;
56
+ var _ref, role, mode, normalizedQuestion, out;
29
57
 
30
58
  return _regenerator["default"].wrap(function _callee$(_context) {
31
59
  while (1) {
32
60
  switch (_context.prev = _context.next) {
33
61
  case 0:
34
62
  _ref = env || {}, role = _ref.role, mode = _ref.mode;
35
- response = (0, _cloneDeep["default"])(question);
36
- response.showTeacherInstructions = role === 'instructor' && (mode === 'view' || mode === 'evaluate'); // if we don't show the teacher instructions don't pass them on
63
+ normalizedQuestion = normalize(question);
64
+ out = _objectSpread(_objectSpread({}, normalizedQuestion), {}, {
65
+ teacherInstructions: null
66
+ });
37
67
 
38
- if (!response.showTeacherInstructions) {
39
- response.passages.forEach(function (passage) {
40
- delete passage.teacherInstructions;
41
- });
68
+ if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
69
+ if (normalizedQuestion.teacherInstructionsEnabled) {
70
+ out.teacherInstructions = normalizedQuestion.teacherInstructions;
71
+ }
42
72
  }
43
73
 
44
- return _context.abrupt("return", response);
74
+ return _context.abrupt("return", out);
45
75
 
46
76
  case 5:
47
77
  case "end":
@@ -52,4 +82,20 @@ function _model() {
52
82
  }));
53
83
  return _model.apply(this, arguments);
54
84
  }
85
+
86
+ var validate = function validate() {
87
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
88
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
89
+ var errors = {};
90
+ ['teacherInstructions', 'title', 'subtitle', 'author', 'text'].forEach(function (field) {
91
+ var _config$field;
92
+
93
+ if ((_config$field = config[field]) !== null && _config$field !== void 0 && _config$field.required && !getContent(model[field])) {
94
+ errors[field] = 'This field is required.';
95
+ }
96
+ });
97
+ return errors;
98
+ };
99
+
100
+ exports.validate = validate;
55
101
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["model","question","session","env","role","mode","response","showTeacherInstructions","passages","forEach","passage","teacherInstructions"],"mappings":";;;;;;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;SACsBA,K;;;;;yFAAf,iBAAqBC,QAArB,EAA+BC,OAA/B,EAAwCC,GAAxC;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,mBACkBA,GAAG,IAAI,EADzB,EACGC,IADH,QACGA,IADH,EACSC,IADT,QACSA,IADT;AAECC,YAAAA,QAFD,GAEY,2BAAUL,QAAV,CAFZ;AAILK,YAAAA,QAAQ,CAACC,uBAAT,GAAmCH,IAAI,KAAK,YAAT,KAA0BC,IAAI,KAAK,MAAT,IAAmBA,IAAI,KAAK,UAAtD,CAAnC,CAJK,CAML;;AACA,gBAAI,CAACC,QAAQ,CAACC,uBAAd,EAAuC;AACrCD,cAAAA,QAAQ,CAACE,QAAT,CAAkBC,OAAlB,CAA0B,UAACC,OAAD,EAAa;AACrC,uBAAOA,OAAO,CAACC,mBAAf;AACD,eAFD;AAGD;;AAXI,6CAaEL,QAbF;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G","sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport async function model(question, session, env) {\n const { role, mode } = env || {};\n const response = cloneDeep(question);\n\n response.showTeacherInstructions = role === 'instructor' && (mode === 'view' || mode === 'evaluate');\n\n // if we don't show the teacher instructions don't pass them on\n if (!response.showTeacherInstructions) {\n response.passages.forEach((passage) => {\n delete passage.teacherInstructions;\n });\n }\n\n return response;\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["getContent","html","replace","createDefaultModel","model","Promise","resolve","defaults","normalize","question","session","env","role","mode","normalizedQuestion","out","teacherInstructions","teacherInstructionsEnabled","validate","config","errors","forEach","field","required"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;;;;;AAEA,IAAMA,UAAU,GAAG,SAAbA,UAAa,CAACC,IAAD;AAAA,SAAU,CAACA,IAAI,IAAI,EAAT,EAAaC,OAAb,CAAqB,6BAArB,EAAoD,EAApD,CAAV;AAAA,CAAnB;;AAEO,SAASC,kBAAT,GAAwC;AAAA,MAAZC,KAAY,uEAAJ,EAAI;AAC7C,SAAO,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAa;AAC9BA,IAAAA,OAAO,iCACFC,oBADE,GAEFH,KAFE,EAAP;AAID,GALM,CAAP;AAMD;;AAEM,IAAMI,SAAS,GAAG,SAAZA,SAAY,CAACC,QAAD;AAAA,yCACpBF,oBADoB,GAEpBE,QAFoB;AAAA,CAAlB;AAKP;AACA;AACA;AACA;AACA;AACA;;;;;SACsBL,K;;;;;yFAAf,iBAAqBK,QAArB,EAA+BC,OAA/B,EAAwCC,GAAxC;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,mBACkBA,GAAG,IAAI,EADzB,EACGC,IADH,QACGA,IADH,EACSC,IADT,QACSA,IADT;AAECC,YAAAA,kBAFD,GAEsBN,SAAS,CAACC,QAAD,CAF/B;AAICM,YAAAA,GAJD,mCAKAD,kBALA;AAMHE,cAAAA,mBAAmB,EAAE;AANlB;;AASL,gBAAIJ,IAAI,KAAK,YAAT,KAA0BC,IAAI,KAAK,MAAT,IAAmBA,IAAI,KAAK,UAAtD,CAAJ,EAAuE;AACrE,kBAAIC,kBAAkB,CAACG,0BAAvB,EAAmD;AACjDF,gBAAAA,GAAG,CAACC,mBAAJ,GAA0BF,kBAAkB,CAACE,mBAA7C;AACD;AACF;;AAbI,6CAeED,GAfF;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G;;;;AAkBA,IAAMG,QAAQ,GAAG,SAAXA,QAAW,GAA6B;AAAA,MAA5Bd,KAA4B,uEAApB,EAAoB;AAAA,MAAhBe,MAAgB,uEAAP,EAAO;AACnD,MAAMC,MAAM,GAAG,EAAf;AAEA,GAAC,qBAAD,EAAwB,OAAxB,EAAiC,UAAjC,EAA6C,QAA7C,EAAuD,MAAvD,EAA+DC,OAA/D,CAAuE,UAACC,KAAD,EAAW;AAAA;;AAChF,QAAI,iBAAAH,MAAM,CAACG,KAAD,CAAN,wDAAeC,QAAf,IAA2B,CAACvB,UAAU,CAACI,KAAK,CAACkB,KAAD,CAAN,CAA1C,EAA0D;AACxDF,MAAAA,MAAM,CAACE,KAAD,CAAN,GAAgB,yBAAhB;AACD;AACF,GAJD;AAMA,SAAOF,MAAP;AACD,CAVM","sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\nimport defaults from './defaults';\n\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe)([^>]+)>)/gi, '');\n\nexport function createDefaultModel(model = {}) {\n return new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n}\n\nexport const normalize = (question) => ({\n ...defaults,\n ...question,\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport async function model(question, session, env) {\n const { role, mode } = env || {};\n const normalizedQuestion = normalize(question);\n\n const out = {\n ...normalizedQuestion,\n teacherInstructions: null\n };\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n if (normalizedQuestion.teacherInstructionsEnabled) {\n out.teacherInstructions = normalizedQuestion.teacherInstructions;\n }\n }\n\n return out;\n}\n\nexport const validate = (model = {}, config = {}) => {\n const errors = {};\n\n ['teacherInstructions', 'title', 'subtitle', 'author', 'text'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n return errors;\n};\n"],"file":"index.js"}