@pie-lib/mask-markup 1.11.2 → 1.12.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/CHANGELOG.md +35 -0
- package/lib/choices/choice.js +20 -16
- package/lib/choices/choice.js.map +1 -1
- package/lib/choices/index.js +17 -15
- package/lib/choices/index.js.map +1 -1
- package/lib/components/blank.js +27 -21
- package/lib/components/blank.js.map +1 -1
- package/lib/components/correct-input.js +22 -12
- package/lib/components/correct-input.js.map +1 -1
- package/lib/components/dropdown.js +20 -16
- package/lib/components/dropdown.js.map +1 -1
- package/lib/components/input.js +7 -3
- package/lib/components/input.js.map +1 -1
- package/lib/constructed-response.js +7 -3
- package/lib/constructed-response.js.map +1 -1
- package/lib/drag-in-the-blank.js +19 -17
- package/lib/drag-in-the-blank.js.map +1 -1
- package/lib/index.js +12 -12
- package/lib/inline-dropdown.js +1 -1
- package/lib/inline-dropdown.js.map +1 -1
- package/lib/mask.js +47 -26
- package/lib/mask.js.map +1 -1
- package/lib/serialization.js +13 -4
- package/lib/serialization.js.map +1 -1
- package/lib/with-mask.js +19 -15
- package/lib/with-mask.js.map +1 -1
- package/package.json +4 -4
- package/src/components/correct-input.jsx +25 -11
- package/src/components/input.jsx +15 -2
- package/src/constructed-response.jsx +5 -2
- package/src/mask.jsx +14 -1
- package/src/serialization.js +8 -1
package/lib/mask.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
|
-
exports["default"] =
|
|
8
|
+
exports.renderChildren = exports["default"] = void 0;
|
|
7
9
|
|
|
8
10
|
var _react = _interopRequireDefault(require("react"));
|
|
9
11
|
|
|
@@ -17,27 +19,29 @@ var _serialization = require("./serialization");
|
|
|
17
19
|
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
21
|
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
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; }
|
|
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
23
|
|
|
24
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
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) { _defineProperty(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
25
|
|
|
26
26
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
27
27
|
|
|
28
28
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
29
29
|
|
|
30
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
30
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
31
31
|
|
|
32
|
-
function
|
|
32
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
33
33
|
|
|
34
|
-
function
|
|
34
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
35
|
+
|
|
36
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
37
|
+
|
|
38
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
35
39
|
|
|
36
40
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
37
41
|
|
|
38
|
-
function
|
|
42
|
+
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; } }
|
|
39
43
|
|
|
40
|
-
function
|
|
44
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
41
45
|
|
|
42
46
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
43
47
|
|
|
@@ -51,7 +55,7 @@ var Paragraph = (0, _styles.withStyles)(function (theme) {
|
|
|
51
55
|
}
|
|
52
56
|
};
|
|
53
57
|
})(function (props) {
|
|
54
|
-
return _react["default"].createElement("div", {
|
|
58
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
55
59
|
className: props.classes.para
|
|
56
60
|
}, props.children);
|
|
57
61
|
});
|
|
@@ -89,6 +93,15 @@ var renderChildren = function renderChildren(layout, value, onChange, rootRender
|
|
|
89
93
|
(layout.nodes || []).forEach(function (n, index) {
|
|
90
94
|
var key = "".concat(n.type, "-").concat(index);
|
|
91
95
|
|
|
96
|
+
if (n.isMath) {
|
|
97
|
+
children.push( /*#__PURE__*/_react["default"].createElement("span", {
|
|
98
|
+
dangerouslySetInnerHTML: {
|
|
99
|
+
__html: "<math>".concat(n.nodes[0].innerHTML, "</math>")
|
|
100
|
+
}
|
|
101
|
+
}));
|
|
102
|
+
return children;
|
|
103
|
+
}
|
|
104
|
+
|
|
92
105
|
if (rootRenderChildren) {
|
|
93
106
|
var c = rootRenderChildren(n, value, onChange);
|
|
94
107
|
|
|
@@ -112,7 +125,7 @@ var renderChildren = function renderChildren(layout, value, onChange, rootRender
|
|
|
112
125
|
for (markKey in _serialization.MARK_TAGS) {
|
|
113
126
|
if (_serialization.MARK_TAGS[markKey] === mark.type) {
|
|
114
127
|
var Tag = markKey;
|
|
115
|
-
children.push(_react["default"].createElement(Tag, null, content));
|
|
128
|
+
children.push( /*#__PURE__*/_react["default"].createElement(Tag, null, content));
|
|
116
129
|
break;
|
|
117
130
|
}
|
|
118
131
|
}
|
|
@@ -123,18 +136,18 @@ var renderChildren = function renderChildren(layout, value, onChange, rootRender
|
|
|
123
136
|
var subNodes = renderChildren(n, value, onChange, rootRenderChildren, n);
|
|
124
137
|
|
|
125
138
|
if (n.type === 'p' || n.type === 'paragraph') {
|
|
126
|
-
children.push(_react["default"].createElement(Paragraph, {
|
|
139
|
+
children.push( /*#__PURE__*/_react["default"].createElement(Paragraph, {
|
|
127
140
|
key: key
|
|
128
141
|
}, subNodes));
|
|
129
142
|
} else {
|
|
130
143
|
var _Tag = n.type;
|
|
131
144
|
|
|
132
145
|
if (n.nodes && n.nodes.length > 0) {
|
|
133
|
-
children.push(_react["default"].createElement(_Tag, _extends({
|
|
146
|
+
children.push( /*#__PURE__*/_react["default"].createElement(_Tag, _extends({
|
|
134
147
|
key: key
|
|
135
148
|
}, n.data.attributes), subNodes));
|
|
136
149
|
} else {
|
|
137
|
-
children.push(_react["default"].createElement(_Tag, _extends({
|
|
150
|
+
children.push( /*#__PURE__*/_react["default"].createElement(_Tag, _extends({
|
|
138
151
|
key: key
|
|
139
152
|
}, n.data.attributes)));
|
|
140
153
|
}
|
|
@@ -143,21 +156,29 @@ var renderChildren = function renderChildren(layout, value, onChange, rootRender
|
|
|
143
156
|
});
|
|
144
157
|
return children;
|
|
145
158
|
};
|
|
159
|
+
|
|
160
|
+
exports.renderChildren = renderChildren;
|
|
161
|
+
var MaskContainer = (0, _styles.withStyles)(function () {
|
|
162
|
+
return {
|
|
163
|
+
main: {
|
|
164
|
+
display: 'inherit'
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
})(function (props) {
|
|
168
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
169
|
+
className: props.classes.main
|
|
170
|
+
}, props.children);
|
|
171
|
+
});
|
|
146
172
|
/**
|
|
147
173
|
* Renders a layout that uses the slate.js Value model structure.
|
|
148
174
|
*/
|
|
149
175
|
|
|
150
|
-
|
|
151
|
-
exports.renderChildren = renderChildren;
|
|
152
|
-
|
|
153
|
-
var Mask =
|
|
154
|
-
/*#__PURE__*/
|
|
155
|
-
function (_React$Component) {
|
|
176
|
+
var Mask = /*#__PURE__*/function (_React$Component) {
|
|
156
177
|
_inherits(Mask, _React$Component);
|
|
157
178
|
|
|
158
|
-
|
|
159
|
-
var _getPrototypeOf2;
|
|
179
|
+
var _super = _createSuper(Mask);
|
|
160
180
|
|
|
181
|
+
function Mask() {
|
|
161
182
|
var _this;
|
|
162
183
|
|
|
163
184
|
_classCallCheck(this, Mask);
|
|
@@ -166,10 +187,10 @@ function (_React$Component) {
|
|
|
166
187
|
args[_key] = arguments[_key];
|
|
167
188
|
}
|
|
168
189
|
|
|
169
|
-
_this =
|
|
190
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
170
191
|
|
|
171
192
|
_defineProperty(_assertThisInitialized(_this), "handleChange", function (id, value) {
|
|
172
|
-
var data = _objectSpread({}, _this.props.value, _defineProperty({}, id, value));
|
|
193
|
+
var data = _objectSpread(_objectSpread({}, _this.props.value), {}, _defineProperty({}, id, value));
|
|
173
194
|
|
|
174
195
|
_this.props.onChange(data);
|
|
175
196
|
});
|
|
@@ -184,7 +205,7 @@ function (_React$Component) {
|
|
|
184
205
|
value = _this$props.value,
|
|
185
206
|
layout = _this$props.layout;
|
|
186
207
|
var children = renderChildren(layout, value, this.handleChange, this.props.renderChildren);
|
|
187
|
-
return _react["default"].createElement(
|
|
208
|
+
return /*#__PURE__*/_react["default"].createElement(MaskContainer, null, children);
|
|
188
209
|
}
|
|
189
210
|
}]);
|
|
190
211
|
|
package/lib/mask.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mask.jsx"],"names":["Paragraph","theme","para","paddingTop","spacing","unit","paddingBottom","props","classes","children","restrictWhitespaceTypes","addText","parentNode","text","isWhitespace","trim","parentType","type","includes","undefined","getMark","n","mark","leaves","find","leave","length","marks","renderChildren","layout","value","onChange","rootRenderChildren","nodes","forEach","index","key","
|
|
1
|
+
{"version":3,"sources":["../src/mask.jsx"],"names":["Paragraph","theme","para","paddingTop","spacing","unit","paddingBottom","props","classes","children","restrictWhitespaceTypes","addText","parentNode","text","isWhitespace","trim","parentType","type","includes","undefined","getMark","n","mark","leaves","find","leave","length","marks","renderChildren","layout","value","onChange","rootRenderChildren","nodes","forEach","index","key","isMath","push","__html","innerHTML","c","object","content","reduce","acc","l","t","extraText","markKey","MARK_TAGS","Tag","subNodes","data","attributes","MaskContainer","main","display","Mask","id","handleChange","React","Component","PropTypes","func"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,SAAS,GAAG,wBAAW,UAAAC,KAAK;AAAA,SAAK;AACrCC,IAAAA,IAAI,EAAE;AACJC,MAAAA,UAAU,EAAE,IAAIF,KAAK,CAACG,OAAN,CAAcC,IAD1B;AAEJC,MAAAA,aAAa,EAAE,IAAIL,KAAK,CAACG,OAAN,CAAcC;AAF7B;AAD+B,GAAL;AAAA,CAAhB,EAKd,UAAAE,KAAK;AAAA,sBAAI;AAAK,IAAA,SAAS,EAAEA,KAAK,CAACC,OAAN,CAAcN;AAA9B,KAAqCK,KAAK,CAACE,QAA3C,CAAJ;AAAA,CALS,CAAlB;AAOA,IAAMC,uBAAuB,GAAG,CAAC,OAAD,EAAU,IAAV,CAAhC;;AAEA,IAAMC,OAAO,GAAG,SAAVA,OAAU,CAACC,UAAD,EAAaC,IAAb,EAAsB;AACpC,MAAMC,YAAY,GAAGD,IAAI,CAACE,IAAL,OAAgB,EAArC;AACA,MAAMC,UAAU,GAAGJ,UAAU,IAAIA,UAAU,CAACK,IAA5C;;AAEA,MAAIH,YAAY,IAAIJ,uBAAuB,CAACQ,QAAxB,CAAiCF,UAAjC,C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EAlB+BoD,kBAAMC,S;;;;gBAAnBJ,I,eACA;AACjB9B,EAAAA,cAAc,EAAEmC,sBAAUC,IADT;AAEjBnC,EAAAA,MAAM,EAAEkC,sBAAUrB,MAFD;AAGjBZ,EAAAA,KAAK,EAAEiC,sBAAUrB,MAHA;AAIjBX,EAAAA,QAAQ,EAAEgC,sBAAUC;AAJH,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport get from 'lodash/get';\nimport { withStyles } from '@material-ui/core/styles';\nimport { MARK_TAGS } from './serialization';\n\nconst Paragraph = withStyles(theme => ({\n para: {\n paddingTop: 2 * theme.spacing.unit,\n paddingBottom: 2 * theme.spacing.unit\n }\n}))(props => <div className={props.classes.para}>{props.children}</div>);\n\nconst restrictWhitespaceTypes = ['tbody', 'tr'];\n\nconst addText = (parentNode, text) => {\n const isWhitespace = text.trim() === '';\n const parentType = parentNode && parentNode.type;\n\n if (isWhitespace && restrictWhitespaceTypes.includes(parentType)) {\n return undefined;\n } else {\n return text;\n }\n};\n\nconst getMark = n => {\n const mark = n.leaves.find(leave => get(leave, 'marks', []).length);\n\n if (mark) {\n return mark.marks[0];\n }\n\n return null;\n};\n\nexport const renderChildren = (layout, value, onChange, rootRenderChildren, parentNode) => {\n if (!value) {\n return null;\n }\n\n const children = [];\n\n (layout.nodes || []).forEach((n, index) => {\n const key = `${n.type}-${index}`;\n\n if (n.isMath) {\n children.push(\n <span dangerouslySetInnerHTML={{ __html: `<math>${n.nodes[0].innerHTML}</math>` }} />\n );\n return children;\n }\n\n if (rootRenderChildren) {\n const c = rootRenderChildren(n, value, onChange);\n if (c) {\n children.push(c);\n return;\n }\n }\n\n if (n.object === 'text') {\n const content = n.leaves.reduce((acc, l) => {\n const t = l.text;\n const extraText = addText(parentNode, t);\n return extraText ? acc + extraText : acc;\n }, '');\n const mark = getMark(n);\n\n if (mark) {\n let markKey;\n\n for (markKey in MARK_TAGS) {\n if (MARK_TAGS[markKey] === mark.type) {\n const Tag = markKey;\n\n children.push(<Tag>{content}</Tag>);\n break;\n }\n }\n } else if (content.length > 0) {\n children.push(content);\n }\n } else {\n const subNodes = renderChildren(n, value, onChange, rootRenderChildren, n);\n if (n.type === 'p' || n.type === 'paragraph') {\n children.push(<Paragraph key={key}>{subNodes}</Paragraph>);\n } else {\n const Tag = n.type;\n if (n.nodes && n.nodes.length > 0) {\n children.push(\n <Tag key={key} {...n.data.attributes}>\n {subNodes}\n </Tag>\n );\n } else {\n children.push(<Tag key={key} {...n.data.attributes} />);\n }\n }\n }\n });\n return children;\n};\n\nconst MaskContainer = withStyles(() => ({\n main: {\n display: 'inherit'\n }\n}))(props => <div className={props.classes.main}>{props.children}</div>);\n\n/**\n * Renders a layout that uses the slate.js Value model structure.\n */\nexport default class Mask extends React.Component {\n static propTypes = {\n renderChildren: PropTypes.func,\n layout: PropTypes.object,\n value: PropTypes.object,\n onChange: PropTypes.func\n };\n\n handleChange = (id, value) => {\n const data = { ...this.props.value, [id]: value };\n this.props.onChange(data);\n };\n\n render() {\n const { value, layout } = this.props;\n const children = renderChildren(layout, value, this.handleChange, this.props.renderChildren);\n\n return <MaskContainer>{children}</MaskContainer>;\n }\n}\n"],"file":"mask.js"}
|
package/lib/serialization.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.reactAttributes = exports.parseStyleString = exports.deserialize = exports.MARK_TAGS = void 0;
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
@@ -15,9 +15,9 @@ var _debug = _interopRequireDefault(require("debug"));
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
17
|
|
|
18
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
18
|
+
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; }
|
|
19
19
|
|
|
20
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
20
|
+
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) { _defineProperty(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; }
|
|
21
21
|
|
|
22
22
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
23
|
|
|
@@ -69,7 +69,8 @@ exports.parseStyleString = parseStyleString;
|
|
|
69
69
|
|
|
70
70
|
var reactAttributes = function reactAttributes(o) {
|
|
71
71
|
return (0, _toStyle.object)(o, {
|
|
72
|
-
camelize: true
|
|
72
|
+
camelize: true,
|
|
73
|
+
addUnits: false
|
|
73
74
|
});
|
|
74
75
|
};
|
|
75
76
|
|
|
@@ -164,6 +165,14 @@ var rules = [marks, {
|
|
|
164
165
|
var normalAttrs = attr(el) || {};
|
|
165
166
|
var allAttrs = attributes.reduce(attributesToMap(el), _objectSpread({}, normalAttrs));
|
|
166
167
|
var object = getObject(type);
|
|
168
|
+
|
|
169
|
+
if (el.tagName.toLowerCase() === 'math') {
|
|
170
|
+
return {
|
|
171
|
+
isMath: true,
|
|
172
|
+
nodes: [el]
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
167
176
|
return {
|
|
168
177
|
object: object,
|
|
169
178
|
type: type,
|
package/lib/serialization.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/serialization.js"],"names":["log","INLINE","MARK","TEXT_NODE","COMMENT_NODE","attr","el","attributes","length","undefined","out","i","a","name","value","getObject","type","includes","parseStyleString","s","regex","match","result","exec","trim","reactAttributes","o","camelize","handleStyles","attribute","styleString","getAttribute","handleClass","acc","classNames","attributesToMap","style","className","MARK_TAGS","b","em","u","code","strong","marks","deserialize","next","mark","tagName","toLowerCase","object","nodes","childNodes","rules","nodeType","leaves","text","textContent","normalAttrs","allAttrs","reduce","data","dataset","html","Html","defaultBlock","toJSON"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,oCAAN,CAAZ;AAEA,IAAMC,MAAM,GAAG,CAAC,MAAD,CAAf;AACA,IAAMC,IAAI,GAAG,CAAC,IAAD,EAAO,QAAP,EAAiB,GAAjB,CAAb;AACA,IAAMC,SAAS,GAAG,CAAlB;AACA,IAAMC,YAAY,GAAG,CAArB;;AAEA,IAAMC,IAAI,GAAG,SAAPA,IAAO,CAAAC,EAAE,EAAI;AACjB,MAAI,CAACA,EAAE,CAACC,UAAJ,IAAkBD,EAAE,CAACC,UAAH,CAAcC,MAAd,IAAwB,CAA9C,EAAiD;AAC/C,WAAOC,SAAP;AACD;;AAED,MAAMC,GAAG,GAAG,EAAZ;AACA,MAAIC,CAAJ;;AAEA,OAAKA,CAAC,GAAG,CAAT,EAAYA,CAAC,GAAGL,EAAE,CAACC,UAAH,CAAcC,MAA9B,EAAsCG,CAAC,EAAvC,EAA2C;AACzC,QAAMC,CAAC,GAAGN,EAAE,CAACC,UAAH,CAAcI,CAAd,CAAV;AAEAD,IAAAA,GAAG,CAACE,CAAC,CAACC,IAAH,CAAH,GAAcD,CAAC,CAACE,KAAhB;AACD;;AAED,SAAOJ,GAAP;AACD,CAfD;;AAiBA,IAAMK,SAAS,GAAG,SAAZA,SAAY,CAAAC,IAAI,EAAI;AACxB,MAAIf,MAAM,CAACgB,QAAP,CAAgBD,IAAhB,CAAJ,EAA2B;AACzB,WAAO,QAAP;AACD,GAFD,MAEO,IAAId,IAAI,CAACe,QAAL,CAAcD,IAAd,CAAJ,EAAyB;AAC9B,WAAO,MAAP;AACD;;AACD,SAAO,OAAP;AACD,CAPD;;AASO,IAAME,gBAAgB,GAAG,SAAnBA,gBAAmB,CAAAC,CAAC,EAAI;AACnC,MAAMC,KAAK,GAAG,yBAAd;AACA,MAAIC,KAAJ;AACA,MAAMC,MAAM,GAAG,EAAf;;AACA,SAAQD,KAAK,GAAGD,KAAK,CAACG,IAAN,CAAWJ,CAAX,CAAhB,EAAgC;AAC9BG,IAAAA,MAAM,CAACD,KAAK,CAAC,CAAD,CAAN,CAAN,GAAmBA,KAAK,CAAC,CAAD,CAAL,CAASG,IAAT,EAAnB;AACD;;AACD,SAAOF,MAAP;AACD,CARM;;;;AAUA,IAAMG,eAAe,GAAG,SAAlBA,eAAkB,CAAAC,CAAC;AAAA,SAAI,qBAAcA,CAAd,EAAiB;AAAEC,IAAAA,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"sources":["../src/serialization.js"],"names":["log","INLINE","MARK","TEXT_NODE","COMMENT_NODE","attr","el","attributes","length","undefined","out","i","a","name","value","getObject","type","includes","parseStyleString","s","regex","match","result","exec","trim","reactAttributes","o","camelize","addUnits","handleStyles","attribute","styleString","getAttribute","handleClass","acc","classNames","attributesToMap","style","className","MARK_TAGS","b","em","u","code","strong","marks","deserialize","next","mark","tagName","toLowerCase","object","nodes","childNodes","rules","nodeType","leaves","text","textContent","normalAttrs","allAttrs","reduce","isMath","data","dataset","html","Html","defaultBlock","toJSON"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,oCAAN,CAAZ;AAEA,IAAMC,MAAM,GAAG,CAAC,MAAD,CAAf;AACA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ACoD;AAAX,SAAD;AAFH,OAAP;AAID;;AAED,QAAM1C,IAAI,GAAGV,EAAE,CAAC2C,OAAH,CAAWC,WAAX,EAAb;AAEA,QAAMS,WAAW,GAAGtD,IAAI,CAACC,EAAD,CAAJ,IAAY,EAAhC;AACA,QAAMsD,QAAQ,GAAGrD,UAAU,CAACsD,MAAX,CAAkBzB,eAAe,CAAC9B,EAAD,CAAjC,oBAA4CqD,WAA5C,EAAjB;AACA,QAAMR,MAAM,GAAGpC,SAAS,CAACC,IAAD,CAAxB;;AAEA,QAAIV,EAAE,CAAC2C,OAAH,CAAWC,WAAX,OAA6B,MAAjC,EAAyC;AACvC,aAAO;AACLY,QAAAA,MAAM,EAAE,IADH;AAELV,QAAAA,KAAK,EAAE,CAAC9C,EAAD;AAFF,OAAP;AAID;;AAED,WAAO;AACL6C,MAAAA,MAAM,EAANA,MADK;AAELnC,MAAAA,IAAI,EAAJA,IAFK;AAGL+C,MAAAA,IAAI,EAAE;AAAEC,QAAAA,OAAO,oBAAO1D,EAAE,CAAC0D,OAAV,CAAT;AAA8BzD,QAAAA,UAAU,oBAAOqD,QAAP;AAAxC,OAHD;AAILR,MAAAA,KAAK,EAAEL,IAAI,CAACzC,EAAE,CAAC+C,UAAJ;AAJN,KAAP;AAMD;AAnCH,CAFY,CAAd;AAyCA;AACA;AACA;AACA;;AACA,IAAMY,IAAI,GAAG,IAAIC,+BAAJ,CAAS;AAAEZ,EAAAA,KAAK,EAALA,KAAF;AAASa,EAAAA,YAAY,EAAE;AAAvB,CAAT,CAAb;;AAEO,IAAMrB,WAAW,GAAG,SAAdA,WAAc,CAAA3B,CAAC;AAAA,SAAI8C,IAAI,CAACnB,WAAL,CAAiB3B,CAAjB,EAAoB;AAAEiD,IAAAA,MAAM,EAAE;AAAV,GAApB,CAAJ;AAAA,CAArB","sourcesContent":["import React from 'react';\nimport Html from 'slate-html-serializer';\nimport { object as toStyleObject } from 'to-style';\nimport debug from 'debug';\n\nconst log = debug('@pie-lib:mask-markup:serialization');\n\nconst INLINE = ['span'];\nconst MARK = ['em', 'strong', 'u'];\nconst TEXT_NODE = 3;\nconst COMMENT_NODE = 8;\n\nconst attr = el => {\n if (!el.attributes || el.attributes.length <= 0) {\n return undefined;\n }\n\n const out = {};\n let i;\n\n for (i = 0; i < el.attributes.length; i++) {\n const a = el.attributes[i];\n\n out[a.name] = a.value;\n }\n\n return out;\n};\n\nconst getObject = type => {\n if (INLINE.includes(type)) {\n return 'inline';\n } else if (MARK.includes(type)) {\n return 'mark';\n }\n return 'block';\n};\n\nexport const parseStyleString = s => {\n const regex = /([\\w-]*)\\s*:\\s*([^;]*)/g;\n let match;\n const result = {};\n while ((match = regex.exec(s))) {\n result[match[1]] = match[2].trim();\n }\n return result;\n};\n\nexport const reactAttributes = o => toStyleObject(o, { camelize: true, addUnits: false });\n\nconst handleStyles = (el, attribute) => {\n const styleString = el.getAttribute(attribute);\n\n return reactAttributes(parseStyleString(styleString));\n};\n\nconst handleClass = (el, acc, attribute) => {\n const classNames = el.getAttribute(attribute);\n\n delete acc.class;\n\n return classNames;\n};\n\nconst attributesToMap = el => (acc, attribute) => {\n if (!el.getAttribute) {\n return acc;\n }\n\n const value = el.getAttribute(attribute);\n\n if (value) {\n switch (attribute) {\n case 'style':\n acc.style = handleStyles(el, attribute);\n break;\n case 'class':\n acc.className = handleClass(el, acc, attribute);\n break;\n default:\n acc[attribute] = el.getAttribute(attribute);\n break;\n }\n }\n\n return acc;\n};\n\nconst attributes = ['border', 'class', 'style'];\n\n/**\n * Tags to marks.\n *\n * @type {Object}\n */\n\nexport const MARK_TAGS = {\n b: 'bold',\n em: 'italic',\n u: 'underline',\n s: 'strikethrough',\n code: 'code',\n strong: 'strong'\n};\n\nconst marks = {\n deserialize(el, next) {\n const mark = MARK_TAGS[el.tagName.toLowerCase()];\n if (!mark) return;\n log('[deserialize] mark: ', mark);\n return {\n object: 'mark',\n type: mark,\n nodes: next(el.childNodes)\n };\n }\n};\n\nconst rules = [\n marks,\n {\n /**\n * deserialize everything, we're not fussy about the dom structure for now.\n */\n deserialize: (el, next) => {\n if (el.nodeType === COMMENT_NODE) {\n return undefined;\n }\n\n if (el.nodeType === TEXT_NODE) {\n return {\n object: 'text',\n leaves: [{ text: el.textContent }]\n };\n }\n\n const type = el.tagName.toLowerCase();\n\n const normalAttrs = attr(el) || {};\n const allAttrs = attributes.reduce(attributesToMap(el), { ...normalAttrs });\n const object = getObject(type);\n\n if (el.tagName.toLowerCase() === 'math') {\n return {\n isMath: true,\n nodes: [el]\n };\n }\n\n return {\n object,\n type,\n data: { dataset: { ...el.dataset }, attributes: { ...allAttrs } },\n nodes: next(el.childNodes)\n };\n }\n }\n];\n\n/**\n * Create a new serializer instance with our `rules` from above.\n * Having a default div block will just put every div on it's own line, which is not ideal.\n */\nconst html = new Html({ rules, defaultBlock: 'span' });\n\nexport const deserialize = s => html.deserialize(s, { toJSON: true });\n"],"file":"serialization.js"}
|
package/lib/with-mask.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -17,23 +19,25 @@ var _serialization = require("./serialization");
|
|
|
17
19
|
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
21
|
|
|
20
|
-
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
21
|
-
|
|
22
22
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
23
|
|
|
24
24
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
25
25
|
|
|
26
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
26
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
27
27
|
|
|
28
|
-
function
|
|
28
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
29
29
|
|
|
30
|
-
function
|
|
30
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
31
31
|
|
|
32
|
-
function
|
|
32
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
33
33
|
|
|
34
|
-
function
|
|
34
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
35
35
|
|
|
36
|
-
function
|
|
36
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
37
|
+
|
|
38
|
+
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; } }
|
|
39
|
+
|
|
40
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
37
41
|
|
|
38
42
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
39
43
|
|
|
@@ -48,17 +52,17 @@ var buildLayoutFromMarkup = function buildLayoutFromMarkup(markup, type) {
|
|
|
48
52
|
exports.buildLayoutFromMarkup = buildLayoutFromMarkup;
|
|
49
53
|
|
|
50
54
|
var withMask = function withMask(type, renderChildren) {
|
|
51
|
-
var _class
|
|
55
|
+
var _class;
|
|
52
56
|
|
|
53
|
-
return
|
|
54
|
-
/*#__PURE__*/
|
|
55
|
-
function (_React$Component) {
|
|
57
|
+
return _class = /*#__PURE__*/function (_React$Component) {
|
|
56
58
|
_inherits(WithMask, _React$Component);
|
|
57
59
|
|
|
60
|
+
var _super = _createSuper(WithMask);
|
|
61
|
+
|
|
58
62
|
function WithMask() {
|
|
59
63
|
_classCallCheck(this, WithMask);
|
|
60
64
|
|
|
61
|
-
return
|
|
65
|
+
return _super.apply(this, arguments);
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
_createClass(WithMask, [{
|
|
@@ -70,7 +74,7 @@ var withMask = function withMask(type, renderChildren) {
|
|
|
70
74
|
value = _this$props.value,
|
|
71
75
|
onChange = _this$props.onChange;
|
|
72
76
|
var maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);
|
|
73
|
-
return _react["default"].createElement(_mask["default"], {
|
|
77
|
+
return /*#__PURE__*/_react["default"].createElement(_mask["default"], {
|
|
74
78
|
layout: maskLayout,
|
|
75
79
|
value: value,
|
|
76
80
|
onChange: onChange,
|
|
@@ -92,7 +96,7 @@ var withMask = function withMask(type, renderChildren) {
|
|
|
92
96
|
layout: _propTypes["default"].object,
|
|
93
97
|
value: _propTypes["default"].object,
|
|
94
98
|
onChange: _propTypes["default"].func
|
|
95
|
-
}),
|
|
99
|
+
}), _class;
|
|
96
100
|
};
|
|
97
101
|
|
|
98
102
|
exports.withMask = withMask;
|
package/lib/with-mask.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/with-mask.jsx"],"names":["buildLayoutFromMarkup","markup","type","processed","value","document","withMask","renderChildren","props","layout","onChange","maskLayout","React","Component","PropTypes","string","object","func"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/with-mask.jsx"],"names":["buildLayoutFromMarkup","markup","type","processed","value","document","withMask","renderChildren","props","layout","onChange","maskLayout","React","Component","PropTypes","string","object","func"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;AAEO,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,MAAD,EAASC,IAAT,EAAkB;AACrD,sBAA8B,+BAAaD,MAAb,EAAqBC,IAArB,CAA9B;AAAA,MAAgBC,SAAhB,iBAAQF,MAAR;;AACA,MAAMG,KAAK,GAAG,gCAAYD,SAAZ,CAAd;AACA,SAAOC,KAAK,CAACC,QAAb;AACD,CAJM;;;;AAMA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACJ,IAAD,EAAOK,cAAP,EAA0B;AAAA;;AAChD;AAAA;;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA,aAcE,kBAAS;AACP,0BAA4C,KAAKC,KAAjD;AAAA,YAAQP,MAAR,eAAQA,MAAR;AAAA,YAAgBQ,MAAhB,eAAgBA,MAAhB;AAAA,YAAwBL,KAAxB,eAAwBA,KAAxB;AAAA,YAA+BM,QAA/B,eAA+BA,QAA/B;AAEA,YAAMC,UAAU,GAAGF,MAAM,GAAGA,MAAH,GAAYT,qBAAqB,CAACC,MAAD,EAASC,IAAT,CAA1D;AACA,4BACE,gCAAC,gBAAD;AACE,UAAA,MAAM,EAAES,UADV;AAEE,UAAA,KAAK,EAAEP,KAFT;AAGE,UAAA,QAAQ,EAAEM,QAHZ;AAIE,UAAA,cAAc,EAAEH,cAAc,CAAC,KAAKC,KAAN;AAJhC,UADF;AAQD;AA1BH;;AAAA;AAAA,IAA8BI,kBAAMC,SAApC,wCACqB;AACjB;AACN;AACA;AACMZ,IAAAA,MAAM,EAAEa,sBAAUC,MAJD;;AAKjB;AACN;AACA;AACMN,IAAAA,MAAM,EAAEK,sBAAUE,MARD;AASjBZ,IAAAA,KAAK,EAAEU,sBAAUE,MATA;AAUjBN,IAAAA,QAAQ,EAAEI,sBAAUG;AAVH,GADrB;AA4BD,CA7BM","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport Mask from './mask';\nimport componentize from './componentize';\nimport { deserialize } from './serialization';\n\nexport const buildLayoutFromMarkup = (markup, type) => {\n const { markup: processed } = componentize(markup, type);\n const value = deserialize(processed);\n return value.document;\n};\n\nexport const withMask = (type, renderChildren) => {\n return class WithMask extends React.Component {\n static propTypes = {\n /**\n * At the start we'll probably work with markup\n */\n markup: PropTypes.string,\n /**\n * Once we start authoring, it may make sense for use to us layout, which will be a simple js object that maps to `slate.Value`.\n */\n layout: PropTypes.object,\n value: PropTypes.object,\n onChange: PropTypes.func\n };\n\n render() {\n const { markup, layout, value, onChange } = this.props;\n\n const maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);\n return (\n <Mask\n layout={maskLayout}\n value={value}\n onChange={onChange}\n renderChildren={renderChildren(this.props)}\n />\n );\n }\n };\n};\n"],"file":"with-mask.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/mask-markup",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@material-ui/core": "^3.9.3",
|
|
12
12
|
"@pie-lib/drag": "^1.1.52",
|
|
13
|
-
"@pie-lib/math-rendering": "^2.3.
|
|
14
|
-
"@pie-lib/render-ui": "^4.12.
|
|
13
|
+
"@pie-lib/math-rendering": "^2.3.12",
|
|
14
|
+
"@pie-lib/render-ui": "^4.12.4",
|
|
15
15
|
"classnames": "^2.2.6",
|
|
16
16
|
"debug": "^4.1.1",
|
|
17
17
|
"immutable": ">=3.8.1",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"keywords": [],
|
|
28
28
|
"author": "",
|
|
29
29
|
"license": "ISC",
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "94d3f4ebeac61ccfff87705594a1e80f664d4975"
|
|
31
31
|
}
|
|
@@ -30,6 +30,9 @@ export default withStyles(() => ({
|
|
|
30
30
|
borderColor: color.primaryDark()
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
+
crInput: {
|
|
34
|
+
padding: '8px !important'
|
|
35
|
+
},
|
|
33
36
|
correct: correctStyle(color.correct()),
|
|
34
37
|
incorrect: correctStyle(color.incorrect()),
|
|
35
38
|
box: {
|
|
@@ -46,17 +49,24 @@ export default withStyles(() => ({
|
|
|
46
49
|
borderColor: color.correct()
|
|
47
50
|
}
|
|
48
51
|
}))(props => {
|
|
49
|
-
const {
|
|
52
|
+
const {
|
|
53
|
+
correct,
|
|
54
|
+
charactersLimit,
|
|
55
|
+
classes,
|
|
56
|
+
disabled,
|
|
57
|
+
isBox,
|
|
58
|
+
isConstructedResponse,
|
|
59
|
+
width,
|
|
60
|
+
...rest
|
|
61
|
+
} = props;
|
|
50
62
|
const label = typeof correct === 'boolean' ? (correct ? 'correct' : 'incorrect') : undefined;
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
: {};
|
|
63
|
+
const inputProps = charactersLimit ? { maxLength: charactersLimit } : {};
|
|
64
|
+
|
|
65
|
+
if (width) {
|
|
66
|
+
inputProps.style = {
|
|
67
|
+
width: `${width + Math.round(width / 10) + 1}ch` // added some extra space for capital letters
|
|
68
|
+
};
|
|
69
|
+
}
|
|
60
70
|
|
|
61
71
|
return (
|
|
62
72
|
<OutlinedInput
|
|
@@ -66,7 +76,11 @@ export default withStyles(() => ({
|
|
|
66
76
|
[classes.outlinedInput]: true
|
|
67
77
|
})}
|
|
68
78
|
classes={{
|
|
69
|
-
input: classnames({
|
|
79
|
+
input: classnames({
|
|
80
|
+
[classes.input]: true,
|
|
81
|
+
[classes[label]]: label,
|
|
82
|
+
[classes.crInput]: isConstructedResponse
|
|
83
|
+
})
|
|
70
84
|
}}
|
|
71
85
|
inputProps={inputProps}
|
|
72
86
|
labelWidth={0}
|
package/src/components/input.jsx
CHANGED
|
@@ -2,21 +2,34 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import CorrectInput from './correct-input';
|
|
4
4
|
|
|
5
|
-
const Input = ({
|
|
5
|
+
const Input = ({
|
|
6
|
+
disabled,
|
|
7
|
+
correct,
|
|
8
|
+
charactersLimit,
|
|
9
|
+
id,
|
|
10
|
+
isConstructedResponse,
|
|
11
|
+
value,
|
|
12
|
+
onChange,
|
|
13
|
+
showCorrectAnswer,
|
|
14
|
+
width
|
|
15
|
+
}) => {
|
|
6
16
|
return (
|
|
7
17
|
<CorrectInput
|
|
8
18
|
disabled={disabled}
|
|
9
19
|
correct={showCorrectAnswer || correct}
|
|
20
|
+
charactersLimit={charactersLimit}
|
|
10
21
|
variant="outlined"
|
|
11
22
|
value={value}
|
|
23
|
+
isConstructedResponse={isConstructedResponse}
|
|
12
24
|
isBox={true}
|
|
13
|
-
|
|
25
|
+
width={width}
|
|
14
26
|
onChange={e => {
|
|
15
27
|
onChange(id, e.target.value);
|
|
16
28
|
}}
|
|
17
29
|
/>
|
|
18
30
|
);
|
|
19
31
|
};
|
|
32
|
+
|
|
20
33
|
Input.propTypes = {
|
|
21
34
|
id: PropTypes.string,
|
|
22
35
|
value: PropTypes.string,
|
|
@@ -5,12 +5,13 @@ import { withMask } from './with-mask';
|
|
|
5
5
|
export default withMask('input', props => (node, data, onChange) => {
|
|
6
6
|
const dataset = node.data ? node.data.dataset || {} : {};
|
|
7
7
|
if (dataset.component === 'input') {
|
|
8
|
-
const { disabled, feedback, showCorrectAnswer, maxLength } = props;
|
|
8
|
+
const { adjustedLimit, disabled, feedback, showCorrectAnswer, maxLength } = props;
|
|
9
9
|
// the first answer is the correct one
|
|
10
10
|
const correctAnswer = ((props.choices && dataset && props.choices[dataset.id]) || [])[0];
|
|
11
11
|
const finalValue = showCorrectAnswer
|
|
12
12
|
? correctAnswer && correctAnswer.label
|
|
13
13
|
: data[dataset.id] || '';
|
|
14
|
+
const width = maxLength && maxLength[dataset.id];
|
|
14
15
|
|
|
15
16
|
return (
|
|
16
17
|
<Input
|
|
@@ -21,7 +22,9 @@ export default withMask('input', props => (node, data, onChange) => {
|
|
|
21
22
|
id={dataset.id}
|
|
22
23
|
onChange={onChange}
|
|
23
24
|
showCorrectAnswer={showCorrectAnswer}
|
|
24
|
-
|
|
25
|
+
width={width}
|
|
26
|
+
charactersLimit={adjustedLimit ? width : 25}
|
|
27
|
+
isConstructedResponse={true}
|
|
25
28
|
/>
|
|
26
29
|
);
|
|
27
30
|
}
|
package/src/mask.jsx
CHANGED
|
@@ -44,6 +44,13 @@ export const renderChildren = (layout, value, onChange, rootRenderChildren, pare
|
|
|
44
44
|
(layout.nodes || []).forEach((n, index) => {
|
|
45
45
|
const key = `${n.type}-${index}`;
|
|
46
46
|
|
|
47
|
+
if (n.isMath) {
|
|
48
|
+
children.push(
|
|
49
|
+
<span dangerouslySetInnerHTML={{ __html: `<math>${n.nodes[0].innerHTML}</math>` }} />
|
|
50
|
+
);
|
|
51
|
+
return children;
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
if (rootRenderChildren) {
|
|
48
55
|
const c = rootRenderChildren(n, value, onChange);
|
|
49
56
|
if (c) {
|
|
@@ -95,6 +102,12 @@ export const renderChildren = (layout, value, onChange, rootRenderChildren, pare
|
|
|
95
102
|
return children;
|
|
96
103
|
};
|
|
97
104
|
|
|
105
|
+
const MaskContainer = withStyles(() => ({
|
|
106
|
+
main: {
|
|
107
|
+
display: 'inherit'
|
|
108
|
+
}
|
|
109
|
+
}))(props => <div className={props.classes.main}>{props.children}</div>);
|
|
110
|
+
|
|
98
111
|
/**
|
|
99
112
|
* Renders a layout that uses the slate.js Value model structure.
|
|
100
113
|
*/
|
|
@@ -115,6 +128,6 @@ export default class Mask extends React.Component {
|
|
|
115
128
|
const { value, layout } = this.props;
|
|
116
129
|
const children = renderChildren(layout, value, this.handleChange, this.props.renderChildren);
|
|
117
130
|
|
|
118
|
-
return <
|
|
131
|
+
return <MaskContainer>{children}</MaskContainer>;
|
|
119
132
|
}
|
|
120
133
|
}
|
package/src/serialization.js
CHANGED
|
@@ -46,7 +46,7 @@ export const parseStyleString = s => {
|
|
|
46
46
|
return result;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
export const reactAttributes = o => toStyleObject(o, { camelize: true });
|
|
49
|
+
export const reactAttributes = o => toStyleObject(o, { camelize: true, addUnits: false });
|
|
50
50
|
|
|
51
51
|
const handleStyles = (el, attribute) => {
|
|
52
52
|
const styleString = el.getAttribute(attribute);
|
|
@@ -140,6 +140,13 @@ const rules = [
|
|
|
140
140
|
const allAttrs = attributes.reduce(attributesToMap(el), { ...normalAttrs });
|
|
141
141
|
const object = getObject(type);
|
|
142
142
|
|
|
143
|
+
if (el.tagName.toLowerCase() === 'math') {
|
|
144
|
+
return {
|
|
145
|
+
isMath: true,
|
|
146
|
+
nodes: [el]
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
143
150
|
return {
|
|
144
151
|
object,
|
|
145
152
|
type,
|