@pie-element/match-list 7.2.0-beta.0 → 7.2.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 +53 -4
- package/controller/CHANGELOG.md +13 -1
- package/controller/package.json +1 -1
- package/lib/answer-area.js +20 -7
- package/lib/answer-area.js.map +1 -1
- package/lib/answer.js +117 -26
- package/lib/answer.js.map +1 -1
- package/lib/arrow.js +8 -3
- package/lib/arrow.js.map +1 -1
- package/lib/choices-list.js +13 -4
- package/lib/choices-list.js.map +1 -1
- package/lib/droppable-placeholder.js +12 -1
- package/lib/droppable-placeholder.js.map +1 -1
- package/lib/keyboard-coordinates.js +147 -0
- package/lib/keyboard-coordinates.js.map +1 -0
- package/lib/main.js +223 -19
- package/lib/main.js.map +1 -1
- package/package.json +5 -5
package/lib/arrow.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrow.js","names":["_react","_interopRequireDefault","require","_propTypes","_ArrowDropDown","_styles","ArrowContainer","styled","display","position","width","Line","
|
|
1
|
+
{"version":3,"file":"arrow.js","names":["_react","_interopRequireDefault","require","_propTypes","_ArrowDropDown","_styles","_renderUi","ArrowContainer","styled","display","position","width","Line","isRight","backgroundColor","color","border","bottom","content","height","left","Arrow","React","Component","render","direction","props","extraStyle","transform","default","createElement","style","fontSize","exports","_defineProperty2","PropTypes","string","_default"],"sources":["../src/arrow.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport ArrowHead from '@mui/icons-material/ArrowDropDown';\nimport { styled } from '@mui/material/styles';\nimport { color } from '@pie-lib/render-ui';\n\nconst ArrowContainer = styled('div')({\n display: 'inline-block',\n position: 'relative',\n width: '100%',\n});\n\n// A 1px rule joining a prompt to its answer: it is the connector, so it needs to\n// stay perceivable on every scheme's surface.\nconst Line = styled('span')(({ isRight }) => ({\n backgroundColor: color.border(),\n bottom: isRight ? 20 : 19,\n content: '\"\"',\n display: 'block',\n height: 1,\n left: 20,\n position: 'absolute',\n width: '100%',\n}));\n\nexport class Arrow extends React.Component {\n static propTypes = {\n direction: PropTypes.string,\n };\n\n render() {\n const { direction } = this.props;\n\n const extraStyle =\n direction === 'left'\n ? {}\n : {\n transform: 'rotate(180deg)',\n };\n\n return (\n <ArrowContainer style={extraStyle}>\n <ArrowHead\n style={{\n transform: 'rotate(90deg)',\n // Pairs with Line above: head and shaft are one connector and have to\n // step together, or the arrow loses its point on a dark scheme.\n color: color.border(),\n fontSize: 40,\n }}\n />\n <Line isRight={direction !== 'left'} />\n </ArrowContainer>\n );\n }\n}\n\nexport default Arrow;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,cAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AAEA,MAAMK,cAAc,GAAG,IAAAC,cAAM,EAAC,KAAK,CAAC,CAAC;EACnCC,OAAO,EAAE,cAAc;EACvBC,QAAQ,EAAE,UAAU;EACpBC,KAAK,EAAE;AACT,CAAC,CAAC;;AAEF;AACA;AACA,MAAMC,IAAI,GAAG,IAAAJ,cAAM,EAAC,MAAM,CAAC,CAAC,CAAC;EAAEK;AAAQ,CAAC,MAAM;EAC5CC,eAAe,EAAEC,eAAK,CAACC,MAAM,CAAC,CAAC;EAC/BC,MAAM,EAAEJ,OAAO,GAAG,EAAE,GAAG,EAAE;EACzBK,OAAO,EAAE,IAAI;EACbT,OAAO,EAAE,OAAO;EAChBU,MAAM,EAAE,CAAC;EACTC,IAAI,EAAE,EAAE;EACRV,QAAQ,EAAE,UAAU;EACpBC,KAAK,EAAE;AACT,CAAC,CAAC,CAAC;AAEI,MAAMU,KAAK,SAASC,cAAK,CAACC,SAAS,CAAC;EAKzCC,MAAMA,CAAA,EAAG;IACP,MAAM;MAAEC;IAAU,CAAC,GAAG,IAAI,CAACC,KAAK;IAEhC,MAAMC,UAAU,GACdF,SAAS,KAAK,MAAM,GAChB,CAAC,CAAC,GACF;MACEG,SAAS,EAAE;IACb,CAAC;IAEP,oBACE5B,MAAA,CAAA6B,OAAA,CAAAC,aAAA,CAACvB,cAAc;MAACwB,KAAK,EAAEJ;IAAW,gBAChC3B,MAAA,CAAA6B,OAAA,CAAAC,aAAA,CAAC1B,cAAA,CAAAyB,OAAS;MACRE,KAAK,EAAE;QACLH,SAAS,EAAE,eAAe;QAC1B;QACA;QACAb,KAAK,EAAEA,eAAK,CAACC,MAAM,CAAC,CAAC;QACrBgB,QAAQ,EAAE;MACZ;IAAE,CACH,CAAC,eACFhC,MAAA,CAAA6B,OAAA,CAAAC,aAAA,CAAClB,IAAI;MAACC,OAAO,EAAEY,SAAS,KAAK;IAAO,CAAE,CACxB,CAAC;EAErB;AACF;AAACQ,OAAA,CAAAZ,KAAA,GAAAA,KAAA;AAAA,IAAAa,gBAAA,CAAAL,OAAA,EA9BYR,KAAK,eACG;EACjBI,SAAS,EAAEU,kBAAS,CAACC;AACvB,CAAC;AAAA,IAAAC,QAAA,GAAAJ,OAAA,CAAAJ,OAAA,GA6BYR,KAAK","ignoreList":[]}
|
package/lib/choices-list.js
CHANGED
|
@@ -25,7 +25,10 @@ class ChoicesList extends _react.default.Component {
|
|
|
25
25
|
disabled,
|
|
26
26
|
session,
|
|
27
27
|
instanceId,
|
|
28
|
-
onRemoveAnswer
|
|
28
|
+
onRemoveAnswer,
|
|
29
|
+
selectedAnswer,
|
|
30
|
+
onChoiceClick,
|
|
31
|
+
onPlacementClick
|
|
29
32
|
} = this.props;
|
|
30
33
|
const {
|
|
31
34
|
config
|
|
@@ -39,12 +42,15 @@ class ChoicesList extends _react.default.Component {
|
|
|
39
42
|
draggable: true,
|
|
40
43
|
disabled: disabled,
|
|
41
44
|
session: session,
|
|
42
|
-
type: "choice"
|
|
45
|
+
type: "choice",
|
|
46
|
+
selectedAnswer: selectedAnswer,
|
|
47
|
+
onSelectClick: onChoiceClick
|
|
43
48
|
}, answer)));
|
|
44
49
|
return /*#__PURE__*/_react.default.createElement(ChoicesContainer, null, /*#__PURE__*/_react.default.createElement(_droppablePlaceholder.DroppablePlaceholder, {
|
|
45
50
|
id: "choices-pool",
|
|
46
51
|
disabled: disabled,
|
|
47
|
-
onRemoveAnswer: onRemoveAnswer
|
|
52
|
+
onRemoveAnswer: onRemoveAnswer,
|
|
53
|
+
onPlacementClick: onPlacementClick
|
|
48
54
|
}, filteredAnswers));
|
|
49
55
|
}
|
|
50
56
|
}
|
|
@@ -54,7 +60,10 @@ exports.ChoicesList = ChoicesList;
|
|
|
54
60
|
instanceId: _propTypes.default.string.isRequired,
|
|
55
61
|
model: _propTypes.default.object.isRequired,
|
|
56
62
|
disabled: _propTypes.default.bool.isRequired,
|
|
57
|
-
onRemoveAnswer: _propTypes.default.func
|
|
63
|
+
onRemoveAnswer: _propTypes.default.func,
|
|
64
|
+
selectedAnswer: _propTypes.default.object,
|
|
65
|
+
onChoiceClick: _propTypes.default.func,
|
|
66
|
+
onPlacementClick: _propTypes.default.func
|
|
58
67
|
});
|
|
59
68
|
var _default = exports.default = ChoicesList;
|
|
60
69
|
//# sourceMappingURL=choices-list.js.map
|
package/lib/choices-list.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"choices-list.js","names":["_react","_interopRequireDefault","require","_propTypes","_styles","_lodashEs","_answer","_droppablePlaceholder","ChoicesContainer","styled","theme","marginBottom","spacing","ChoicesList","React","Component","render","model","disabled","session","instanceId","onRemoveAnswer","props","config","duplicates","filteredAnswers","answers","filter","answer","isEmpty","value","isUndefined","find","val","id","map","default","createElement","_extends2","key","draggable","type","DroppablePlaceholder","exports","_defineProperty2","PropTypes","object","isRequired","string","bool","func","_default"],"sources":["../src/choices-list.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { styled } from '@mui/material/styles';\nimport { find, isEmpty, isUndefined } from 'lodash-es';\nimport DragAndDropAnswer from './answer';\nimport { DroppablePlaceholder } from './droppable-placeholder';\n\nconst ChoicesContainer = styled('div')(({ theme }) => ({\n marginBottom: theme.spacing(2),\n}));\n\nexport class ChoicesList extends React.Component {\n static propTypes = {\n session: PropTypes.object.isRequired,\n instanceId: PropTypes.string.isRequired,\n model: PropTypes.object.isRequired,\n disabled: PropTypes.bool.isRequired,\n onRemoveAnswer: PropTypes.func,\n };\n\n render() {\n const {
|
|
1
|
+
{"version":3,"file":"choices-list.js","names":["_react","_interopRequireDefault","require","_propTypes","_styles","_lodashEs","_answer","_droppablePlaceholder","ChoicesContainer","styled","theme","marginBottom","spacing","ChoicesList","React","Component","render","model","disabled","session","instanceId","onRemoveAnswer","selectedAnswer","onChoiceClick","onPlacementClick","props","config","duplicates","filteredAnswers","answers","filter","answer","isEmpty","value","isUndefined","find","val","id","map","default","createElement","_extends2","key","draggable","type","onSelectClick","DroppablePlaceholder","exports","_defineProperty2","PropTypes","object","isRequired","string","bool","func","_default"],"sources":["../src/choices-list.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { styled } from '@mui/material/styles';\nimport { find, isEmpty, isUndefined } from 'lodash-es';\nimport DragAndDropAnswer from './answer';\nimport { DroppablePlaceholder } from './droppable-placeholder';\n\nconst ChoicesContainer = styled('div')(({ theme }) => ({\n marginBottom: theme.spacing(2),\n}));\n\nexport class ChoicesList extends React.Component {\n static propTypes = {\n session: PropTypes.object.isRequired,\n instanceId: PropTypes.string.isRequired,\n model: PropTypes.object.isRequired,\n disabled: PropTypes.bool.isRequired,\n onRemoveAnswer: PropTypes.func,\n selectedAnswer: PropTypes.object,\n onChoiceClick: PropTypes.func,\n onPlacementClick: PropTypes.func,\n };\n\n render() {\n const {\n model,\n disabled,\n session,\n instanceId,\n onRemoveAnswer,\n selectedAnswer,\n onChoiceClick,\n onPlacementClick,\n } = this.props;\n const { config } = model;\n const { duplicates } = config;\n\n const filteredAnswers = config.answers\n .filter(\n (answer) =>\n duplicates ||\n isEmpty(session) ||\n !session.value ||\n isUndefined(find(session.value, (val) => val === answer.id)),\n )\n .map((answer) => (\n <DragAndDropAnswer\n key={answer.id}\n instanceId={instanceId}\n draggable={true}\n disabled={disabled}\n session={session}\n type=\"choice\"\n selectedAnswer={selectedAnswer}\n onSelectClick={onChoiceClick}\n {...answer}\n />\n ));\n\n return (\n <ChoicesContainer>\n <DroppablePlaceholder\n id=\"choices-pool\"\n disabled={disabled}\n onRemoveAnswer={onRemoveAnswer}\n onPlacementClick={onPlacementClick}\n >\n {filteredAnswers}\n </DroppablePlaceholder>\n </ChoicesContainer>\n );\n }\n}\n\nexport default ChoicesList;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,qBAAA,GAAAL,OAAA;AAEA,MAAMM,gBAAgB,GAAG,IAAAC,cAAM,EAAC,KAAK,CAAC,CAAC,CAAC;EAAEC;AAAM,CAAC,MAAM;EACrDC,YAAY,EAAED,KAAK,CAACE,OAAO,CAAC,CAAC;AAC/B,CAAC,CAAC,CAAC;AAEI,MAAMC,WAAW,SAASC,cAAK,CAACC,SAAS,CAAC;EAY/CC,MAAMA,CAAA,EAAG;IACP,MAAM;MACJC,KAAK;MACLC,QAAQ;MACRC,OAAO;MACPC,UAAU;MACVC,cAAc;MACdC,cAAc;MACdC,aAAa;MACbC;IACF,CAAC,GAAG,IAAI,CAACC,KAAK;IACd,MAAM;MAAEC;IAAO,CAAC,GAAGT,KAAK;IACxB,MAAM;MAAEU;IAAW,CAAC,GAAGD,MAAM;IAE7B,MAAME,eAAe,GAAGF,MAAM,CAACG,OAAO,CACnCC,MA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B,kBAAS,CAACK,IAAI;EAC9BhC,cAAc,EAAE2B,kBAAS,CAACC,MAAM;EAChC3B,aAAa,EAAE0B,kBAAS,CAACK,IAAI;EAC7B9B,gBAAgB,EAAEyB,kBAAS,CAACK;AAC9B,CAAC;AAAA,IAAAC,QAAA,GAAAR,OAAA,CAAAR,OAAA,GAqDY1B,WAAW","ignoreList":[]}
|
|
@@ -29,6 +29,7 @@ function DroppablePlaceholder({
|
|
|
29
29
|
id,
|
|
30
30
|
disabled,
|
|
31
31
|
children,
|
|
32
|
+
onPlacementClick,
|
|
32
33
|
...rest
|
|
33
34
|
}) {
|
|
34
35
|
const {
|
|
@@ -41,8 +42,17 @@ function DroppablePlaceholder({
|
|
|
41
42
|
},
|
|
42
43
|
disabled
|
|
43
44
|
});
|
|
45
|
+
const handleClick = () => {
|
|
46
|
+
if (disabled) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
onPlacementClick?.({
|
|
50
|
+
type: 'choices-pool'
|
|
51
|
+
});
|
|
52
|
+
};
|
|
44
53
|
return /*#__PURE__*/_react.default.createElement(Container, (0, _extends2.default)({
|
|
45
54
|
ref: setNodeRef,
|
|
55
|
+
onClick: handleClick,
|
|
46
56
|
style: {
|
|
47
57
|
backgroundColor: isOver ? 'rgba(0,0,0,0.05)' : 'transparent'
|
|
48
58
|
}
|
|
@@ -54,7 +64,8 @@ function DroppablePlaceholder({
|
|
|
54
64
|
DroppablePlaceholder.propTypes = {
|
|
55
65
|
id: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
56
66
|
disabled: _propTypes.default.bool,
|
|
57
|
-
children: _propTypes.default.node
|
|
67
|
+
children: _propTypes.default.node,
|
|
68
|
+
onPlacementClick: _propTypes.default.func
|
|
58
69
|
};
|
|
59
70
|
var _default = exports.default = DroppablePlaceholder;
|
|
60
71
|
//# sourceMappingURL=droppable-placeholder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"droppable-placeholder.js","names":["_react","_interopRequireDefault","require","_propTypes","_core","_styles","_drag","Container","styled","theme","alignItems","display","flexDirection","flexWrap","justifyContent","marginTop","spacing","marginBottom","minHeight","transition","DroppablePlaceholder","id","disabled","children","rest","setNodeRef","isOver","useDroppable","data","type","default","createElement","_extends2","ref","style","backgroundColor","MatchDroppablePlaceholder","propTypes","PropTypes","oneOfType","string","number","bool","node","_default","exports"],"sources":["../src/droppable-placeholder.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { useDroppable } from '@dnd-kit/core';\nimport { styled } from '@mui/material/styles';\nimport { MatchDroppablePlaceholder } from '@pie-lib/drag';\n\nconst Container = styled('div')(({ theme }) => ({\n alignItems: 'center',\n display: 'flex',\n flexDirection: 'row',\n flexWrap: 'wrap',\n justifyContent: 'space-between',\n marginTop: theme.spacing(1),\n marginBottom: theme.spacing(1),\n minHeight: 50,\n transition: 'background-color 200ms ease',\n}));\n\nexport function DroppablePlaceholder({ id, disabled, children, ...rest }) {\n const { setNodeRef, isOver } = useDroppable({\n id: id || 'choices-pool',\n data: { type: 'choices-pool' },\n disabled,\n });\n\n return (\n <Container\n ref={setNodeRef}\n style={{ backgroundColor: isOver ? 'rgba(0,0,0,0.05)' : 'transparent' }}\n {...rest}\n >\n <MatchDroppablePlaceholder id={id} disabled={disabled}>\n {children}\n </MatchDroppablePlaceholder>\n </Container>\n );\n}\n\nDroppablePlaceholder.propTypes = {\n id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n disabled: PropTypes.bool,\n children: PropTypes.node,\n};\n\nexport default DroppablePlaceholder;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAEA,MAAMK,SAAS,GAAG,IAAAC,cAAM,EAAC,KAAK,CAAC,CAAC,CAAC;EAAEC;AAAM,CAAC,MAAM;EAC5CC,UAAU,EAAE,QAAQ;EACpBC,OAAO,EAAE,MAAM;EACfC,aAAa,EAAE,KAAK;EACpBC,QAAQ,EAAE,MAAM;EAChBC,cAAc,EAAE,eAAe;EAC/BC,SAAS,EAAEN,KAAK,CAACO,OAAO,CAAC,CAAC,CAAC;EAC3BC,YAAY,EAAER,KAAK,CAACO,OAAO,CAAC,CAAC,CAAC;EAC9BE,SAAS,EAAE,EAAE;EACbC,UAAU,EAAE;AAChB,CAAC,CAAC,CAAC;AAEI,SAASC,oBAAoBA,CAAC;EAAEC,EAAE;EAAEC,QAAQ;EAAEC,QAAQ;EAAE,GAAGC;AAAK,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"droppable-placeholder.js","names":["_react","_interopRequireDefault","require","_propTypes","_core","_styles","_drag","Container","styled","theme","alignItems","display","flexDirection","flexWrap","justifyContent","marginTop","spacing","marginBottom","minHeight","transition","DroppablePlaceholder","id","disabled","children","onPlacementClick","rest","setNodeRef","isOver","useDroppable","data","type","handleClick","default","createElement","_extends2","ref","onClick","style","backgroundColor","MatchDroppablePlaceholder","propTypes","PropTypes","oneOfType","string","number","bool","node","func","_default","exports"],"sources":["../src/droppable-placeholder.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { useDroppable } from '@dnd-kit/core';\nimport { styled } from '@mui/material/styles';\nimport { MatchDroppablePlaceholder } from '@pie-lib/drag';\n\nconst Container = styled('div')(({ theme }) => ({\n alignItems: 'center',\n display: 'flex',\n flexDirection: 'row',\n flexWrap: 'wrap',\n justifyContent: 'space-between',\n marginTop: theme.spacing(1),\n marginBottom: theme.spacing(1),\n minHeight: 50,\n transition: 'background-color 200ms ease',\n}));\n\nexport function DroppablePlaceholder({ id, disabled, children, onPlacementClick, ...rest }) {\n const { setNodeRef, isOver } = useDroppable({\n id: id || 'choices-pool',\n data: { type: 'choices-pool' },\n disabled,\n });\n\n const handleClick = () => {\n if (disabled) {\n return;\n }\n\n onPlacementClick?.({ type: 'choices-pool' });\n };\n\n return (\n <Container\n ref={setNodeRef}\n onClick={handleClick}\n style={{ backgroundColor: isOver ? 'rgba(0,0,0,0.05)' : 'transparent' }}\n {...rest}\n >\n <MatchDroppablePlaceholder id={id} disabled={disabled}>\n {children}\n </MatchDroppablePlaceholder>\n </Container>\n );\n}\n\nDroppablePlaceholder.propTypes = {\n id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),\n disabled: PropTypes.bool,\n children: PropTypes.node,\n onPlacementClick: PropTypes.func,\n};\n\nexport default DroppablePlaceholder;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AAEA,MAAMK,SAAS,GAAG,IAAAC,cAAM,EAAC,KAAK,CAAC,CAAC,CAAC;EAAEC;AAAM,CAAC,MAAM;EAC5CC,UAAU,EAAE,QAAQ;EACpBC,OAAO,EAAE,MAAM;EACfC,aAAa,EAAE,KAAK;EACpBC,QAAQ,EAAE,MAAM;EAChBC,cAAc,EAAE,eAAe;EAC/BC,SAAS,EAAEN,KAAK,CAACO,OAAO,CAAC,CAAC,CAAC;EAC3BC,YAAY,EAAER,KAAK,CAACO,OAAO,CAAC,CAAC,CAAC;EAC9BE,SAAS,EAAE,EAAE;EACbC,UAAU,EAAE;AAChB,CAAC,CAAC,CAAC;AAEI,SAASC,oBAAoBA,CAAC;EAAEC,EAAE;EAAEC,QAAQ;EAAEC,QAAQ;EAAEC,gBAAgB;EAAE,GAAGC;AAAK,CAAC,EAAE;EACxF,MAAM;IAAEC,UAAU;IAAEC;EAAO,CAAC,GAAG,IAAAC,kBAAY,EAAC;IACxCP,EAAE,EAAEA,EAAE,IAAI,cAAc;IACxBQ,IAAI,EAAE;MAAEC,IAAI,EAAE;IAAe,CAAC;IAC9BR;EACJ,CAAC,CAAC;EAEF,MAAMS,WAAW,GAAGA,CAAA,KAAM;IACtB,IAAIT,QAAQ,EAAE;MACZ;IACF;IAEAE,gBAAgB,GAAG;MAAEM,IAAI,EAAE;IAAe,CAAC,CAAC;EAChD,CAAC;EAED,oBACI9B,MAAA,CAAAgC,OAAA,CAAAC,aAAA,CAAC1B,SAAS,MAAA2B,SAAA,CAAAF,OAAA;IACNG,GAAG,EAAET,UAAW;IAChBU,OAAO,EAAEL,WAAY;IACrBM,KAAK,EAAE;MAAEC,eAAe,EAAEX,MAAM,GAAG,kBAAkB,GAAG;IAAc;EAAE,GACpEF,IAAI,gBAERzB,MAAA,CAAAgC,OAAA,CAAAC,aAAA,CAAC3B,KAAA,CAAAiC,yBAAyB;IAAClB,EAAE,EAAEA,EAAG;IAACC,QAAQ,EAAEA;EAAS,GACjDC,QACsB,CACpB,CAAC;AAEpB;AAEAH,oBAAoB,CAACoB,SAAS,GAAG;EAC7BnB,EAAE,EAAEoB,kBAAS,CAACC,SAAS,CAAC,CAACD,kBAAS,CAACE,MAAM,EAAEF,kBAAS,CAACG,MAAM,CAAC,CAAC;EAC7DtB,QAAQ,EAAEmB,kBAAS,CAACI,IAAI;EACxBtB,QAAQ,EAAEkB,kBAAS,CAACK,IAAI;EACxBtB,gBAAgB,EAAEiB,kBAAS,CAACM;AAChC,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAjB,OAAA,GAEaZ,oBAAoB","ignoreList":[]}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.closestDroppableKeyboardCoordinates = void 0;
|
|
7
|
+
var _core = require("@dnd-kit/core");
|
|
8
|
+
const ARROW_STEP = 25;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Custom keyboard coordinate getter for non-sortable drag-and-drop.
|
|
12
|
+
*
|
|
13
|
+
* Tab/Shift+Tab cycle the dragged item directly onto the next/previous droppable
|
|
14
|
+
* (response area or the choices pool), in DOM order, placing the dragged item's own
|
|
15
|
+
* top-left corner at the target's center-left point. Arrow keys are left doing plain
|
|
16
|
+
* free-form movement (nudging the dragged item by a fixed step, same as dnd-kit's own
|
|
17
|
+
* default keyboard behavior) rather than jumping between droppables — collision
|
|
18
|
+
* detection (rectIntersection) still picks up whatever the item ends up actually
|
|
19
|
+
* overlapping.
|
|
20
|
+
*/
|
|
21
|
+
const closestDroppableKeyboardCoordinates = (event, {
|
|
22
|
+
active,
|
|
23
|
+
context,
|
|
24
|
+
currentCoordinates
|
|
25
|
+
}) => {
|
|
26
|
+
const {
|
|
27
|
+
code
|
|
28
|
+
} = event;
|
|
29
|
+
const isTab = code === 'Tab';
|
|
30
|
+
const isArrow = code === _core.KeyboardCode.Down || code === _core.KeyboardCode.Up || code === _core.KeyboardCode.Left || code === _core.KeyboardCode.Right;
|
|
31
|
+
if (!isTab && !isArrow) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
if (isArrow) {
|
|
36
|
+
switch (code) {
|
|
37
|
+
case _core.KeyboardCode.Down:
|
|
38
|
+
return {
|
|
39
|
+
...currentCoordinates,
|
|
40
|
+
y: currentCoordinates.y + ARROW_STEP
|
|
41
|
+
};
|
|
42
|
+
case _core.KeyboardCode.Up:
|
|
43
|
+
return {
|
|
44
|
+
...currentCoordinates,
|
|
45
|
+
y: currentCoordinates.y - ARROW_STEP
|
|
46
|
+
};
|
|
47
|
+
case _core.KeyboardCode.Right:
|
|
48
|
+
return {
|
|
49
|
+
...currentCoordinates,
|
|
50
|
+
x: currentCoordinates.x + ARROW_STEP
|
|
51
|
+
};
|
|
52
|
+
case _core.KeyboardCode.Left:
|
|
53
|
+
return {
|
|
54
|
+
...currentCoordinates,
|
|
55
|
+
x: currentCoordinates.x - ARROW_STEP
|
|
56
|
+
};
|
|
57
|
+
default:
|
|
58
|
+
return currentCoordinates;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const {
|
|
62
|
+
droppableRects,
|
|
63
|
+
droppableContainers,
|
|
64
|
+
collisionRect
|
|
65
|
+
} = context;
|
|
66
|
+
if (!droppableRects || droppableRects.size === 0) {
|
|
67
|
+
return currentCoordinates;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// `currentCoordinates` is the top-left of the dragged item's collision rect (not its
|
|
71
|
+
// center), so derive the dragged item's center in the same frame before comparing it
|
|
72
|
+
// against droppable centers below. Returning a droppable's *center* as the next
|
|
73
|
+
// coordinates (as opposed to its top-left) would shift the dragged item's top-left to
|
|
74
|
+
// that center, overshooting the target by roughly half its size and causing
|
|
75
|
+
// dnd-kit to resolve collisions against a neighboring droppable instead.
|
|
76
|
+
const draggedHalfSize = {
|
|
77
|
+
x: (collisionRect?.width || 0) / 2,
|
|
78
|
+
y: (collisionRect?.height || 0) / 2
|
|
79
|
+
};
|
|
80
|
+
const currentCenter = {
|
|
81
|
+
x: currentCoordinates.x + draggedHalfSize.x,
|
|
82
|
+
y: currentCoordinates.y + draggedHalfSize.y
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// A placed answer ("target") is itself a droppable for its own prompt slot
|
|
86
|
+
// ("drop-{promptId}"). That self drop-zone must never be treated as a navigable
|
|
87
|
+
// target: it sits under the dragged item, so a tiny (even sub-pixel) discrepancy
|
|
88
|
+
// between its measured rect and the dragged item's own rect is enough to make it
|
|
89
|
+
// register as the "closest" candidate, which reads as the drag being stuck.
|
|
90
|
+
// Exclude it outright rather than relying on a distance threshold.
|
|
91
|
+
const activeData = active?.data?.current;
|
|
92
|
+
const ownDropId = activeData?.promptId != null ? `drop-${activeData.promptId}` : undefined;
|
|
93
|
+
|
|
94
|
+
// Collect top-left and center of all enabled droppable containers
|
|
95
|
+
const targets = [];
|
|
96
|
+
for (const [id, container] of droppableContainers) {
|
|
97
|
+
if (container?.disabled) continue;
|
|
98
|
+
if (id === ownDropId) continue;
|
|
99
|
+
const rect = droppableRects.get(id);
|
|
100
|
+
if (!rect) continue;
|
|
101
|
+
const center = {
|
|
102
|
+
x: rect.left + rect.width / 2,
|
|
103
|
+
y: rect.top + rect.height / 2
|
|
104
|
+
};
|
|
105
|
+
// Land the dragged item's own top-left corner at the target's center-left point,
|
|
106
|
+
// rather than at the target's own top-left corner.
|
|
107
|
+
const dropPosition = {
|
|
108
|
+
x: rect.left,
|
|
109
|
+
y: rect.top + rect.height / 2
|
|
110
|
+
};
|
|
111
|
+
targets.push({
|
|
112
|
+
id,
|
|
113
|
+
dropPosition,
|
|
114
|
+
center
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (targets.length === 0) {
|
|
118
|
+
return currentCoordinates;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Tab/Shift+Tab: cycle through targets in DOM order (sorted top-to-bottom, left-to-right)
|
|
122
|
+
const reverse = event.shiftKey;
|
|
123
|
+
|
|
124
|
+
// Sort targets by position (top to bottom, then left to right)
|
|
125
|
+
targets.sort((a, b) => {
|
|
126
|
+
if (Math.abs(a.center.y - b.center.y) > 10) return a.center.y - b.center.y;
|
|
127
|
+
return a.center.x - b.center.x;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Find the current target (closest to current coordinates)
|
|
131
|
+
let currentIndex = 0;
|
|
132
|
+
let minDist = Infinity;
|
|
133
|
+
for (let i = 0; i < targets.length; i++) {
|
|
134
|
+
const dist = distance(currentCenter, targets[i].center);
|
|
135
|
+
if (dist < minDist) {
|
|
136
|
+
minDist = dist;
|
|
137
|
+
currentIndex = i;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Move to next/previous
|
|
142
|
+
const nextIndex = reverse ? (currentIndex - 1 + targets.length) % targets.length : (currentIndex + 1) % targets.length;
|
|
143
|
+
return targets[nextIndex].dropPosition;
|
|
144
|
+
};
|
|
145
|
+
exports.closestDroppableKeyboardCoordinates = closestDroppableKeyboardCoordinates;
|
|
146
|
+
const distance = (a, b) => Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);
|
|
147
|
+
//# sourceMappingURL=keyboard-coordinates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard-coordinates.js","names":["_core","require","ARROW_STEP","closestDroppableKeyboardCoordinates","event","active","context","currentCoordinates","code","isTab","isArrow","KeyboardCode","Down","Up","Left","Right","undefined","preventDefault","y","x","droppableRects","droppableContainers","collisionRect","size","draggedHalfSize","width","height","currentCenter","activeData","data","current","ownDropId","promptId","targets","id","container","disabled","rect","get","center","left","top","dropPosition","push","length","reverse","shiftKey","sort","a","b","Math","abs","currentIndex","minDist","Infinity","i","dist","distance","nextIndex","exports","sqrt"],"sources":["../src/keyboard-coordinates.js"],"sourcesContent":["import { KeyboardCode } from '@dnd-kit/core';\n\nconst ARROW_STEP = 25;\n\n/**\n * Custom keyboard coordinate getter for non-sortable drag-and-drop.\n *\n * Tab/Shift+Tab cycle the dragged item directly onto the next/previous droppable\n * (response area or the choices pool), in DOM order, placing the dragged item's own\n * top-left corner at the target's center-left point. Arrow keys are left doing plain\n * free-form movement (nudging the dragged item by a fixed step, same as dnd-kit's own\n * default keyboard behavior) rather than jumping between droppables — collision\n * detection (rectIntersection) still picks up whatever the item ends up actually\n * overlapping.\n */\nexport const closestDroppableKeyboardCoordinates = (event, { active, context, currentCoordinates }) => {\n const { code } = event;\n const isTab = code === 'Tab';\n const isArrow =\n code === KeyboardCode.Down || code === KeyboardCode.Up || code === KeyboardCode.Left || code === KeyboardCode.Right;\n\n if (!isTab && !isArrow) {\n return undefined;\n }\n\n event.preventDefault();\n\n if (isArrow) {\n switch (code) {\n case KeyboardCode.Down:\n return { ...currentCoordinates, y: currentCoordinates.y + ARROW_STEP };\n\n case KeyboardCode.Up:\n return { ...currentCoordinates, y: currentCoordinates.y - ARROW_STEP };\n\n case KeyboardCode.Right:\n return { ...currentCoordinates, x: currentCoordinates.x + ARROW_STEP };\n\n case KeyboardCode.Left:\n return { ...currentCoordinates, x: currentCoordinates.x - ARROW_STEP };\n\n default:\n return currentCoordinates;\n }\n }\n\n const { droppableRects, droppableContainers, collisionRect } = context;\n\n if (!droppableRects || droppableRects.size === 0) {\n return currentCoordinates;\n }\n\n // `currentCoordinates` is the top-left of the dragged item's collision rect (not its\n // center), so derive the dragged item's center in the same frame before comparing it\n // against droppable centers below. Returning a droppable's *center* as the next\n // coordinates (as opposed to its top-left) would shift the dragged item's top-left to\n // that center, overshooting the target by roughly half its size and causing\n // dnd-kit to resolve collisions against a neighboring droppable instead.\n const draggedHalfSize = {\n x: (collisionRect?.width || 0) / 2,\n y: (collisionRect?.height || 0) / 2,\n };\n const currentCenter = {\n x: currentCoordinates.x + draggedHalfSize.x,\n y: currentCoordinates.y + draggedHalfSize.y,\n };\n\n // A placed answer (\"target\") is itself a droppable for its own prompt slot\n // (\"drop-{promptId}\"). That self drop-zone must never be treated as a navigable\n // target: it sits under the dragged item, so a tiny (even sub-pixel) discrepancy\n // between its measured rect and the dragged item's own rect is enough to make it\n // register as the \"closest\" candidate, which reads as the drag being stuck.\n // Exclude it outright rather than relying on a distance threshold.\n const activeData = active?.data?.current;\n const ownDropId = activeData?.promptId != null ? `drop-${activeData.promptId}` : undefined;\n\n // Collect top-left and center of all enabled droppable containers\n const targets = [];\n\n for (const [id, container] of droppableContainers) {\n if (container?.disabled) continue;\n\n if (id === ownDropId) continue;\n\n const rect = droppableRects.get(id);\n\n if (!rect) continue;\n\n const center = {\n x: rect.left + rect.width / 2,\n y: rect.top + rect.height / 2,\n };\n // Land the dragged item's own top-left corner at the target's center-left point,\n // rather than at the target's own top-left corner.\n const dropPosition = {\n x: rect.left,\n y: rect.top + rect.height / 2,\n };\n\n targets.push({ id, dropPosition, center });\n }\n\n if (targets.length === 0) {\n return currentCoordinates;\n }\n\n // Tab/Shift+Tab: cycle through targets in DOM order (sorted top-to-bottom, left-to-right)\n const reverse = event.shiftKey;\n\n // Sort targets by position (top to bottom, then left to right)\n targets.sort((a, b) => {\n if (Math.abs(a.center.y - b.center.y) > 10) return a.center.y - b.center.y;\n return a.center.x - b.center.x;\n });\n\n // Find the current target (closest to current coordinates)\n let currentIndex = 0;\n let minDist = Infinity;\n\n for (let i = 0; i < targets.length; i++) {\n const dist = distance(currentCenter, targets[i].center);\n\n if (dist < minDist) {\n minDist = dist;\n currentIndex = i;\n }\n }\n\n // Move to next/previous\n const nextIndex = reverse\n ? (currentIndex - 1 + targets.length) % targets.length\n : (currentIndex + 1) % targets.length;\n\n return targets[nextIndex].dropPosition;\n};\n\nconst distance = (a, b) => Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAEA,MAAMC,UAAU,GAAG,EAAE;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,mCAAmC,GAAGA,CAACC,KAAK,EAAE;EAAEC,MAAM;EAAEC,OAAO;EAAEC;AAAmB,CAAC,KAAK;EACrG,MAAM;IAAEC;EAAK,CAAC,GAAGJ,KAAK;EACtB,MAAMK,KAAK,GAAGD,IAAI,KAAK,KAAK;EAC5B,MAAME,OAAO,GACXF,IAAI,KAAKG,kBAAY,CAACC,IAAI,IAAIJ,IAAI,KAAKG,kBAAY,CAACE,EAAE,IAAIL,IAAI,KAAKG,kBAAY,CAACG,IAAI,IAAIN,IAAI,KAAKG,kBAAY,CAACI,KAAK;EAErH,IAAI,CAACN,KAAK,IAAI,CAACC,OAAO,EAAE;IACtB,OAAOM,SAAS;EAClB;EAEAZ,KAAK,CAACa,cAAc,CAAC,CAAC;EAEtB,IAAIP,OAAO,EAAE;IACX,QAAQF,IAAI;MACV,KAAKG,kBAAY,CAACC,IAAI;QACpB,OAAO;UAAE,GA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B,CAAC;EAChC,CAAC,CAAC;;EAEF;EACA,IAAIiC,YAAY,GAAG,CAAC;EACpB,IAAIC,OAAO,GAAGC,QAAQ;EAEtB,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGtB,OAAO,CAACW,MAAM,EAAEW,CAAC,EAAE,EAAE;IACvC,MAAMC,IAAI,GAAGC,QAAQ,CAAC9B,aAAa,EAAEM,OAAO,CAACsB,CAAC,CAAC,CAAChB,MAAM,CAAC;IAEvD,IAAIiB,IAAI,GAAGH,OAAO,EAAE;MAClBA,OAAO,GAAGG,IAAI;MACdJ,YAAY,GAAGG,CAAC;IAClB;EACF;;EAEA;EACA,MAAMG,SAAS,GAAGb,OAAO,GACrB,CAACO,YAAY,GAAG,CAAC,GAAGnB,OAAO,CAACW,MAAM,IAAIX,OAAO,CAACW,MAAM,GACpD,CAACQ,YAAY,GAAG,CAAC,IAAInB,OAAO,CAACW,MAAM;EAEvC,OAAOX,OAAO,CAACyB,SAAS,CAAC,CAAChB,YAAY;AACxC,CAAC;AAACiB,OAAA,CAAAxD,mCAAA,GAAAA,mCAAA;AAEF,MAAMsD,QAAQ,GAAGA,CAACT,CAAC,EAAEC,CAAC,KAAKC,IAAI,CAACU,IAAI,CAAC,CAACZ,CAAC,CAAC7B,CAAC,GAAG8B,CAAC,CAAC9B,CAAC,KAAK,CAAC,GAAG,CAAC6B,CAAC,CAAC9B,CAAC,GAAG+B,CAAC,CAAC/B,CAAC,KAAK,CAAC,CAAC","ignoreList":[]}
|
package/lib/main.js
CHANGED
|
@@ -11,6 +11,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
11
11
|
var _drag = require("@pie-lib/drag");
|
|
12
12
|
var _core = require("@dnd-kit/core");
|
|
13
13
|
var _modifiers = require("@dnd-kit/modifiers");
|
|
14
|
+
var _keyboardCoordinates = require("./keyboard-coordinates");
|
|
14
15
|
var _correctAnswerToggle = _interopRequireDefault(require("@pie-lib/correct-answer-toggle"));
|
|
15
16
|
var _renderUi = require("@pie-lib/render-ui");
|
|
16
17
|
var _styles = require("@mui/material/styles");
|
|
@@ -18,6 +19,39 @@ var _lodashEs = require("lodash-es");
|
|
|
18
19
|
var _answerArea = _interopRequireDefault(require("./answer-area"));
|
|
19
20
|
var _choicesList = _interopRequireDefault(require("./choices-list"));
|
|
20
21
|
var _answer = require("./answer");
|
|
22
|
+
// A click that lands right after a real drag gesture ends (pointer drag-and-drop, or
|
|
23
|
+
// the browser's own synthetic click for a keyboard Space/Enter) must be ignored by the
|
|
24
|
+
// new click-to-select/click-to-place handlers below, or it would immediately reopen or
|
|
25
|
+
// re-trigger a selection for a drag that just completed.
|
|
26
|
+
const CLICK_AFTER_DRAG_GUARD_MS = 250;
|
|
27
|
+
const sensors = [
|
|
28
|
+
// Without an activationConstraint, dnd-kit's PointerSensor calls its internal
|
|
29
|
+
// handleStart() synchronously on pointerdown, before any movement — meaning a plain
|
|
30
|
+
// click is itself "activated" as a drag. Once activated, dnd-kit adds a capture-phase
|
|
31
|
+
// document click listener that calls stopPropagation() (to suppress the native
|
|
32
|
+
// "ghost click" a real drag leaves behind), which also swallows the click for a
|
|
33
|
+
// gesture with zero movement, before it ever reaches our own onClick handlers below.
|
|
34
|
+
// Requiring 8px of movement (matching @pie-lib/drag's DragProvider convention used
|
|
35
|
+
// elsewhere in this codebase) defers activation until an actual drag gesture is
|
|
36
|
+
// underway, so a plain click passes through untouched.
|
|
37
|
+
{
|
|
38
|
+
sensor: _core.PointerSensor,
|
|
39
|
+
options: {
|
|
40
|
+
activationConstraint: {
|
|
41
|
+
distance: 8
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
45
|
+
sensor: _core.KeyboardSensor,
|
|
46
|
+
options: {
|
|
47
|
+
coordinateGetter: _keyboardCoordinates.closestDroppableKeyboardCoordinates,
|
|
48
|
+
keyboardCodes: {
|
|
49
|
+
start: [_core.KeyboardCode.Space, _core.KeyboardCode.Enter],
|
|
50
|
+
cancel: [_core.KeyboardCode.Esc],
|
|
51
|
+
end: [_core.KeyboardCode.Space, _core.KeyboardCode.Enter]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}];
|
|
21
55
|
const MainContainer = (0, _styles.styled)('div')({
|
|
22
56
|
display: 'flex',
|
|
23
57
|
flexDirection: 'column',
|
|
@@ -25,6 +59,19 @@ const MainContainer = (0, _styles.styled)('div')({
|
|
|
25
59
|
color: _renderUi.color.text(),
|
|
26
60
|
backgroundColor: _renderUi.color.background()
|
|
27
61
|
});
|
|
62
|
+
const InteractiveRegion = (0, _styles.styled)('div')({
|
|
63
|
+
width: '100%',
|
|
64
|
+
overflowX: 'auto',
|
|
65
|
+
overflowY: 'hidden'
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// A block child of a scroll port is sized to the scroll port, so it has to opt out explicitly for
|
|
69
|
+
// the content to be able to overflow. min-content keeps the rows and the pool the same width.
|
|
70
|
+
const InteractiveRegionContent = (0, _styles.styled)('div')({
|
|
71
|
+
display: 'flex',
|
|
72
|
+
flexDirection: 'column',
|
|
73
|
+
minWidth: 'min-content'
|
|
74
|
+
});
|
|
28
75
|
class Main extends _react.default.Component {
|
|
29
76
|
constructor(props) {
|
|
30
77
|
super(props);
|
|
@@ -51,22 +98,19 @@ class Main extends _react.default.Component {
|
|
|
51
98
|
rect
|
|
52
99
|
}
|
|
53
100
|
});
|
|
101
|
+
this.selectAnswer(active.data.current);
|
|
54
102
|
}
|
|
55
103
|
});
|
|
56
|
-
(0, _defineProperty2.default)(this, "
|
|
104
|
+
(0, _defineProperty2.default)(this, "onDragCancel", () => {
|
|
57
105
|
this.setState({
|
|
58
106
|
draggingElement: null
|
|
59
107
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
const activeData = active.data.current;
|
|
68
|
-
const overData = over?.data.current;
|
|
69
|
-
if (!activeData) {
|
|
108
|
+
this.cancelSelection();
|
|
109
|
+
this.lastDragEndAt = Date.now();
|
|
110
|
+
});
|
|
111
|
+
// Pure placement logic
|
|
112
|
+
(0, _defineProperty2.default)(this, "placeAnswer", (activeData, overData) => {
|
|
113
|
+
if (!activeData || !overData) {
|
|
70
114
|
return;
|
|
71
115
|
}
|
|
72
116
|
const {
|
|
@@ -93,9 +137,9 @@ class Main extends _react.default.Component {
|
|
|
93
137
|
const sourcePromptId = activeData.promptId;
|
|
94
138
|
|
|
95
139
|
// Handle dropping onto a drop zone
|
|
96
|
-
if (overData
|
|
140
|
+
if (overData.type === 'drop-zone' && overData.promptId != null) {
|
|
97
141
|
const targetPromptId = overData.promptId;
|
|
98
|
-
if (activeData.type === 'choice' &&
|
|
142
|
+
if (activeData.type === 'choice' && targetPromptId !== undefined) {
|
|
99
143
|
// check if this choice is already placed somewhere
|
|
100
144
|
const existingPlacement = (0, _lodashEs.findKey)(session.value, val => val === answerId);
|
|
101
145
|
if (existingPlacement && !duplicates) {
|
|
@@ -126,6 +170,88 @@ class Main extends _react.default.Component {
|
|
|
126
170
|
onSessionChange(session);
|
|
127
171
|
}
|
|
128
172
|
});
|
|
173
|
+
(0, _defineProperty2.default)(this, "onPlaceAnswer", event => {
|
|
174
|
+
this.setState({
|
|
175
|
+
draggingElement: null
|
|
176
|
+
});
|
|
177
|
+
const {
|
|
178
|
+
active,
|
|
179
|
+
over
|
|
180
|
+
} = event;
|
|
181
|
+
if (!active) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const activeData = active.data.current;
|
|
185
|
+
const overData = over?.data.current;
|
|
186
|
+
if (!activeData) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
this.placeAnswer(activeData, overData);
|
|
190
|
+
this.cancelSelection();
|
|
191
|
+
this.lastDragEndAt = Date.now();
|
|
192
|
+
});
|
|
193
|
+
(0, _defineProperty2.default)(this, "isSameAnswer", (a, b) => !!a && !!b && a.type === b.type && a.id === b.id && a.promptId === b.promptId);
|
|
194
|
+
// Unconditionally selects (used by the drag-start mirror, and internally when
|
|
195
|
+
// switching from one choice to another).
|
|
196
|
+
(0, _defineProperty2.default)(this, "selectAnswer", data => {
|
|
197
|
+
this.setState({
|
|
198
|
+
selectedAnswer: data
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
// Click-to-select semantics: selecting the currently-selected answer again clears
|
|
202
|
+
// the selection instead of re-selecting it.
|
|
203
|
+
(0, _defineProperty2.default)(this, "toggleAnswerSelection", data => {
|
|
204
|
+
this.setState(state => ({
|
|
205
|
+
selectedAnswer: this.isSameAnswer(state.selectedAnswer, data) ? null : data
|
|
206
|
+
}));
|
|
207
|
+
});
|
|
208
|
+
(0, _defineProperty2.default)(this, "cancelSelection", () => {
|
|
209
|
+
this.setState({
|
|
210
|
+
selectedAnswer: null
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
// If a real dnd-kit drag (started via keyboard Space/Enter) is still live when a
|
|
214
|
+
// click completes the placement below, it needs to be cleanly ended — otherwise
|
|
215
|
+
// dnd-kit would still think a drag is in progress (still listening for Tab/arrow/
|
|
216
|
+
// Space/Escape, still showing the drag overlay) for a placement the click already
|
|
217
|
+
// performed. Escape is already configured as this sensor's cancel key, and
|
|
218
|
+
// dispatching it as a real DOM KeyboardEvent is how dnd-kit's own document-level
|
|
219
|
+
// listener is reached from outside its sensor. onDragCancel is intentionally not
|
|
220
|
+
// wired to redo any placement — it only resets local UI state — so this is safe to
|
|
221
|
+
// call unconditionally, including when no drag is actually live (dnd-kit simply has
|
|
222
|
+
// no listener attached in that case, and the dispatch is a no-op).
|
|
223
|
+
(0, _defineProperty2.default)(this, "endAnyLiveKeyboardDrag", () => {
|
|
224
|
+
document.dispatchEvent(new KeyboardEvent('keydown', {
|
|
225
|
+
code: 'Escape',
|
|
226
|
+
bubbles: true,
|
|
227
|
+
cancelable: true
|
|
228
|
+
}));
|
|
229
|
+
});
|
|
230
|
+
(0, _defineProperty2.default)(this, "placeSelectedAnswer", overData => {
|
|
231
|
+
const {
|
|
232
|
+
selectedAnswer
|
|
233
|
+
} = this.state;
|
|
234
|
+
if (!selectedAnswer) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
this.placeAnswer(selectedAnswer, overData);
|
|
238
|
+
this.cancelSelection();
|
|
239
|
+
this.endAnyLiveKeyboardDrag();
|
|
240
|
+
this.lastDragEndAt = Date.now();
|
|
241
|
+
});
|
|
242
|
+
(0, _defineProperty2.default)(this, "isClickSoonAfterDragEnd", () => Date.now() - this.lastDragEndAt < CLICK_AFTER_DRAG_GUARD_MS);
|
|
243
|
+
(0, _defineProperty2.default)(this, "onChoiceClick", data => {
|
|
244
|
+
if (this.isClickSoonAfterDragEnd()) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
this.toggleAnswerSelection(data);
|
|
248
|
+
});
|
|
249
|
+
(0, _defineProperty2.default)(this, "onPlacementClick", overData => {
|
|
250
|
+
if (this.isClickSoonAfterDragEnd()) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
this.placeSelectedAnswer(overData);
|
|
254
|
+
});
|
|
129
255
|
(0, _defineProperty2.default)(this, "toggleShowCorrect", () => {
|
|
130
256
|
this.setState({
|
|
131
257
|
showCorrectAnswer: !this.state.showCorrectAnswer
|
|
@@ -151,8 +277,10 @@ class Main extends _react.default.Component {
|
|
|
151
277
|
this.instanceId = (0, _lodashEs.uniqueId)();
|
|
152
278
|
this.state = {
|
|
153
279
|
showCorrectAnswer: false,
|
|
154
|
-
draggingElement: null
|
|
280
|
+
draggingElement: null,
|
|
281
|
+
selectedAnswer: null
|
|
155
282
|
};
|
|
283
|
+
this.lastDragEndAt = 0;
|
|
156
284
|
}
|
|
157
285
|
onRemoveAnswer(id) {
|
|
158
286
|
const {
|
|
@@ -178,10 +306,80 @@ class Main extends _react.default.Component {
|
|
|
178
306
|
prompt,
|
|
179
307
|
language
|
|
180
308
|
} = config;
|
|
309
|
+
|
|
310
|
+
// Helpers for accessible announcements
|
|
311
|
+
const getChoiceLabel = dragId => {
|
|
312
|
+
// dragId is like "choice-123" or "target-123"
|
|
313
|
+
const answerId = String(dragId).replace(/^(choice|target)-/, '');
|
|
314
|
+
const answer = config.answers.find(a => String(a.id) === answerId);
|
|
315
|
+
if (answer?.title) {
|
|
316
|
+
// Strip HTML tags for screen reader
|
|
317
|
+
const text = answer.title.replace(/<[^>]*>/g, '').trim();
|
|
318
|
+
return text || `Answer ${answerId}`;
|
|
319
|
+
}
|
|
320
|
+
return `Answer ${answerId}`;
|
|
321
|
+
};
|
|
322
|
+
const getDropTargetLabel = dropId => {
|
|
323
|
+
// dropId is like "drop-456" or "choices-pool"
|
|
324
|
+
if (dropId === 'choices-pool') {
|
|
325
|
+
return {
|
|
326
|
+
label: 'Choices list',
|
|
327
|
+
choiceId: null
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
const promptId = String(dropId).replace(/^drop-/, '');
|
|
331
|
+
const promptItem = config.prompts.find(p => String(p.id) === promptId);
|
|
332
|
+
const label = promptItem?.title ? `Response area for ${promptItem.title.replace(/<[^>]*>/g, '').trim()}` : `Response area ${promptId}`;
|
|
333
|
+
const choiceId = session.value?.[promptId];
|
|
334
|
+
return {
|
|
335
|
+
label,
|
|
336
|
+
choiceId: choiceId || null
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
const announcements = {
|
|
340
|
+
onDragStart({
|
|
341
|
+
active
|
|
342
|
+
}) {
|
|
343
|
+
return `Picked up ${getChoiceLabel(active.id)}. Use Tab to move between response areas, then press Space or Enter to drop.`;
|
|
344
|
+
},
|
|
345
|
+
onDragOver({
|
|
346
|
+
active,
|
|
347
|
+
over
|
|
348
|
+
}) {
|
|
349
|
+
if (!over) {
|
|
350
|
+
return `${getChoiceLabel(active.id)} is not over a response area.`;
|
|
351
|
+
}
|
|
352
|
+
const target = getDropTargetLabel(over.id);
|
|
353
|
+
const content = target.choiceId ? `Currently contains ${getChoiceLabel(target.choiceId)}.` : 'Currently empty.';
|
|
354
|
+
return `Over ${target.label}. ${content}`;
|
|
355
|
+
},
|
|
356
|
+
onDragEnd({
|
|
357
|
+
active,
|
|
358
|
+
over
|
|
359
|
+
}) {
|
|
360
|
+
if (!over) {
|
|
361
|
+
return `${getChoiceLabel(active.id)} was returned to its original position.`;
|
|
362
|
+
}
|
|
363
|
+
return `Dropped ${getChoiceLabel(active.id)} in ${getDropTargetLabel(over.id).label}.`;
|
|
364
|
+
},
|
|
365
|
+
onDragCancel({
|
|
366
|
+
active
|
|
367
|
+
}) {
|
|
368
|
+
return `Cancelled. ${getChoiceLabel(active.id)} was returned to its original position.`;
|
|
369
|
+
}
|
|
370
|
+
};
|
|
181
371
|
return /*#__PURE__*/_react.default.createElement(_core.DndContext, {
|
|
372
|
+
sensors: sensors,
|
|
373
|
+
collisionDetection: _core.rectIntersection,
|
|
182
374
|
onDragStart: this.onDragStart,
|
|
183
375
|
onDragEnd: this.onPlaceAnswer,
|
|
184
|
-
|
|
376
|
+
onDragCancel: this.onDragCancel,
|
|
377
|
+
modifiers: [_modifiers.restrictToFirstScrollableAncestor],
|
|
378
|
+
accessibility: {
|
|
379
|
+
screenReaderInstructions: {
|
|
380
|
+
draggable: 'Press Space or Enter to pick up this answer choice. Once picked up, use Tab or Shift+Tab to cycle through response areas, or use arrow keys to move it freely. Press Space or Enter to drop, or Escape to cancel. You can also click an answer choice to select it, then click a response area to place it there.'
|
|
381
|
+
}
|
|
382
|
+
}
|
|
185
383
|
}, /*#__PURE__*/_react.default.createElement(MainContainer, null, /*#__PURE__*/_react.default.createElement(_renderUi.PreviewPrompt, {
|
|
186
384
|
className: "prompt",
|
|
187
385
|
prompt: prompt
|
|
@@ -190,20 +388,26 @@ class Main extends _react.default.Component {
|
|
|
190
388
|
toggled: showCorrectAnswer,
|
|
191
389
|
onToggle: this.toggleShowCorrect,
|
|
192
390
|
language: language
|
|
193
|
-
}), /*#__PURE__*/_react.default.createElement(_answerArea.default, {
|
|
391
|
+
}), /*#__PURE__*/_react.default.createElement(InteractiveRegion, null, /*#__PURE__*/_react.default.createElement(InteractiveRegionContent, null, /*#__PURE__*/_react.default.createElement(_answerArea.default, {
|
|
194
392
|
instanceId: this.instanceId,
|
|
195
393
|
model: model,
|
|
196
394
|
session: session,
|
|
197
395
|
onRemoveAnswer: id => this.onRemoveAnswer(id),
|
|
198
396
|
disabled: mode !== 'gather',
|
|
199
|
-
showCorrect: showCorrectAnswer
|
|
397
|
+
showCorrect: showCorrectAnswer,
|
|
398
|
+
selectedAnswer: this.state.selectedAnswer,
|
|
399
|
+
onChoiceClick: this.onChoiceClick,
|
|
400
|
+
onPlacementClick: this.onPlacementClick
|
|
200
401
|
}), /*#__PURE__*/_react.default.createElement(_choicesList.default, {
|
|
201
402
|
instanceId: this.instanceId,
|
|
202
403
|
model: model,
|
|
203
404
|
session: session,
|
|
204
405
|
disabled: mode !== 'gather',
|
|
205
|
-
onRemoveAnswer: id => this.onRemoveAnswer(id)
|
|
206
|
-
|
|
406
|
+
onRemoveAnswer: id => this.onRemoveAnswer(id),
|
|
407
|
+
selectedAnswer: this.state.selectedAnswer,
|
|
408
|
+
onChoiceClick: this.onChoiceClick,
|
|
409
|
+
onPlacementClick: this.onPlacementClick
|
|
410
|
+
}))), model.correctness && model.feedback && !showCorrectAnswer && /*#__PURE__*/_react.default.createElement(_renderUi.Feedback, {
|
|
207
411
|
correctness: model.correctness.correctness,
|
|
208
412
|
feedback: model.feedback
|
|
209
413
|
})), /*#__PURE__*/_react.default.createElement(_core.DragOverlay, null, this.renderDragOverlay()));
|