@pie-lib/mask-markup 3.1.3 → 4.0.0-next.37
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/dist/_virtual/_rolldown/runtime.js +4 -0
- package/dist/choices/choice.d.ts +28 -0
- package/dist/choices/choice.js +92 -0
- package/dist/choices/index.d.ts +29 -0
- package/dist/choices/index.js +59 -0
- package/dist/componentize.d.ts +12 -0
- package/dist/componentize.js +4 -0
- package/dist/components/blank.d.ts +45 -0
- package/dist/components/blank.js +273 -0
- package/dist/components/correct-input.d.ts +11 -0
- package/dist/components/dropdown.d.ts +37 -0
- package/dist/components/dropdown.js +311 -0
- package/dist/components/input.d.ts +37 -0
- package/dist/constructed-response.d.ts +44 -0
- package/dist/constructed-response.js +56 -0
- package/dist/customizable.d.ts +43 -0
- package/dist/customizable.js +8 -0
- package/dist/drag-in-the-blank.d.ts +47 -0
- package/dist/drag-in-the-blank.js +220 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +7 -0
- package/dist/inline-dropdown.d.ts +44 -0
- package/dist/inline-dropdown.js +24 -0
- package/dist/keyboard-coordinates.d.ts +25 -0
- package/dist/keyboard-coordinates.js +49 -0
- package/dist/mask.d.ts +30 -0
- package/dist/mask.js +95 -0
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/index.js +17 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssPrefix.js +9 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssUnitless.js +26 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/hasOwn.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isFunction.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isObject.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixInfo.js +24 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixProperties.js +32 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixer.js +29 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/camelize.js +14 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenRe.js +8 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenate.js +12 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/separate.js +11 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toLowerFirst.js +10 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toUpperFirst.js +10 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleObject.js +55 -0
- package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleString.js +16 -0
- package/dist/serialization.d.ts +34 -0
- package/dist/serialization.js +132 -0
- package/dist/with-mask.d.ts +55 -0
- package/dist/with-mask.js +45 -0
- package/package.json +35 -19
- package/CHANGELOG.json +0 -17
- package/CHANGELOG.md +0 -1353
- package/LICENSE.md +0 -5
- package/lib/choices/choice.js +0 -138
- package/lib/choices/choice.js.map +0 -1
- package/lib/choices/index.js +0 -126
- package/lib/choices/index.js.map +0 -1
- package/lib/componentize.js +0 -21
- package/lib/componentize.js.map +0 -1
- package/lib/components/blank.js +0 -489
- package/lib/components/blank.js.map +0 -1
- package/lib/components/correct-input.js +0 -94
- package/lib/components/correct-input.js.map +0 -1
- package/lib/components/dropdown.js +0 -480
- package/lib/components/dropdown.js.map +0 -1
- package/lib/components/input.js +0 -50
- package/lib/components/input.js.map +0 -1
- package/lib/constructed-response.js +0 -101
- package/lib/constructed-response.js.map +0 -1
- package/lib/customizable.js +0 -42
- package/lib/customizable.js.map +0 -1
- package/lib/drag-in-the-blank.js +0 -363
- package/lib/drag-in-the-blank.js.map +0 -1
- package/lib/index.js +0 -55
- package/lib/index.js.map +0 -1
- package/lib/inline-dropdown.js +0 -40
- package/lib/inline-dropdown.js.map +0 -1
- package/lib/keyboard-coordinates.js +0 -156
- package/lib/keyboard-coordinates.js.map +0 -1
- package/lib/mask.js +0 -203
- package/lib/mask.js.map +0 -1
- package/lib/serialization.js +0 -261
- package/lib/serialization.js.map +0 -1
- package/lib/with-mask.js +0 -97
- package/lib/with-mask.js.map +0 -1
- package/src/__tests__/drag-in-the-blank.test.js +0 -256
- package/src/__tests__/index.test.js +0 -38
- package/src/__tests__/keyboard-coordinates.test.js +0 -202
- package/src/__tests__/mask.test.js +0 -479
- package/src/__tests__/serialization.test.js +0 -54
- package/src/__tests__/utils.js +0 -1
- package/src/__tests__/with-mask.test.js +0 -76
- package/src/choices/__tests__/index.test.js +0 -212
- package/src/choices/choice.jsx +0 -113
- package/src/choices/index.jsx +0 -88
- package/src/componentize.js +0 -13
- package/src/components/__tests__/blank.test.js +0 -413
- package/src/components/__tests__/correct-input.test.js +0 -90
- package/src/components/__tests__/dropdown.test.js +0 -129
- package/src/components/__tests__/input.test.js +0 -102
- package/src/components/blank.jsx +0 -504
- package/src/components/correct-input.jsx +0 -82
- package/src/components/dropdown.jsx +0 -421
- package/src/components/input.jsx +0 -48
- package/src/constructed-response.jsx +0 -87
- package/src/customizable.jsx +0 -34
- package/src/drag-in-the-blank.jsx +0 -351
- package/src/index.js +0 -16
- package/src/inline-dropdown.jsx +0 -29
- package/src/keyboard-coordinates.js +0 -147
- package/src/mask.jsx +0 -174
- package/src/serialization.js +0 -260
- package/src/with-mask.jsx +0 -75
package/lib/serialization.js
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.reactAttributes = exports.parseStyleString = exports.deserialize = exports.MARK_TAGS = void 0;
|
|
8
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
-
var _toStyle = require("to-style");
|
|
11
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
12
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
|
-
var log = (0, _debug["default"])('@pie-lib:mask-markup:serialization');
|
|
15
|
-
var INLINE = ['span'];
|
|
16
|
-
var MARK = ['em', 'strong', 'u'];
|
|
17
|
-
var TEXT_NODE = 3;
|
|
18
|
-
var COMMENT_NODE = 8;
|
|
19
|
-
var ELEMENT_NODE = 1;
|
|
20
|
-
var attr = function attr(el) {
|
|
21
|
-
if (!el.attributes || el.attributes.length <= 0) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
var out = {};
|
|
25
|
-
var i;
|
|
26
|
-
for (i = 0; i < el.attributes.length; i++) {
|
|
27
|
-
var a = el.attributes[i];
|
|
28
|
-
out[a.name] = a.value;
|
|
29
|
-
}
|
|
30
|
-
return out;
|
|
31
|
-
};
|
|
32
|
-
var getObject = function getObject(type) {
|
|
33
|
-
if (INLINE.includes(type)) {
|
|
34
|
-
return 'inline';
|
|
35
|
-
} else if (MARK.includes(type)) {
|
|
36
|
-
return 'mark';
|
|
37
|
-
}
|
|
38
|
-
return 'block';
|
|
39
|
-
};
|
|
40
|
-
var parseStyleString = exports.parseStyleString = function parseStyleString(s) {
|
|
41
|
-
var regex = /([\w-]*)\s*:\s*([^;]*)/g;
|
|
42
|
-
var match;
|
|
43
|
-
var result = {};
|
|
44
|
-
while (match = regex.exec(s)) {
|
|
45
|
-
result[match[1]] = match[2].trim();
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
var reactAttributes = exports.reactAttributes = function reactAttributes(o) {
|
|
50
|
-
return (0, _toStyle.object)(o, {
|
|
51
|
-
camelize: true,
|
|
52
|
-
addUnits: false
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
var handleStyles = function handleStyles(el, attribute) {
|
|
56
|
-
var styleString = el.getAttribute(attribute);
|
|
57
|
-
return reactAttributes(parseStyleString(styleString));
|
|
58
|
-
};
|
|
59
|
-
var handleClass = function handleClass(el, acc, attribute) {
|
|
60
|
-
var classNames = el.getAttribute(attribute);
|
|
61
|
-
delete acc["class"];
|
|
62
|
-
return classNames;
|
|
63
|
-
};
|
|
64
|
-
var attributesToMap = function attributesToMap(el) {
|
|
65
|
-
return function (acc, attribute) {
|
|
66
|
-
if (!el.getAttribute) {
|
|
67
|
-
return acc;
|
|
68
|
-
}
|
|
69
|
-
var value = el.getAttribute(attribute);
|
|
70
|
-
if (value) {
|
|
71
|
-
switch (attribute) {
|
|
72
|
-
case 'style':
|
|
73
|
-
acc.style = handleStyles(el, attribute);
|
|
74
|
-
break;
|
|
75
|
-
case 'class':
|
|
76
|
-
acc.className = handleClass(el, acc, attribute);
|
|
77
|
-
break;
|
|
78
|
-
default:
|
|
79
|
-
acc[attribute] = el.getAttribute(attribute);
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return acc;
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
var attributes = ['border', 'class', 'style'];
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Tags to marks.
|
|
90
|
-
*
|
|
91
|
-
* @type {Object}
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
var MARK_TAGS = exports.MARK_TAGS = {
|
|
95
|
-
b: 'bold',
|
|
96
|
-
em: 'italic',
|
|
97
|
-
u: 'underline',
|
|
98
|
-
s: 'strikethrough',
|
|
99
|
-
code: 'code',
|
|
100
|
-
strong: 'strong'
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Recursively process DOM nodes and convert them to Slate JSON format
|
|
105
|
-
*/
|
|
106
|
-
var processNode = function processNode(node) {
|
|
107
|
-
var marks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
108
|
-
// Skip comment nodes
|
|
109
|
-
if (node.nodeType === COMMENT_NODE) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// Handle text nodes
|
|
114
|
-
if (node.nodeType === TEXT_NODE) {
|
|
115
|
-
var text = node.textContent;
|
|
116
|
-
var leaf = {
|
|
117
|
-
text: text
|
|
118
|
-
};
|
|
119
|
-
if (marks.length > 0) {
|
|
120
|
-
leaf.marks = marks.map(function (m) {
|
|
121
|
-
return {
|
|
122
|
-
type: m,
|
|
123
|
-
data: undefined
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
return {
|
|
128
|
-
object: 'text',
|
|
129
|
-
leaves: [leaf]
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Handle element nodes
|
|
134
|
-
if (node.nodeType === ELEMENT_NODE) {
|
|
135
|
-
var type = node.tagName.toLowerCase();
|
|
136
|
-
|
|
137
|
-
// Check if this is a mark tag
|
|
138
|
-
var markType = MARK_TAGS[type];
|
|
139
|
-
if (markType) {
|
|
140
|
-
log('[deserialize] mark: ', markType);
|
|
141
|
-
// Process children with this mark added and return them flattened
|
|
142
|
-
var _childNodes = processNodes(node.childNodes, [].concat((0, _toConsumableArray2["default"])(marks), [markType]));
|
|
143
|
-
// Return an array indicator with the nodes (will be flattened by parent)
|
|
144
|
-
return {
|
|
145
|
-
_flatten: true,
|
|
146
|
-
nodes: _childNodes
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Handle math elements specially
|
|
151
|
-
if (type === 'math') {
|
|
152
|
-
return {
|
|
153
|
-
isMath: true,
|
|
154
|
-
nodes: [node]
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Process regular elements
|
|
159
|
-
var normalAttrs = attr(node) || {};
|
|
160
|
-
if (type === 'audio' && normalAttrs.controls === '') {
|
|
161
|
-
normalAttrs.controls = true;
|
|
162
|
-
}
|
|
163
|
-
var allAttrs = attributes.reduce(attributesToMap(node), _objectSpread({}, normalAttrs));
|
|
164
|
-
var object = getObject(type);
|
|
165
|
-
var childNodes = processNodes(node.childNodes, marks);
|
|
166
|
-
return {
|
|
167
|
-
object: object,
|
|
168
|
-
type: type,
|
|
169
|
-
data: {
|
|
170
|
-
dataset: _objectSpread({}, node.dataset),
|
|
171
|
-
attributes: _objectSpread({}, allAttrs)
|
|
172
|
-
},
|
|
173
|
-
nodes: childNodes
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
return null;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Process a NodeList and convert to array of Slate nodes
|
|
181
|
-
*/
|
|
182
|
-
var processNodes = function processNodes(nodeList) {
|
|
183
|
-
var marks = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
184
|
-
var nodes = [];
|
|
185
|
-
for (var i = 0; i < nodeList.length; i++) {
|
|
186
|
-
var result = processNode(nodeList[i], marks);
|
|
187
|
-
if (result !== null) {
|
|
188
|
-
// Handle flattening for mark nodes
|
|
189
|
-
if (result._flatten && result.nodes) {
|
|
190
|
-
nodes.push.apply(nodes, (0, _toConsumableArray2["default"])(result.nodes));
|
|
191
|
-
} else {
|
|
192
|
-
nodes.push(result);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return nodes;
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Deserialize HTML string to Slate JSON format
|
|
201
|
-
*/
|
|
202
|
-
var deserialize = exports.deserialize = function deserialize(htmlString) {
|
|
203
|
-
// Handle empty or whitespace-only strings
|
|
204
|
-
if (!htmlString || !htmlString.trim()) {
|
|
205
|
-
return {
|
|
206
|
-
object: 'value',
|
|
207
|
-
document: {
|
|
208
|
-
object: 'document',
|
|
209
|
-
data: {},
|
|
210
|
-
nodes: [{
|
|
211
|
-
object: 'block',
|
|
212
|
-
type: 'span',
|
|
213
|
-
data: {},
|
|
214
|
-
isVoid: false,
|
|
215
|
-
nodes: []
|
|
216
|
-
}]
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Use DOMParser to parse the HTML
|
|
222
|
-
var parser = new DOMParser();
|
|
223
|
-
var doc = parser.parseFromString(htmlString, 'text/html');
|
|
224
|
-
|
|
225
|
-
// Process all nodes in the body
|
|
226
|
-
var nodes = processNodes(doc.body.childNodes);
|
|
227
|
-
|
|
228
|
-
// If we only have text nodes (no block elements), wrap in default span block
|
|
229
|
-
var hasBlockElements = nodes.some(function (node) {
|
|
230
|
-
return node.object === 'block' || node.object === 'inline';
|
|
231
|
-
});
|
|
232
|
-
if (!hasBlockElements && nodes.length > 0) {
|
|
233
|
-
nodes = [{
|
|
234
|
-
object: 'block',
|
|
235
|
-
type: 'span',
|
|
236
|
-
data: {},
|
|
237
|
-
isVoid: false,
|
|
238
|
-
nodes: nodes
|
|
239
|
-
}];
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// If no nodes were produced, add a default span block
|
|
243
|
-
if (nodes.length === 0) {
|
|
244
|
-
nodes = [{
|
|
245
|
-
object: 'block',
|
|
246
|
-
type: 'span',
|
|
247
|
-
data: {},
|
|
248
|
-
isVoid: false,
|
|
249
|
-
nodes: []
|
|
250
|
-
}];
|
|
251
|
-
}
|
|
252
|
-
return {
|
|
253
|
-
object: 'value',
|
|
254
|
-
document: {
|
|
255
|
-
object: 'document',
|
|
256
|
-
data: {},
|
|
257
|
-
nodes: nodes
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
};
|
|
261
|
-
//# sourceMappingURL=serialization.js.map
|
package/lib/serialization.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serialization.js","names":["_toStyle","require","_debug","_interopRequireDefault","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","log","debug","INLINE","MARK","TEXT_NODE","COMMENT_NODE","ELEMENT_NODE","attr","el","attributes","undefined","out","i","a","name","value","getObject","type","includes","parseStyleString","exports","s","regex","match","result","exec","trim","reactAttributes","toStyleObject","camelize","addUnits","handleStyles","attribute","styleString","getAttribute","handleClass","acc","classNames","attributesToMap","style","className","MARK_TAGS","b","em","u","code","strong","processNode","node","marks","nodeType","text","textContent","leaf","map","m","data","object","leaves","tagName","toLowerCase","markType","childNodes","processNodes","concat","_toConsumableArray2","_flatten","nodes","isMath","normalAttrs","controls","allAttrs","reduce","dataset","nodeList","deserialize","htmlString","document","isVoid","parser","DOMParser","doc","parseFromString","body","hasBlockElements","some"],"sources":["../src/serialization.js"],"sourcesContent":["import { 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;\nconst ELEMENT_NODE = 1;\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\n/**\n * Recursively process DOM nodes and convert them to Slate JSON format\n */\nconst processNode = (node, marks = []) => {\n // Skip comment nodes\n if (node.nodeType === COMMENT_NODE) {\n return null;\n }\n\n // Handle text nodes\n if (node.nodeType === TEXT_NODE) {\n const text = node.textContent;\n const leaf = { text };\n\n if (marks.length > 0) {\n leaf.marks = marks.map((m) => ({ type: m, data: undefined }));\n }\n\n return {\n object: 'text',\n leaves: [leaf],\n };\n }\n\n // Handle element nodes\n if (node.nodeType === ELEMENT_NODE) {\n const type = node.tagName.toLowerCase();\n\n // Check if this is a mark tag\n const markType = MARK_TAGS[type];\n if (markType) {\n log('[deserialize] mark: ', markType);\n // Process children with this mark added and return them flattened\n const childNodes = processNodes(node.childNodes, [...marks, markType]);\n // Return an array indicator with the nodes (will be flattened by parent)\n return { _flatten: true, nodes: childNodes };\n }\n\n // Handle math elements specially\n if (type === 'math') {\n return {\n isMath: true,\n nodes: [node],\n };\n }\n\n // Process regular elements\n const normalAttrs = attr(node) || {};\n\n if (type === 'audio' && normalAttrs.controls === '') {\n normalAttrs.controls = true;\n }\n\n const allAttrs = attributes.reduce(attributesToMap(node), { ...normalAttrs });\n const object = getObject(type);\n\n const childNodes = processNodes(node.childNodes, marks);\n\n return {\n object,\n type,\n data: { dataset: { ...node.dataset }, attributes: { ...allAttrs } },\n nodes: childNodes,\n };\n }\n\n return null;\n};\n\n/**\n * Process a NodeList and convert to array of Slate nodes\n */\nconst processNodes = (nodeList, marks = []) => {\n const nodes = [];\n for (let i = 0; i < nodeList.length; i++) {\n const result = processNode(nodeList[i], marks);\n if (result !== null) {\n // Handle flattening for mark nodes\n if (result._flatten && result.nodes) {\n nodes.push(...result.nodes);\n } else {\n nodes.push(result);\n }\n }\n }\n return nodes;\n};\n\n/**\n * Deserialize HTML string to Slate JSON format\n */\nexport const deserialize = (htmlString) => {\n // Handle empty or whitespace-only strings\n if (!htmlString || !htmlString.trim()) {\n return {\n object: 'value',\n document: {\n object: 'document',\n data: {},\n nodes: [\n {\n object: 'block',\n type: 'span',\n data: {},\n isVoid: false,\n nodes: [],\n },\n ],\n },\n };\n }\n\n // Use DOMParser to parse the HTML\n const parser = new DOMParser();\n const doc = parser.parseFromString(htmlString, 'text/html');\n\n // Process all nodes in the body\n let nodes = processNodes(doc.body.childNodes);\n\n // If we only have text nodes (no block elements), wrap in default span block\n const hasBlockElements = nodes.some((node) => node.object === 'block' || node.object === 'inline');\n\n if (!hasBlockElements && nodes.length > 0) {\n nodes = [\n {\n object: 'block',\n type: 'span',\n data: {},\n isVoid: false,\n nodes: nodes,\n },\n ];\n }\n\n // If no nodes were produced, add a default span block\n if (nodes.length === 0) {\n nodes = [\n {\n object: 'block',\n type: 'span',\n data: {},\n isVoid: false,\n nodes: [],\n },\n ];\n }\n\n return {\n object: 'value',\n document: {\n object: 'document',\n data: {},\n nodes,\n },\n };\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA0B,SAAAG,QAAAC,CAAA,EAAAC,CAAA,QAAAC,CAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,OAAAG,MAAA,CAAAE,qBAAA,QAAAC,CAAA,GAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,GAAAC,CAAA,KAAAK,CAAA,GAAAA,CAAA,CAAAC,MAAA,WAAAN,CAAA,WAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,EAAAC,CAAA,EAAAQ,UAAA,OAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,EAAAI,CAAA,YAAAJ,CAAA;AAAA,SAAAU,cAAAZ,CAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAY,SAAA,CAAAC,MAAA,EAAAb,CAAA,UAAAC,CAAA,WAAAW,SAAA,CAAAZ,CAAA,IAAAY,SAAA,CAAAZ,CAAA,QAAAA,CAAA,OAAAF,OAAA,CAAAI,MAAA,CAAAD,CAAA,OAAAa,OAAA,WAAAd,CAAA,QAAAe,gBAAA,aAAAhB,CAAA,EAAAC,CAAA,EAAAC,CAAA,CAAAD,CAAA,SAAAE,MAAA,CAAAc,yBAAA,GAAAd,MAAA,CAAAe,gBAAA,CAAAlB,CAAA,EAAAG,MAAA,CAAAc,yBAAA,CAAAf,CAAA,KAAAH,OAAA,CAAAI,MA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,CAAC,CAAC;MACRW,KAAK,EAALA;IACF;EACF,CAAC;AACH,CAAC","ignoreList":[]}
|
package/lib/with-mask.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.withMask = exports.buildLayoutFromMarkup = void 0;
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
11
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
12
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
13
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
-
var _react = _interopRequireDefault(require("react"));
|
|
15
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
16
|
-
var _mask = _interopRequireDefault(require("./mask"));
|
|
17
|
-
var _componentize2 = _interopRequireDefault(require("./componentize"));
|
|
18
|
-
var _serialization = require("./serialization");
|
|
19
|
-
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
20
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
21
|
-
var buildLayoutFromMarkup = exports.buildLayoutFromMarkup = function buildLayoutFromMarkup(markup, type) {
|
|
22
|
-
var _componentize = (0, _componentize2["default"])(markup, type),
|
|
23
|
-
processed = _componentize.markup;
|
|
24
|
-
var value = (0, _serialization.deserialize)(processed);
|
|
25
|
-
return value.document;
|
|
26
|
-
};
|
|
27
|
-
var withMask = exports.withMask = function withMask(type, renderChildren) {
|
|
28
|
-
var _WithMask;
|
|
29
|
-
return _WithMask = /*#__PURE__*/function (_React$Component) {
|
|
30
|
-
function WithMask(props) {
|
|
31
|
-
var _this;
|
|
32
|
-
(0, _classCallCheck2["default"])(this, WithMask);
|
|
33
|
-
_this = _callSuper(this, WithMask, [props]);
|
|
34
|
-
_this.containerRef = /*#__PURE__*/_react["default"].createRef();
|
|
35
|
-
return _this;
|
|
36
|
-
}
|
|
37
|
-
(0, _inherits2["default"])(WithMask, _React$Component);
|
|
38
|
-
return (0, _createClass2["default"])(WithMask, [{
|
|
39
|
-
key: "componentDidUpdate",
|
|
40
|
-
value: function componentDidUpdate(prevProps) {
|
|
41
|
-
if (this.props.markup !== prevProps.markup) {
|
|
42
|
-
var domNode = this.containerRef.current;
|
|
43
|
-
var mathElements = domNode && domNode.querySelectorAll('[data-latex][data-math-handled="true"]');
|
|
44
|
-
|
|
45
|
-
// Clean up for fresh MathJax processing
|
|
46
|
-
(mathElements || []).forEach(function (el) {
|
|
47
|
-
// Remove the MathJax container to allow for clean updates
|
|
48
|
-
var mjxContainer = el.querySelector('mjx-container');
|
|
49
|
-
if (mjxContainer) {
|
|
50
|
-
el.removeChild(mjxContainer);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Update the innerHTML to match the raw LaTeX data, ensuring it is reprocessed correctly
|
|
54
|
-
var latexCode = el.getAttribute('data-raw');
|
|
55
|
-
el.innerHTML = latexCode;
|
|
56
|
-
|
|
57
|
-
// Remove the attribute to signal that MathJax should reprocess this element
|
|
58
|
-
el.removeAttribute('data-math-handled');
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}, {
|
|
63
|
-
key: "render",
|
|
64
|
-
value: function render() {
|
|
65
|
-
var _this$props = this.props,
|
|
66
|
-
markup = _this$props.markup,
|
|
67
|
-
layout = _this$props.layout,
|
|
68
|
-
value = _this$props.value,
|
|
69
|
-
onChange = _this$props.onChange,
|
|
70
|
-
elementType = _this$props.elementType;
|
|
71
|
-
var maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);
|
|
72
|
-
return /*#__PURE__*/_react["default"].createElement(_mask["default"], {
|
|
73
|
-
containerRef: this.containerRef,
|
|
74
|
-
elementType: elementType,
|
|
75
|
-
layout: maskLayout,
|
|
76
|
-
value: value,
|
|
77
|
-
onChange: onChange,
|
|
78
|
-
renderChildren: renderChildren(this.props)
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}]);
|
|
82
|
-
}(_react["default"].Component), (0, _defineProperty2["default"])(_WithMask, "propTypes", {
|
|
83
|
-
/**
|
|
84
|
-
* At the start we'll probably work with markup
|
|
85
|
-
*/
|
|
86
|
-
markup: _propTypes["default"].string,
|
|
87
|
-
/**
|
|
88
|
-
* 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`.
|
|
89
|
-
*/
|
|
90
|
-
layout: _propTypes["default"].object,
|
|
91
|
-
value: _propTypes["default"].object,
|
|
92
|
-
onChange: _propTypes["default"].func,
|
|
93
|
-
customMarkMarkupComponent: _propTypes["default"].func,
|
|
94
|
-
elementType: _propTypes["default"].string
|
|
95
|
-
}), _WithMask;
|
|
96
|
-
};
|
|
97
|
-
//# sourceMappingURL=with-mask.js.map
|
package/lib/with-mask.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"with-mask.js","names":["_react","_interopRequireDefault","require","_propTypes","_mask","_componentize2","_serialization","_callSuper","t","o","e","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","apply","Boolean","prototype","valueOf","call","buildLayoutFromMarkup","exports","markup","type","_componentize","componentize","processed","value","deserialize","document","withMask","renderChildren","_WithMask","_React$Component","WithMask","props","_this","_classCallCheck2","containerRef","React","createRef","_inherits2","_createClass2","key","componentDidUpdate","prevProps","domNode","current","mathElements","querySelectorAll","forEach","el","mjxContainer","querySelector","removeChild","latexCode","getAttribute","innerHTML","removeAttribute","render","_this$props","layout","onChange","elementType","maskLayout","createElement","Component","_defineProperty2","PropTypes","string","object","func","customMarkMarkupComponent"],"sources":["../src/with-mask.jsx"],"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 customMarkMarkupComponent: PropTypes.func,\n elementType: PropTypes.string,\n };\n\n constructor(props) {\n super(props);\n this.containerRef = React.createRef();\n }\n\n componentDidUpdate(prevProps) {\n if (this.props.markup !== prevProps.markup) {\n const domNode = this.containerRef.current;\n const mathElements = domNode && domNode.querySelectorAll('[data-latex][data-math-handled=\"true\"]');\n\n // Clean up for fresh MathJax processing\n (mathElements || []).forEach((el) => {\n // Remove the MathJax container to allow for clean updates\n const mjxContainer = el.querySelector('mjx-container');\n\n if (mjxContainer) {\n el.removeChild(mjxContainer);\n }\n\n // Update the innerHTML to match the raw LaTeX data, ensuring it is reprocessed correctly\n const latexCode = el.getAttribute('data-raw');\n el.innerHTML = latexCode;\n\n // Remove the attribute to signal that MathJax should reprocess this element\n el.removeAttribute('data-math-handled');\n });\n }\n }\n\n render() {\n const { markup, layout, value, onChange, elementType } = this.props;\n\n const maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);\n return (\n <Mask\n containerRef={this.containerRef}\n elementType={elementType}\n layout={maskLayout}\n value={value}\n onChange={onChange}\n renderChildren={renderChildren(this.props)}\n />\n );\n }\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,cAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AAA8C,SAAAK,WAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,WAAAD,CAAA,OAAAE,gBAAA,aAAAF,CAAA,OAAAG,2BAAA,aAAAJ,CAAA,EAAAK,yBAAA,KAAAC,OAAA,CAAAC,SAAA,CAAAN,CAAA,EAAAC,CAAA,YAAAC,gBAAA,aAAAH,CAAA,EAAAQ,WAAA,IAAAP,CAAA,CAAAQ,KAAA,CAAAT,CAAA,EAAAE,CAAA;AAAA,SAAAG,0BAAA,cAAAL,CAAA,IAAAU,OAAA,CAAAC,SAAA,CAAAC,OAAA,CAAAC,IAAA,CAAAP,OAAA,CAAAC,SAAA,CAAAG,OAAA,iCAAAV,CAAA,aAAAK,yBAAA,YAAAA,0BAAA,aAAAL,CAAA;AAEvC,IAAMc,qBAAqB,GAAAC,OAAA,CAAAD,qBAAA,GAAG,SAAxBA,qBAAqBA,CAAIE,MAAM,EAAEC,IAAI,EAAK;EACrD,IAAAC,aAAA,GAA8B,IAAAC,yBAAY,EAACH,MAAM,EAAEC,IAAI,CAAC;IAAxCG,SAAS,GAAAF,aAAA,CAAjBF,MAAM;EACd,IAAMK,KAAK,GAAG,IAAAC,0BAAW,EAACF,SAAS,CAAC;EACpC,OAAOC,KAAK,CAACE,QAAQ;AACvB,CAAC;AAEM,IAAMC,QAAQ,GAAAT,OAAA,CAAAS,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AA3Db,MAAM,GAAAsC,WAAA,CAANtC,MAAM;UAAEuC,MAAM,GAAAD,WAAA,CAANC,MAAM;UAAElC,KAAK,GAAAiC,WAAA,CAALjC,KAAK;UAAEmC,QAAQ,GAAAF,WAAA,CAARE,QAAQ;UAAEC,WAAW,GAAAH,WAAA,CAAXG,WAAW;QAEpD,IAAMC,UAAU,GAAGH,MAAM,GAAGA,MAAM,GAAGzC,qBAAqB,CAACE,MAAM,EAAEC,IAAI,CAAC;QACxE,oBACEzB,MAAA,YAAAmE,aAAA,CAAC/D,KAAA,WAAI;UACHoC,YAAY,EAAE,IAAI,CAACA,YAAa;UAChCyB,WAAW,EAAEA,WAAY;UACzBF,MAAM,EAAEG,UAAW;UACnBrC,KAAK,EAAEA,KAAM;UACbmC,QAAQ,EAAEA,QAAS;UACnB/B,cAAc,EAAEA,cAAc,CAAC,IAAI,CAACI,KAAK;QAAE,CAC5C,CAAC;MAEN;IAAC;EAAA,EA3D2BI,iBAAK,CAAC2B,SAAS,OAAAC,gBAAA,aAAAnC,SAAA,eACxB;IACjB;AACN;AACA;IACMV,MAAM,EAAE8C,qBAAS,CAACC,MAAM;IACxB;AACN;AACA;IACMR,MAAM,EAAEO,qBAAS,CAACE,MAAM;IACxB3C,KAAK,EAAEyC,qBAAS,CAACE,MAAM;IACvBR,QAAQ,EAAEM,qBAAS,CAACG,IAAI;IACxBC,yBAAyB,EAAEJ,qBAAS,CAACG,IAAI;IACzCR,WAAW,EAAEK,qBAAS,CAACC;EACzB,CAAC,GAAArC,SAAA;AA+CL,CAAC","ignoreList":[]}
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { render, screen } from '@testing-library/react';
|
|
3
|
-
import DragInTheBlank from '../drag-in-the-blank';
|
|
4
|
-
import { closestDroppableKeyboardCoordinates } from '../keyboard-coordinates';
|
|
5
|
-
|
|
6
|
-
const markup = `<div>
|
|
7
|
-
<img src="https://image.shutterstock.com/image-vector/cow-jumped-over-moon-traditional-260nw-1152899330.jpg"></img>
|
|
8
|
-
<h5>Hey Diddle Diddle <i>by ?</i></h5>
|
|
9
|
-
<p>1: Hey, diddle, diddle,</p>
|
|
10
|
-
<p>2: The cat and the fiddle,</p>
|
|
11
|
-
<p>3: The cow {{0}} over the moon;</p>
|
|
12
|
-
<p>4: The little dog {{1}},</p>
|
|
13
|
-
<p>5: To see such sport,</p>
|
|
14
|
-
<p>6: And the dish ran away with the {{2}}.</p>
|
|
15
|
-
</div>`;
|
|
16
|
-
const choice = (v, id) => ({ value: v, id });
|
|
17
|
-
|
|
18
|
-
let capturedDragProviderProps;
|
|
19
|
-
|
|
20
|
-
// Mock DragProvider and DragDroppablePlaceholder to avoid DndContext requirement
|
|
21
|
-
jest.mock('@pie-lib/drag', () => ({
|
|
22
|
-
DragProvider: (props) => {
|
|
23
|
-
capturedDragProviderProps = props;
|
|
24
|
-
// Simple wrapper that doesn't require DndContext
|
|
25
|
-
return <div data-testid="drag-provider">{props.children}</div>;
|
|
26
|
-
},
|
|
27
|
-
DragDroppablePlaceholder: ({ children, disabled, instanceId }) => {
|
|
28
|
-
// Simple wrapper that doesn't require useDroppable
|
|
29
|
-
return <div data-testid="drag-droppable-placeholder">{children}</div>;
|
|
30
|
-
},
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
// Mock @dnd-kit/core components and hooks used by DragInTheBlank and child components
|
|
34
|
-
jest.mock('@dnd-kit/core', () => ({
|
|
35
|
-
DragOverlay: ({ children }) => <div data-testid="drag-overlay">{children}</div>,
|
|
36
|
-
closestCenter: jest.fn(),
|
|
37
|
-
useDraggable: jest.fn(() => ({
|
|
38
|
-
attributes: {},
|
|
39
|
-
listeners: {},
|
|
40
|
-
setNodeRef: jest.fn(),
|
|
41
|
-
transform: null,
|
|
42
|
-
isDragging: false,
|
|
43
|
-
})),
|
|
44
|
-
useDroppable: jest.fn(() => ({
|
|
45
|
-
setNodeRef: jest.fn(),
|
|
46
|
-
isOver: false,
|
|
47
|
-
active: null,
|
|
48
|
-
})),
|
|
49
|
-
}));
|
|
50
|
-
|
|
51
|
-
jest.mock('@dnd-kit/utilities', () => ({
|
|
52
|
-
CSS: {
|
|
53
|
-
Translate: {
|
|
54
|
-
toString: jest.fn(() => 'translate3d(0, 0, 0)'),
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
describe('DragInTheBlank', () => {
|
|
60
|
-
const defaultProps = {
|
|
61
|
-
disabled: false,
|
|
62
|
-
feedback: {},
|
|
63
|
-
markup,
|
|
64
|
-
choices: [
|
|
65
|
-
choice('Jumped', '0'),
|
|
66
|
-
choice('Laughed', '1'),
|
|
67
|
-
choice('Spoon', '2'),
|
|
68
|
-
choice('Fork', '3'),
|
|
69
|
-
choice('Bumped', '4'),
|
|
70
|
-
choice('Smiled', '5'),
|
|
71
|
-
],
|
|
72
|
-
|
|
73
|
-
value: {
|
|
74
|
-
0: undefined,
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
describe('render', () => {
|
|
79
|
-
it('renders correctly with default props', () => {
|
|
80
|
-
const { container } = render(<DragInTheBlank {...defaultProps} />);
|
|
81
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
82
|
-
// Check that markup content is rendered
|
|
83
|
-
expect(screen.getByText(/Hey Diddle Diddle/)).toBeInTheDocument();
|
|
84
|
-
expect(screen.getByText(/Hey, diddle, diddle,/)).toBeInTheDocument();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('renders correctly with disabled prop as true', () => {
|
|
88
|
-
const { container } = render(<DragInTheBlank {...defaultProps} disabled={true} />);
|
|
89
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('renders correctly with feedback', () => {
|
|
93
|
-
const { container } = render(
|
|
94
|
-
<DragInTheBlank
|
|
95
|
-
{...defaultProps}
|
|
96
|
-
feedback={{
|
|
97
|
-
0: {
|
|
98
|
-
value: 'Jumped',
|
|
99
|
-
correct: 'Jumped',
|
|
100
|
-
},
|
|
101
|
-
1: {
|
|
102
|
-
value: 'Laughed',
|
|
103
|
-
correct: 'Laughed',
|
|
104
|
-
},
|
|
105
|
-
2: {
|
|
106
|
-
value: 'Spoon',
|
|
107
|
-
correct: 'Spoon',
|
|
108
|
-
},
|
|
109
|
-
}}
|
|
110
|
-
/>,
|
|
111
|
-
);
|
|
112
|
-
expect(container.firstChild).toBeInTheDocument();
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('selection state', () => {
|
|
117
|
-
const baseProps = {
|
|
118
|
-
value: {},
|
|
119
|
-
onChange: jest.fn(),
|
|
120
|
-
choices: [{ id: '0', value: 'firstChoice' }, { id: '1', value: 'secondChoice' }],
|
|
121
|
-
markup: 'text {{0}} more {{1}} end',
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
beforeEach(() => {
|
|
125
|
-
baseProps.onChange.mockClear();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('mirrors an active drag into selectedItem on drag start', () => {
|
|
129
|
-
const instance = new DragInTheBlank(baseProps);
|
|
130
|
-
instance.setState = (s) => Object.assign(instance.state, typeof s === 'function' ? s(instance.state) : s);
|
|
131
|
-
const data = { id: '0', choice: { id: '0', value: 'X' }, fromChoice: false, type: 'MaskBlank' };
|
|
132
|
-
|
|
133
|
-
instance.handleDragStart({ active: { data: { current: data } } });
|
|
134
|
-
|
|
135
|
-
expect(instance.state.selectedItem).toEqual(data);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('toggleItemSelection selects, then deselects the same item', () => {
|
|
139
|
-
const instance = new DragInTheBlank(baseProps);
|
|
140
|
-
instance.setState = (s) => Object.assign(instance.state, typeof s === 'function' ? s(instance.state) : s);
|
|
141
|
-
const data = { choice: { id: '0' }, fromChoice: true, type: 'MaskBlank' };
|
|
142
|
-
|
|
143
|
-
instance.toggleItemSelection(data);
|
|
144
|
-
expect(instance.state.selectedItem).toEqual(data);
|
|
145
|
-
|
|
146
|
-
instance.toggleItemSelection(data);
|
|
147
|
-
expect(instance.state.selectedItem).toBeNull();
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('placeSelectedItem places a pool choice into a blank via commitPlacement/onChange', () => {
|
|
151
|
-
const instance = new DragInTheBlank(baseProps);
|
|
152
|
-
instance.setState = (s) => Object.assign(instance.state, typeof s === 'function' ? s(instance.state) : s);
|
|
153
|
-
const poolChoice = { choice: { id: '0' }, instanceId: 'x', fromChoice: true, type: 'MaskBlank' };
|
|
154
|
-
|
|
155
|
-
instance.toggleItemSelection(poolChoice);
|
|
156
|
-
instance.placeSelectedItem('blank-1');
|
|
157
|
-
|
|
158
|
-
expect(baseProps.onChange).toHaveBeenCalledWith({ 'blank-1': '0' });
|
|
159
|
-
expect(instance.state.selectedItem).toBeNull();
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('placeSelectedItem with targetId undefined removes a placed item (returns it to the board)', () => {
|
|
163
|
-
const props = { ...baseProps, value: { 'blank-1': '0' } };
|
|
164
|
-
const instance = new DragInTheBlank(props);
|
|
165
|
-
instance.setState = (s) => Object.assign(instance.state, typeof s === 'function' ? s(instance.state) : s);
|
|
166
|
-
const placedItem = { id: 'blank-1', choice: { id: '0' }, instanceId: 'x', fromChoice: false, type: 'MaskBlank' };
|
|
167
|
-
|
|
168
|
-
instance.toggleItemSelection(placedItem);
|
|
169
|
-
instance.placeSelectedItem(undefined);
|
|
170
|
-
|
|
171
|
-
expect(props.onChange).toHaveBeenCalledWith({});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('placeSelectedItem does nothing when nothing is selected', () => {
|
|
175
|
-
const instance = new DragInTheBlank(baseProps);
|
|
176
|
-
instance.setState = (s) => Object.assign(instance.state, typeof s === 'function' ? s(instance.state) : s);
|
|
177
|
-
|
|
178
|
-
instance.placeSelectedItem('blank-1');
|
|
179
|
-
|
|
180
|
-
expect(baseProps.onChange).not.toHaveBeenCalled();
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('onItemClick and onPlacementClick are ignored for a short window right after a drag ends', () => {
|
|
184
|
-
const instance = new DragInTheBlank(baseProps);
|
|
185
|
-
instance.setState = (s) => Object.assign(instance.state, typeof s === 'function' ? s(instance.state) : s);
|
|
186
|
-
const data = { choice: { id: '0' }, fromChoice: true, type: 'MaskBlank' };
|
|
187
|
-
|
|
188
|
-
instance.handleDragEnd({ active: null, over: null });
|
|
189
|
-
instance.onItemClick(data);
|
|
190
|
-
|
|
191
|
-
expect(instance.state.selectedItem).toBeNull();
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('onPlacementClick is ignored for a short window right after a drag ends', () => {
|
|
195
|
-
const instance = new DragInTheBlank(baseProps);
|
|
196
|
-
instance.setState = (s) => Object.assign(instance.state, typeof s === 'function' ? s(instance.state) : s);
|
|
197
|
-
const data = { choice: { id: '0' }, fromChoice: true, type: 'MaskBlank' };
|
|
198
|
-
|
|
199
|
-
instance.handleDragEnd({ active: null, over: null });
|
|
200
|
-
// Select an item after the drag-end guard is armed, so placeSelectedItem would
|
|
201
|
-
// have something to place if the guard didn't short-circuit it first.
|
|
202
|
-
instance.toggleItemSelection(data);
|
|
203
|
-
instance.onPlacementClick('blank-1');
|
|
204
|
-
|
|
205
|
-
expect(baseProps.onChange).not.toHaveBeenCalled();
|
|
206
|
-
expect(instance.state.selectedItem).toEqual(data);
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it("onDragEnd dropping a blank's own content back onto its own slot is a no-op", () => {
|
|
210
|
-
const props = { ...baseProps, value: { 'blank-1': '0' } };
|
|
211
|
-
const instance = new DragInTheBlank(props);
|
|
212
|
-
instance.setState = (s) => Object.assign(instance.state, typeof s === 'function' ? s(instance.state) : s);
|
|
213
|
-
const draggedItem = { id: 'blank-1', choice: { id: '0' }, fromChoice: false, type: 'MaskBlank' };
|
|
214
|
-
|
|
215
|
-
instance.handleDragEnd({
|
|
216
|
-
active: { data: { current: draggedItem } },
|
|
217
|
-
over: { data: { current: { id: 'blank-1', accepts: ['MaskBlank'] } } },
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
expect(props.onChange).not.toHaveBeenCalled();
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
describe('DragProvider wiring', () => {
|
|
225
|
-
it('passes the Tab/Shift+Tab coordinate getter and keyboard codes to DragProvider', () => {
|
|
226
|
-
render(
|
|
227
|
-
<DragInTheBlank
|
|
228
|
-
value={{}}
|
|
229
|
-
onChange={jest.fn()}
|
|
230
|
-
choices={[]}
|
|
231
|
-
markup="text {{0}} end"
|
|
232
|
-
/>,
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
expect(capturedDragProviderProps.keyboardCoordinateGetter).toBe(closestDroppableKeyboardCoordinates);
|
|
236
|
-
expect(capturedDragProviderProps.keyboardCodes).toEqual({
|
|
237
|
-
start: ['Space', 'Enter'],
|
|
238
|
-
cancel: ['Escape'],
|
|
239
|
-
end: ['Space', 'Enter'],
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it('passes onDragCancel to DragProvider', () => {
|
|
244
|
-
render(
|
|
245
|
-
<DragInTheBlank
|
|
246
|
-
value={{}}
|
|
247
|
-
onChange={jest.fn()}
|
|
248
|
-
choices={[]}
|
|
249
|
-
markup="text {{0}} end"
|
|
250
|
-
/>,
|
|
251
|
-
);
|
|
252
|
-
|
|
253
|
-
expect(typeof capturedDragProviderProps.onDragCancel).toBe('function');
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
});
|