@pie-lib/drag 2.22.3-next.2 → 2.22.4-next.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 +6 -76
- package/lib/__tests__/placeholder.test.js +140 -0
- package/lib/__tests__/uid-context.test.js +58 -0
- package/lib/drag-in-the-blank-dp.js +58 -27
- package/lib/drag-in-the-blank-dp.js.map +1 -1
- package/lib/drag-provider.js +61 -0
- package/lib/drag-provider.js.map +1 -0
- package/lib/drag-type.js +3 -4
- package/lib/drag-type.js.map +1 -1
- package/lib/draggable-choice.js +89 -0
- package/lib/draggable-choice.js.map +1 -0
- package/lib/droppable-placeholder.js +34 -66
- package/lib/droppable-placeholder.js.map +1 -1
- package/lib/ica-dp.js +27 -27
- package/lib/ica-dp.js.map +1 -1
- package/lib/index.js +8 -36
- package/lib/index.js.map +1 -1
- package/lib/match-list-dp.js +39 -27
- package/lib/match-list-dp.js.map +1 -1
- package/lib/placeholder.js +78 -100
- package/lib/placeholder.js.map +1 -1
- package/lib/preview-component.js +68 -108
- package/lib/preview-component.js.map +1 -1
- package/lib/swap.js +2 -8
- package/lib/swap.js.map +1 -1
- package/lib/uid-context.js +5 -19
- package/lib/uid-context.js.map +1 -1
- package/package.json +12 -18
- package/src/__tests__/placeholder.test.jsx +84 -25
- package/src/__tests__/uid-context.test.jsx +49 -16
- package/src/drag-in-the-blank-dp.jsx +62 -16
- package/src/drag-provider.jsx +50 -0
- package/src/drag-type.js +1 -1
- package/src/draggable-choice.jsx +88 -0
- package/src/droppable-placeholder.jsx +38 -28
- package/src/ica-dp.jsx +20 -18
- package/src/index.js +4 -8
- package/src/match-list-dp.jsx +41 -18
- package/src/placeholder.jsx +68 -72
- package/src/preview-component.jsx +62 -70
- package/esm/index.css +0 -847
- package/esm/index.js +0 -118265
- package/esm/index.js.map +0 -1
- package/esm/package.json +0 -3
- package/lib/choice.js +0 -129
- package/lib/choice.js.map +0 -1
- package/lib/with-drag-context.js +0 -59
- package/lib/with-drag-context.js.map +0 -1
- package/src/__tests__/__snapshots__/placeholder.test.jsx.snap +0 -68
- package/src/choice.jsx +0 -76
- package/src/with-drag-context.js +0 -32
package/lib/swap.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports["default"] = void 0;
|
|
9
|
-
|
|
10
8
|
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
11
|
-
|
|
12
|
-
var _default = function _default(arr, fromIndex, toIndex) {
|
|
9
|
+
var _default = exports["default"] = function _default(arr, fromIndex, toIndex) {
|
|
13
10
|
if (!arr || arr.length <= 1 || fromIndex === undefined || toIndex === undefined) {
|
|
14
11
|
throw new Error("swap requires a non-empty array, fromIndex, toIndex: ".concat(arr, ", ").concat(fromIndex, " ").concat(toIndex));
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
var update = (0, _cloneDeep["default"])(arr);
|
|
18
14
|
var tmp = arr[toIndex];
|
|
19
15
|
update[toIndex] = update[fromIndex];
|
|
20
16
|
update[fromIndex] = tmp;
|
|
21
17
|
return update;
|
|
22
18
|
};
|
|
23
|
-
|
|
24
|
-
exports["default"] = _default;
|
|
25
|
-
//# sourceMappingURL=swap.js.map
|
|
19
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfY2xvbmVEZWVwIiwiX2ludGVyb3BSZXF1aXJlRGVmYXVsdCIsInJlcXVpcmUiLCJfZGVmYXVsdCIsImV4cG9ydHMiLCJhcnIiLCJmcm9tSW5kZXgiLCJ0b0luZGV4IiwibGVuZ3RoIiwidW5kZWZpbmVkIiwiRXJyb3IiLCJjb25jYXQiLCJ1cGRhdGUi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5RE4sR0FBRyxRQUFBTSxNQUFBLENBQUtMLFNBQVMsT0FBQUssTUFBQSxDQUFJSixPQUFPLENBQUUsQ0FBQztFQUN6RztFQUVBLElBQU1LLE1BQU0sR0FBRyxJQUFBQyxxQkFBUyxFQUFDUixHQUFHLENBQUM7RUFDN0IsSUFBTVMsR0FBRyxHQUFHVCxHQUFHLENBQUNFLE9BQU8sQ0FBQztFQUN4QkssTUFBTSxDQUFDTCxPQUFPLENBQUMsR0FBR0ssTUFBTSxDQUFDTixTQUFTLENBQUM7RUFDbkNNLE1BQU0sQ0FBQ04sU0FBUyxDQUFDLEdBQUdRLEdBQUc7RUFFdkIsT0FBT0YsTUFBTTtBQUNmLENBQUMiLCJpZ25vcmVMaXN0IjpbXX0=
|
package/lib/swap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"swap.js","names":["_cloneDeep","_interopRequireDefault","require","_default","exports","arr","fromIndex","toIndex","length","undefined","Error","concat","update","cloneDeep","tmp"],"sources":["../src/swap.js"],"sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\n\nexport default (arr, fromIndex, toIndex) => {\n if (!arr || arr.length <= 1 || fromIndex === undefined || toIndex === undefined) {\n throw new Error(`swap requires a non-empty array, fromIndex, toIndex: ${arr}, ${fromIndex} ${toIndex}`);\n }\n\n const update = cloneDeep(arr);\n const tmp = arr[toIndex];\n update[toIndex] = update[fromIndex];\n update[fromIndex] = tmp;\n\n return update;\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAyC,IAAAC,QAAA,GAAAC,OAAA,cAE1B,SAAAD,SAACE,GAAG,EAAEC,SAAS,EAAEC,OAAO,EAAK;EAC1C,IAAI,CAACF,GAAG,IAAIA,GAAG,CAACG,MAAM,IAAI,CAAC,IAAIF,SAAS,KAAKG,SAAS,IAAIF,OAAO,KAAKE,SAAS,EAAE;IAC/E,MAAM,IAAIC,KAAK,yDAAAC,MAAA,CAAyDN,GAAG,QAAAM,MAAA,CAAKL,SAAS,OAAAK,MAAA,CAAIJ,OAAO,CAAE,CAAC;EACzG;EAEA,IAAMK,MAAM,GAAG,IAAAC,qBAAS,EAACR,GAAG,CAAC;EAC7B,IAAMS,GAAG,GAAGT,GAAG,CAACE,OAAO,CAAC;EACxBK,MAAM,CAACL,OAAO,CAAC,GAAGK,MAAM,CAACN,SAAS,CAAC;EACnCM,MAAM,CAACN,SAAS,CAAC,GAAGQ,GAAG;EAEvB,OAAOF,MAAM;AACf,CAAC","ignoreList":[]}
|
package/lib/uid-context.js
CHANGED
|
@@ -1,30 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.withUid = exports.generateId = exports.Provider = exports.Consumer = void 0;
|
|
9
|
-
|
|
10
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
-
|
|
12
9
|
var _react = _interopRequireDefault(require("react"));
|
|
13
|
-
|
|
14
10
|
var _React$createContext = /*#__PURE__*/_react["default"].createContext(-1),
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
exports.Provider = Provider;
|
|
19
|
-
exports.Consumer = Consumer;
|
|
20
|
-
|
|
21
|
-
var generateId = function generateId() {
|
|
11
|
+
Consumer = exports.Consumer = _React$createContext.Consumer,
|
|
12
|
+
Provider = exports.Provider = _React$createContext.Provider;
|
|
13
|
+
var generateId = exports.generateId = function generateId() {
|
|
22
14
|
return (Math.random() * 1000001).toFixed(0);
|
|
23
15
|
};
|
|
24
|
-
|
|
25
|
-
exports.generateId = generateId;
|
|
26
|
-
|
|
27
|
-
var withUid = function withUid(Component) {
|
|
16
|
+
var withUid = exports.withUid = function withUid(Component) {
|
|
28
17
|
var Wrapped = function Wrapped(props) {
|
|
29
18
|
return /*#__PURE__*/_react["default"].createElement(Consumer, null, function (uid) {
|
|
30
19
|
return /*#__PURE__*/_react["default"].createElement(Component, (0, _extends2["default"])({}, props, {
|
|
@@ -32,9 +21,6 @@ var withUid = function withUid(Component) {
|
|
|
32
21
|
}));
|
|
33
22
|
});
|
|
34
23
|
};
|
|
35
|
-
|
|
36
24
|
return Wrapped;
|
|
37
25
|
};
|
|
38
|
-
|
|
39
|
-
exports.withUid = withUid;
|
|
40
|
-
//# sourceMappingURL=uid-context.js.map
|
|
26
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJfcmVhY3QiLCJfaW50ZXJvcFJlcXVpcmVEZWZhdWx0IiwicmVxdWlyZSIsIl9SZWFjdCRjcmVhdGVDb250ZXh0IiwiUmVhY3QiLCJjcmVhdGVDb250ZXh0IiwiQ29uc3VtZXIiLCJleHBvcnRzIiwiUHJvdmlkZXIiLCJnZW5lcmF0ZUlkIiwiTWF0aCIsInJhbmRvbSIsInRvRml4ZWQiLCJ3aXRoVWlkIiwiQ29tcG9uZW50IiwiV3JhcHBlZCIsInByb3BzIiwiY3JlYXRlRWxlbWVudCIsInVpZCIsIl9leHRlbmRzMiJdLCJzb3VyY2VzIjpbIi4uL3NyYy91aWQtY29udGV4dC5qcyJdLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgUmVhY3QgZnJvbSAncmVhY3QnO1xuXG5jb25zdCB7IENvbnN1bWVyLCBQcm92aWRlciB9ID0gUmVhY3QuY3JlYXRlQ29udGV4dCgtMSk7XG5cbmV4cG9ydCB7IFByb3ZpZGVyLCBDb25zdW1lciB9O1xuXG5leHBvcnQgY29uc3QgZ2VuZXJhdGVJZCA9ICgpID0+IChNYXRoLnJhbmRvbSgpICogMTAwMDAwMSkudG9GaXhlZCgwKTtcblxuZXhwb3J0IGNvbnN0IHdpdGhVaWQgPSAoQ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Q0FBQztJQUFBLENBQVcsQ0FBQztFQUFBO0VBRTdGLE9BQU9ILE9BQU87QUFDaEIsQ0FBQyIsImlnbm9yZUxpc3QiOltdfQ==
|
package/lib/uid-context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"uid-context.js","names":["_react","_interopRequireDefault","require","_React$createContext","React","createContext","Consumer","exports","Provider","generateId","Math","random","toFixed","withUid","Component","Wrapped","props","createElement","uid","_extends2"],"sources":["../src/uid-context.js"],"sourcesContent":["import React from 'react';\n\nconst { Consumer, Provider } = React.createContext(-1);\n\nexport { Provider, Consumer };\n\nexport const generateId = () => (Math.random() * 1000001).toFixed(0);\n\nexport const withUid = (Component) => {\n const Wrapped = (props) => <Consumer>{(uid) => <Component {...props} uid={uid} />}</Consumer>;\n\n return Wrapped;\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,oBAAA,gBAA+BC,iBAAK,CAACC,aAAa,CAAC,CAAC,CAAC,CAAC;EAA9CC,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAAH,oBAAA,CAARG,QAAQ;EAAEE,QAAQ,GAAAD,OAAA,CAAAC,QAAA,GAAAL,oBAAA,CAARK,QAAQ;AAInB,IAAMC,UAAU,GAAAF,OAAA,CAAAE,UAAA,GAAG,SAAbA,UAAUA,CAAA;EAAA,OAAS,CAACC,IAAI,CAACC,MAAM,CAAC,CAAC,GAAG,OAAO,EAAEC,OAAO,CAAC,CAAC,CAAC;AAAA;AAE7D,IAAMC,OAAO,GAAAN,OAAA,CAAAM,OAAA,GAAG,SAAVA,OAAOA,CAAIC,SAAS,EAAK;EACpC,IAAMC,OAAO,GAAG,SAAVA,OAAOA,CAAIC,KAAK;IAAA,oBAAKhB,MAAA,YAAAiB,aAAA,CAACX,QAAQ,QAAE,UAACY,GAAG;MAAA,oBAAKlB,MAAA,YAAAiB,aAAA,CAACH,SAAS,MAAAK,SAAA,iBAAKH,KAAK;QAAEE,GAAG,EAAEA;MAAI,EAAE,CAAC;IAAA,CAAW,CAAC;EAAA;EAE7F,OAAOH,OAAO;AAChB,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/drag",
|
|
3
|
-
"version": "2.22.
|
|
3
|
+
"version": "2.22.4-next.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@
|
|
9
|
-
"@
|
|
10
|
-
"@
|
|
8
|
+
"@dnd-kit/core": "6.1.0",
|
|
9
|
+
"@dnd-kit/sortable": "8.0.0",
|
|
10
|
+
"@dnd-kit/utilities": "3.2.2",
|
|
11
|
+
"@emotion/react": "^11.14.0",
|
|
12
|
+
"@emotion/style": "^0.8.0",
|
|
13
|
+
"@mui/icons-material": "^7.3.4",
|
|
14
|
+
"@mui/material": "^7.3.4",
|
|
15
|
+
"@pie-lib/math-rendering": "3.22.3-next.0",
|
|
16
|
+
"@pie-lib/render-ui": "4.35.4-next.0",
|
|
11
17
|
"classnames": "^2.2.6",
|
|
12
18
|
"lodash": "^4.17.11",
|
|
13
19
|
"prop-types": "^15.7.2",
|
|
14
|
-
"react": "^
|
|
15
|
-
"react-dnd": "^14.0.5",
|
|
16
|
-
"react-dnd-html5-backend": "^14.0.2",
|
|
17
|
-
"react-dnd-multi-backend": "^6.0.2",
|
|
18
|
-
"react-dnd-touch-backend": "^12.0.0"
|
|
20
|
+
"react": "^18.2.0"
|
|
19
21
|
},
|
|
20
22
|
"publishConfig": {
|
|
21
23
|
"access": "public"
|
|
@@ -23,13 +25,5 @@
|
|
|
23
25
|
"scripts": {},
|
|
24
26
|
"author": "",
|
|
25
27
|
"license": "ISC",
|
|
26
|
-
"gitHead": "
|
|
27
|
-
"exports": {
|
|
28
|
-
".": {
|
|
29
|
-
"require": "./lib/index.js",
|
|
30
|
-
"import": "./src/index.js",
|
|
31
|
-
"default": "./lib/index.js"
|
|
32
|
-
},
|
|
33
|
-
"./esm": "./esm/index.js"
|
|
34
|
-
}
|
|
28
|
+
"gitHead": "ad47e833acbaecca94eab8df2aee2a1ee9d90516"
|
|
35
29
|
}
|
|
@@ -1,48 +1,107 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { PlaceHolder } from '../placeholder';
|
|
4
4
|
|
|
5
5
|
describe('placeholder', () => {
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
placeholder: 'placeholder',
|
|
10
|
-
disabled: 'disabled',
|
|
11
|
-
over: 'over',
|
|
12
|
-
number: 'number',
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
const props = { ...defaults, ...extras };
|
|
16
|
-
return shallow(<PlaceHolder {...props}> Foo </PlaceHolder>);
|
|
6
|
+
const renderComponent = (extras = {}) => {
|
|
7
|
+
const props = { ...extras };
|
|
8
|
+
return render(<PlaceHolder {...props}>Foo</PlaceHolder>);
|
|
17
9
|
};
|
|
18
10
|
|
|
19
|
-
describe('
|
|
20
|
-
it('
|
|
21
|
-
|
|
22
|
-
expect(
|
|
11
|
+
describe('rendering', () => {
|
|
12
|
+
it('renders children content', () => {
|
|
13
|
+
renderComponent();
|
|
14
|
+
expect(screen.getByText('Foo')).toBeInTheDocument();
|
|
23
15
|
});
|
|
24
16
|
|
|
25
|
-
it('
|
|
26
|
-
|
|
17
|
+
it('renders with regular placeholder class', () => {
|
|
18
|
+
const { container } = renderComponent();
|
|
19
|
+
const placeholder = container.firstChild;
|
|
20
|
+
expect(placeholder).toHaveClass('placeholder');
|
|
27
21
|
});
|
|
28
22
|
|
|
29
|
-
it('
|
|
30
|
-
|
|
23
|
+
it('applies over class when isOver is true', () => {
|
|
24
|
+
const { container } = renderComponent({ isOver: true });
|
|
25
|
+
const placeholder = container.firstChild;
|
|
26
|
+
expect(placeholder).toHaveClass('over');
|
|
31
27
|
});
|
|
32
28
|
|
|
33
|
-
it('
|
|
34
|
-
|
|
29
|
+
it('applies disabled class when disabled is true', () => {
|
|
30
|
+
const { container } = renderComponent({ disabled: true });
|
|
31
|
+
const placeholder = container.firstChild;
|
|
32
|
+
expect(placeholder).toHaveClass('disabled');
|
|
35
33
|
});
|
|
36
34
|
|
|
37
|
-
it('
|
|
38
|
-
const
|
|
35
|
+
it('applies custom className', () => {
|
|
36
|
+
const { container } = renderComponent({ className: 'bar' });
|
|
37
|
+
const placeholder = container.firstChild;
|
|
38
|
+
expect(placeholder).toHaveClass('bar');
|
|
39
|
+
expect(placeholder).toHaveClass('placeholder');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('applies choice type class', () => {
|
|
43
|
+
const { container } = renderComponent({ type: 'choice' });
|
|
44
|
+
const placeholder = container.firstChild;
|
|
45
|
+
expect(placeholder).toHaveClass('choice');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('applies board class when choiceBoard is true', () => {
|
|
49
|
+
const { container } = renderComponent({ choiceBoard: true });
|
|
50
|
+
const placeholder = container.firstChild;
|
|
51
|
+
expect(placeholder).toHaveClass('board');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('applies categorizeBoard class when choiceBoard and isCategorize are true', () => {
|
|
55
|
+
const { container } = renderComponent({ choiceBoard: true, isCategorize: true });
|
|
56
|
+
const placeholder = container.firstChild;
|
|
57
|
+
expect(placeholder).toHaveClass('categorizeBoard');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('applies verticalPool class when isVerticalPool is true', () => {
|
|
61
|
+
const { container } = renderComponent({ isVerticalPool: true });
|
|
62
|
+
const placeholder = container.firstChild;
|
|
63
|
+
expect(placeholder).toHaveClass('verticalPool');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('grid styles', () => {
|
|
68
|
+
it('applies grid column styles', () => {
|
|
69
|
+
const { container } = renderComponent({
|
|
70
|
+
grid: { columns: 3 },
|
|
71
|
+
});
|
|
72
|
+
const placeholder = container.firstChild;
|
|
73
|
+
expect(placeholder).toHaveStyle({ gridTemplateColumns: 'repeat(3, 1fr)' });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('applies grid row styles with default value', () => {
|
|
77
|
+
const { container } = renderComponent({
|
|
78
|
+
grid: { rows: 2 },
|
|
79
|
+
});
|
|
80
|
+
const placeholder = container.firstChild;
|
|
81
|
+
expect(placeholder).toHaveStyle({ gridTemplateRows: 'repeat(2, 1fr)' });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('applies grid row styles with custom rowsRepeatValue', () => {
|
|
85
|
+
const { container } = renderComponent({
|
|
39
86
|
grid: {
|
|
40
87
|
rows: 2,
|
|
41
88
|
columns: 1,
|
|
42
89
|
rowsRepeatValue: 'min-content',
|
|
43
90
|
},
|
|
44
91
|
});
|
|
45
|
-
|
|
92
|
+
const placeholder = container.firstChild;
|
|
93
|
+
expect(placeholder).toHaveStyle({
|
|
94
|
+
gridTemplateRows: 'repeat(2, min-content)',
|
|
95
|
+
gridTemplateColumns: 'repeat(1, 1fr)',
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('min height', () => {
|
|
101
|
+
it('applies minHeight style when provided', () => {
|
|
102
|
+
const { container } = renderComponent({ minHeight: 200 });
|
|
103
|
+
const placeholder = container.firstChild;
|
|
104
|
+
expect(placeholder).toHaveStyle({ minHeight: '200px' });
|
|
46
105
|
});
|
|
47
106
|
});
|
|
48
107
|
});
|
|
@@ -1,21 +1,54 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
createContext: jest.fn().mockReturnValue({
|
|
7
|
-
Consumer: jest.fn((fn) => fn),
|
|
8
|
-
Provider: jest.fn(),
|
|
9
|
-
}),
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
describe('id-context', () => {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { withUid, Provider as UidProvider } from '../uid-context';
|
|
4
|
+
|
|
5
|
+
describe('uid-context', () => {
|
|
13
6
|
describe('withUid', () => {
|
|
14
|
-
it('
|
|
15
|
-
const
|
|
7
|
+
it('provides uid to wrapped component', () => {
|
|
8
|
+
const TestComponent = ({ uid }) => <div data-testid="test-uid">{uid}</div>;
|
|
9
|
+
const WrappedComponent = withUid(TestComponent);
|
|
10
|
+
|
|
11
|
+
render(
|
|
12
|
+
<UidProvider value="test-uid-123">
|
|
13
|
+
<WrappedComponent />
|
|
14
|
+
</UidProvider>,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
expect(screen.getByTestId('test-uid')).toHaveTextContent('test-uid-123');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('passes through other props to wrapped component', () => {
|
|
21
|
+
const TestComponent = ({ uid, customProp }) => (
|
|
22
|
+
<div>
|
|
23
|
+
<span data-testid="uid">{uid}</span>
|
|
24
|
+
<span data-testid="custom">{customProp}</span>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
const WrappedComponent = withUid(TestComponent);
|
|
28
|
+
|
|
29
|
+
render(
|
|
30
|
+
<UidProvider value="test-uid">
|
|
31
|
+
<WrappedComponent customProp="custom-value" />
|
|
32
|
+
</UidProvider>,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(screen.getByTestId('uid')).toHaveTextContent('test-uid');
|
|
36
|
+
expect(screen.getByTestId('custom')).toHaveTextContent('custom-value');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('UidProvider', () => {
|
|
41
|
+
it('provides uid context to children', () => {
|
|
42
|
+
const TestComponent = ({ uid }) => <div data-testid="uid-value">{uid}</div>;
|
|
43
|
+
const WrappedComponent = withUid(TestComponent);
|
|
44
|
+
|
|
45
|
+
render(
|
|
46
|
+
<UidProvider value="provider-uid">
|
|
47
|
+
<WrappedComponent />
|
|
48
|
+
</UidProvider>,
|
|
49
|
+
);
|
|
16
50
|
|
|
17
|
-
|
|
18
|
-
expect(createElement).toBeCalledWith(expect.any(Function), null, expect.anything());
|
|
51
|
+
expect(screen.getByTestId('uid-value')).toHaveTextContent('provider-uid');
|
|
19
52
|
});
|
|
20
53
|
});
|
|
21
54
|
});
|
|
@@ -1,19 +1,65 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import PlaceHolder from './placeholder';
|
|
4
|
+
import { useDroppable } from '@dnd-kit/core';
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
// With @dnd-kit, the drop logic is handled in the DragProvider's onDragEnd callback
|
|
8
|
+
// This component now just wraps DroppablePlaceholder with drag-in-the-blank specific logic
|
|
9
|
+
|
|
10
|
+
const DroppablePlaceholderContainer = styled('div')({
|
|
11
|
+
minHeight: '100px',
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export function DragInTheBlankDroppable({
|
|
15
|
+
children,
|
|
16
|
+
disabled,
|
|
17
|
+
classes,
|
|
18
|
+
isVerticalPool,
|
|
19
|
+
minHeight,
|
|
20
|
+
instanceId,
|
|
21
|
+
...rest
|
|
22
|
+
}) {
|
|
23
|
+
// The actual drop handling will be managed by the parent component
|
|
24
|
+
// through the DragProvider's onDragEnd callback
|
|
25
|
+
const { setNodeRef, isOver } = useDroppable({
|
|
26
|
+
id: 'drag-in-the-blank-droppable',
|
|
27
|
+
data: {
|
|
28
|
+
type: 'MaskBlank',
|
|
29
|
+
accepts: ['MaskBlank'],
|
|
30
|
+
id: 'drag-in-the-blank-droppable',
|
|
31
|
+
toChoiceBoard: true,
|
|
32
|
+
instanceId
|
|
33
|
+
}
|
|
34
|
+
});
|
|
13
35
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
36
|
+
return (
|
|
37
|
+
<div ref={setNodeRef} >
|
|
38
|
+
<DroppablePlaceholderContainer>
|
|
39
|
+
<PlaceHolder
|
|
40
|
+
isOver={isOver}
|
|
41
|
+
choiceBoard={true}
|
|
42
|
+
className={classes}
|
|
43
|
+
isVerticalPool={isVerticalPool}
|
|
44
|
+
extraStyles={{
|
|
45
|
+
width: '100%',
|
|
46
|
+
minHeight: minHeight || 100,
|
|
47
|
+
height: 'auto',
|
|
48
|
+
}}
|
|
49
|
+
>
|
|
50
|
+
{children}
|
|
51
|
+
</PlaceHolder>
|
|
52
|
+
</DroppablePlaceholderContainer>
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
DragInTheBlankDroppable.propTypes = {
|
|
58
|
+
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
59
|
+
children: PropTypes.node,
|
|
60
|
+
disabled: PropTypes.bool,
|
|
61
|
+
onDrop: PropTypes.func,
|
|
62
|
+
instanceId: PropTypes.string,
|
|
63
|
+
};
|
|
18
64
|
|
|
19
|
-
export default
|
|
65
|
+
export default DragInTheBlankDroppable;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { DndContext, PointerSensor, KeyboardSensor, useSensor, useSensors } from '@dnd-kit/core';
|
|
4
|
+
|
|
5
|
+
export function DragProvider({ children, onDragEnd, onDragStart, collisionDetection, modifiers, autoScroll }) {
|
|
6
|
+
const [activeId, setActiveId] = useState(null);
|
|
7
|
+
|
|
8
|
+
const sensors = useSensors(
|
|
9
|
+
useSensor(PointerSensor, { activationConstraint: { distance: 8 }}),
|
|
10
|
+
useSensor(KeyboardSensor)
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const handleDragStart = (event) => {
|
|
14
|
+
setActiveId(event.active.id);
|
|
15
|
+
if (onDragStart) {
|
|
16
|
+
onDragStart(event);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const handleDragEnd = (event) => {
|
|
21
|
+
setActiveId(null);
|
|
22
|
+
if (onDragEnd) {
|
|
23
|
+
onDragEnd(event);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<DndContext
|
|
29
|
+
sensors={sensors}
|
|
30
|
+
onDragStart={handleDragStart}
|
|
31
|
+
onDragEnd={handleDragEnd}
|
|
32
|
+
collisionDetection={collisionDetection}
|
|
33
|
+
modifiers={modifiers}
|
|
34
|
+
autoScroll={autoScroll}
|
|
35
|
+
>
|
|
36
|
+
{children}
|
|
37
|
+
</DndContext>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
DragProvider.propTypes = {
|
|
42
|
+
children: PropTypes.node.isRequired,
|
|
43
|
+
onDragEnd: PropTypes.func,
|
|
44
|
+
onDragStart: PropTypes.func,
|
|
45
|
+
collisionDetection: PropTypes.func,
|
|
46
|
+
modifiers: PropTypes.arrayOf(PropTypes.func),
|
|
47
|
+
autoScroll: PropTypes.object,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default DragProvider;
|
package/src/drag-type.js
CHANGED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import { useDraggable } from '@dnd-kit/core';
|
|
5
|
+
import { grey } from '@mui/material/colors';
|
|
6
|
+
|
|
7
|
+
export const DRAG_TYPE = 'CHOICE';
|
|
8
|
+
|
|
9
|
+
const StyledChoice = styled('div')(({ theme }) => ({
|
|
10
|
+
backgroundColor: theme.palette.background.paper,
|
|
11
|
+
border: `solid 1px ${grey[400]}`,
|
|
12
|
+
padding: theme.spacing(1),
|
|
13
|
+
minHeight: '30px',
|
|
14
|
+
minWidth: theme.spacing(20),
|
|
15
|
+
maxWidth: theme.spacing(75),
|
|
16
|
+
cursor: 'grab',
|
|
17
|
+
'&:active': {
|
|
18
|
+
cursor: 'grabbing',
|
|
19
|
+
},
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
export function DraggableChoice({
|
|
23
|
+
choice,
|
|
24
|
+
children,
|
|
25
|
+
className,
|
|
26
|
+
disabled,
|
|
27
|
+
category,
|
|
28
|
+
alternateResponseIndex,
|
|
29
|
+
choiceIndex,
|
|
30
|
+
onRemoveChoice,
|
|
31
|
+
type,
|
|
32
|
+
id
|
|
33
|
+
}) {
|
|
34
|
+
const {
|
|
35
|
+
attributes,
|
|
36
|
+
listeners,
|
|
37
|
+
setNodeRef,
|
|
38
|
+
isDragging
|
|
39
|
+
} = useDraggable({
|
|
40
|
+
id: id || choice.id, // id to be used for dnd-kit
|
|
41
|
+
disabled: disabled,
|
|
42
|
+
categoryId: category?.id,
|
|
43
|
+
alternateResponseIndex,
|
|
44
|
+
data: {
|
|
45
|
+
id: choice.id,
|
|
46
|
+
value: choice.value,
|
|
47
|
+
choiceId: choice.id,
|
|
48
|
+
from: category?.id,
|
|
49
|
+
categoryId: category?.id,
|
|
50
|
+
alternateResponseIndex,
|
|
51
|
+
choiceIndex,
|
|
52
|
+
onRemoveChoice,
|
|
53
|
+
type
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<StyledChoice
|
|
59
|
+
ref={setNodeRef}
|
|
60
|
+
className={className}
|
|
61
|
+
isDragging={isDragging}
|
|
62
|
+
{...attributes}
|
|
63
|
+
{...listeners}
|
|
64
|
+
>
|
|
65
|
+
{children}
|
|
66
|
+
</StyledChoice>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
DraggableChoice.propTypes = {
|
|
71
|
+
choice: PropTypes.shape({
|
|
72
|
+
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
73
|
+
value: PropTypes.any,
|
|
74
|
+
}).isRequired,
|
|
75
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
|
|
76
|
+
className: PropTypes.string,
|
|
77
|
+
disabled: PropTypes.bool,
|
|
78
|
+
category: PropTypes.shape({
|
|
79
|
+
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
80
|
+
}),
|
|
81
|
+
alternateResponseIndex: PropTypes.number,
|
|
82
|
+
choiceIndex: PropTypes.number,
|
|
83
|
+
onRemoveChoice: PropTypes.func,
|
|
84
|
+
type: PropTypes.string,
|
|
85
|
+
id: PropTypes.string,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default DraggableChoice;
|
|
@@ -1,38 +1,48 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PlaceHolder from './placeholder';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
+
import { useDroppable } from '@dnd-kit/core';
|
|
4
5
|
|
|
5
6
|
const preventInteractionStyle = {
|
|
6
7
|
flex: 1,
|
|
7
8
|
};
|
|
8
9
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
export function DroppablePlaceholder({
|
|
11
|
+
id,
|
|
12
|
+
children,
|
|
13
|
+
disabled,
|
|
14
|
+
classes,
|
|
15
|
+
isVerticalPool,
|
|
16
|
+
minHeight
|
|
17
|
+
}) {
|
|
18
|
+
const { setNodeRef, isOver } = useDroppable({
|
|
19
|
+
id,
|
|
20
|
+
disabled
|
|
21
|
+
});
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
</PlaceHolder>
|
|
35
|
-
</div>,
|
|
36
|
-
);
|
|
37
|
-
}
|
|
23
|
+
return (
|
|
24
|
+
<div ref={setNodeRef} style={preventInteractionStyle}>
|
|
25
|
+
<PlaceHolder
|
|
26
|
+
disabled={disabled}
|
|
27
|
+
isOver={isOver}
|
|
28
|
+
choiceBoard={true}
|
|
29
|
+
className={classes}
|
|
30
|
+
isVerticalPool={isVerticalPool}
|
|
31
|
+
minHeight={minHeight}
|
|
32
|
+
>
|
|
33
|
+
{children}
|
|
34
|
+
</PlaceHolder>
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
38
37
|
}
|
|
38
|
+
|
|
39
|
+
DroppablePlaceholder.propTypes = {
|
|
40
|
+
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
|
41
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
42
|
+
disabled: PropTypes.bool,
|
|
43
|
+
classes: PropTypes.object,
|
|
44
|
+
isVerticalPool: PropTypes.bool,
|
|
45
|
+
minHeight: PropTypes.number,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default DroppablePlaceholder;
|