@pie-lib/drag 2.2.9 → 2.3.1-beta.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 +18 -34
- package/NEXT.CHANGELOG.json +1 -0
- package/package.json +6 -4
- package/src/__tests__/__snapshots__/placeholder.test.jsx.snap +68 -0
- package/src/__tests__/placeholder.test.jsx +48 -0
- package/src/__tests__/uid-context.test.jsx +21 -0
- package/src/drag-in-the-blank-dp.jsx +1 -1
- package/src/droppable-placeholder.jsx +11 -8
- package/src/placeholder.jsx +65 -6
- package/src/preview-component.jsx +58 -19
- package/src/with-drag-context.js +15 -8
- package/README.md +0 -3
- package/lib/choice.js +0 -129
- package/lib/choice.js.map +0 -1
- package/lib/drag-in-the-blank-dp.js +0 -35
- package/lib/drag-in-the-blank-dp.js.map +0 -1
- package/lib/drag-type.js +0 -15
- package/lib/drag-type.js.map +0 -1
- package/lib/droppable-placeholder.js +0 -82
- package/lib/droppable-placeholder.js.map +0 -1
- package/lib/ica-dp.js +0 -37
- package/lib/ica-dp.js.map +0 -1
- package/lib/index.js +0 -89
- package/lib/index.js.map +0 -1
- package/lib/match-list-dp.js +0 -37
- package/lib/match-list-dp.js.map +0 -1
- package/lib/placeholder.js +0 -104
- package/lib/placeholder.js.map +0 -1
- package/lib/preview-component.js +0 -142
- package/lib/preview-component.js.map +0 -1
- package/lib/swap.js +0 -25
- package/lib/swap.js.map +0 -1
- package/lib/uid-context.js +0 -40
- package/lib/uid-context.js.map +0 -1
- package/lib/with-drag-context.js +0 -54
- package/lib/with-drag-context.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,18 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [2.
|
|
7
|
-
|
|
6
|
+
## [2.3.1-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.9...@pie-lib/drag@2.3.1-beta.0) (2025-07-20)
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* revert to pie-lib/math-rendering that what working ([25660ea](https://github.com/pie-framework/pie-lib/commit/25660ea6595e800a71c5494bd3bb9eecd3609a5a))
|
|
8
|
+
**Note:** Version bump only for package @pie-lib/drag
|
|
12
9
|
|
|
13
10
|
|
|
14
11
|
|
|
15
12
|
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
# [2.3.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.9...@pie-lib/drag@2.3.0-beta.0) (2025-07-20)
|
|
18
15
|
|
|
19
16
|
**Note:** Version bump only for package @pie-lib/drag
|
|
20
17
|
|
|
@@ -22,71 +19,58 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
22
19
|
|
|
23
20
|
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
# [2.4.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.9...@pie-lib/drag@2.4.0-beta.0) (2025-07-15)
|
|
26
23
|
|
|
27
24
|
**Note:** Version bump only for package @pie-lib/drag
|
|
28
25
|
|
|
26
|
+
# [2.3.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.9...@pie-lib/drag@2.3.0-beta.0) (2025-07-15)
|
|
29
27
|
|
|
28
|
+
**Note:** Version bump only for package @pie-lib/drag
|
|
29
|
+
|
|
30
|
+
## [2.2.9](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.8...@pie-lib/drag@2.2.9) (2023-10-03)
|
|
30
31
|
|
|
32
|
+
### Bug Fixes
|
|
31
33
|
|
|
34
|
+
- revert to pie-lib/math-rendering that what working ([25660ea](https://github.com/pie-framework/pie-lib/commit/25660ea6595e800a71c5494bd3bb9eecd3609a5a))
|
|
32
35
|
|
|
33
|
-
## [2.2.
|
|
36
|
+
## [2.2.8](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.7...@pie-lib/drag@2.2.8) (2023-10-01)
|
|
34
37
|
|
|
35
38
|
**Note:** Version bump only for package @pie-lib/drag
|
|
36
39
|
|
|
40
|
+
## [2.2.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.6...@pie-lib/drag@2.2.7) (2023-09-27)
|
|
37
41
|
|
|
42
|
+
**Note:** Version bump only for package @pie-lib/drag
|
|
38
43
|
|
|
44
|
+
## [2.2.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.5...@pie-lib/drag@2.2.6) (2023-09-27)
|
|
39
45
|
|
|
46
|
+
**Note:** Version bump only for package @pie-lib/drag
|
|
40
47
|
|
|
41
48
|
## [2.2.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.4...@pie-lib/drag@2.2.5) (2023-09-27)
|
|
42
49
|
|
|
43
|
-
|
|
44
50
|
### Bug Fixes
|
|
45
51
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
- add required packages ([b0b6855](https://github.com/pie-framework/pie-lib/commit/b0b6855418a988ed6ea911c97425b89fbab2794d))
|
|
51
53
|
|
|
52
54
|
## [2.2.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.3...@pie-lib/drag@2.2.4) (2023-08-07)
|
|
53
55
|
|
|
54
|
-
|
|
55
56
|
### Bug Fixes
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
- **drag:** create droppablePlaceholder for ICA PD-3050 ([b2e595e](https://github.com/pie-framework/pie-lib/commit/b2e595e66b331147064c6b72fa44ba756078f159))
|
|
62
59
|
|
|
63
60
|
## [2.2.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.2...@pie-lib/drag@2.2.3) (2023-07-31)
|
|
64
61
|
|
|
65
62
|
**Note:** Version bump only for package @pie-lib/drag
|
|
66
63
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
64
|
## [2.2.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.1...@pie-lib/drag@2.2.2) (2023-07-24)
|
|
72
65
|
|
|
73
|
-
|
|
74
66
|
### Bug Fixes
|
|
75
67
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
- **drag-in-the-blank:** add preview for draged items on touch backend, wip ([4e4bab6](https://github.com/pie-framework/pie-lib/commit/4e4bab63fb69e53d4cdff303d5bfd4fc18a5c7a0))
|
|
81
69
|
|
|
82
70
|
## [2.2.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.2.0...@pie-lib/drag@2.2.1) (2023-06-24)
|
|
83
71
|
|
|
84
72
|
**Note:** Version bump only for package @pie-lib/drag
|
|
85
73
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
74
|
# [2.2.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.1.19...@pie-lib/drag@2.2.0) (2023-06-12)
|
|
91
75
|
|
|
92
76
|
### Features
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/drag",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1-beta.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@material-ui/core": "^3.8.3",
|
|
9
|
-
"@pie-lib/math-rendering": "
|
|
10
|
-
"@pie-lib/render-ui": "^4.
|
|
9
|
+
"@pie-lib/math-rendering": "^3.3.1-beta.0",
|
|
10
|
+
"@pie-lib/render-ui": "^4.16.1-beta.0",
|
|
11
11
|
"classnames": "^2.2.6",
|
|
12
12
|
"lodash": "^4.17.11",
|
|
13
|
+
"prop-types": "^15.7.2",
|
|
14
|
+
"react": "^16.8.1",
|
|
13
15
|
"react-dnd": "^14.0.5",
|
|
14
16
|
"react-dnd-html5-backend": "^14.0.2",
|
|
15
17
|
"react-dnd-multi-backend": "^6.0.2",
|
|
@@ -21,5 +23,5 @@
|
|
|
21
23
|
"scripts": {},
|
|
22
24
|
"author": "",
|
|
23
25
|
"license": "ISC",
|
|
24
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "e2aa3ddac60f49bcb8c2562370f496323642f453"
|
|
25
27
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`placeholder snapshot className 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
className="placeholder bar"
|
|
6
|
+
style={
|
|
7
|
+
Object {
|
|
8
|
+
"minHeight": undefined,
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
>
|
|
12
|
+
Foo
|
|
13
|
+
</div>
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
exports[`placeholder snapshot disabled: true 1`] = `
|
|
17
|
+
<div
|
|
18
|
+
className="placeholder disabled"
|
|
19
|
+
style={
|
|
20
|
+
Object {
|
|
21
|
+
"minHeight": undefined,
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
>
|
|
25
|
+
Foo
|
|
26
|
+
</div>
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
exports[`placeholder snapshot isOver: true 1`] = `
|
|
30
|
+
<div
|
|
31
|
+
className="placeholder over"
|
|
32
|
+
style={
|
|
33
|
+
Object {
|
|
34
|
+
"minHeight": undefined,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
>
|
|
38
|
+
Foo
|
|
39
|
+
</div>
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
exports[`placeholder snapshot reqular 1`] = `
|
|
43
|
+
<div
|
|
44
|
+
className="placeholder"
|
|
45
|
+
style={
|
|
46
|
+
Object {
|
|
47
|
+
"minHeight": undefined,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
>
|
|
51
|
+
Foo
|
|
52
|
+
</div>
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
exports[`placeholder snapshot specific grid rowsRepeatValue 1`] = `
|
|
56
|
+
<div
|
|
57
|
+
className="placeholder"
|
|
58
|
+
style={
|
|
59
|
+
Object {
|
|
60
|
+
"gridTemplateColumns": "repeat(1, 1fr)",
|
|
61
|
+
"gridTemplateRows": "repeat(2, min-content)",
|
|
62
|
+
"minHeight": undefined,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
>
|
|
66
|
+
Foo
|
|
67
|
+
</div>
|
|
68
|
+
`;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { PlaceHolder } from '../placeholder';
|
|
4
|
+
|
|
5
|
+
describe('placeholder', () => {
|
|
6
|
+
const wrapper = (extras) => {
|
|
7
|
+
const defaults = {
|
|
8
|
+
classes: {
|
|
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>);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe('snapshot', () => {
|
|
20
|
+
it('reqular', () => {
|
|
21
|
+
const w = wrapper();
|
|
22
|
+
expect(w).toMatchSnapshot();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('isOver: true', () => {
|
|
26
|
+
expect(wrapper({ isOver: true })).toMatchSnapshot();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('disabled: true', () => {
|
|
30
|
+
expect(wrapper({ disabled: true })).toMatchSnapshot();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('className', () => {
|
|
34
|
+
expect(wrapper({ className: 'bar' })).toMatchSnapshot();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('specific grid rowsRepeatValue', () => {
|
|
38
|
+
const w = wrapper({
|
|
39
|
+
grid: {
|
|
40
|
+
rows: 2,
|
|
41
|
+
columns: 1,
|
|
42
|
+
rowsRepeatValue: 'min-content',
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
expect(w).toMatchSnapshot();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createContext, createElement } from 'react';
|
|
2
|
+
import { withUid } from '../uid-context';
|
|
3
|
+
|
|
4
|
+
jest.mock('react', () => ({
|
|
5
|
+
createElement: jest.fn((c) => c),
|
|
6
|
+
createContext: jest.fn().mockReturnValue({
|
|
7
|
+
Consumer: jest.fn((fn) => fn),
|
|
8
|
+
Provider: jest.fn(),
|
|
9
|
+
}),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
describe('id-context', () => {
|
|
13
|
+
describe('withUid', () => {
|
|
14
|
+
it('calls createElement', () => {
|
|
15
|
+
const Wrapped = withUid(() => ({}));
|
|
16
|
+
|
|
17
|
+
const Consumer = Wrapped({});
|
|
18
|
+
expect(createElement).toBeCalledWith(expect.any(Function), null, expect.anything());
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -4,12 +4,6 @@ import PropTypes from 'prop-types';
|
|
|
4
4
|
|
|
5
5
|
const preventInteractionStyle = {
|
|
6
6
|
flex: 1,
|
|
7
|
-
WebkitTouchCallout: 'none',
|
|
8
|
-
WebkitUserSelect: 'none',
|
|
9
|
-
KhtmlUserSelect: 'none',
|
|
10
|
-
MozUserSelect: 'none',
|
|
11
|
-
MsUserSelect: 'none',
|
|
12
|
-
UserSelect: 'none',
|
|
13
7
|
};
|
|
14
8
|
|
|
15
9
|
export class DroppablePlaceholder extends React.Component {
|
|
@@ -19,14 +13,23 @@ export class DroppablePlaceholder extends React.Component {
|
|
|
19
13
|
isOver: PropTypes.bool,
|
|
20
14
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
21
15
|
disabled: PropTypes.bool,
|
|
16
|
+
isVerticalPool: PropTypes.bool,
|
|
17
|
+
minHeight: PropTypes.number,
|
|
22
18
|
};
|
|
23
19
|
|
|
24
20
|
render() {
|
|
25
|
-
const { children, connectDropTarget, isOver, disabled, classes } = this.props;
|
|
21
|
+
const { children, connectDropTarget, isOver, disabled, classes, isVerticalPool, minHeight } = this.props;
|
|
26
22
|
|
|
27
23
|
return connectDropTarget(
|
|
28
24
|
<div style={preventInteractionStyle}>
|
|
29
|
-
<PlaceHolder
|
|
25
|
+
<PlaceHolder
|
|
26
|
+
disabled={disabled}
|
|
27
|
+
isOver={isOver}
|
|
28
|
+
choiceBoard={true}
|
|
29
|
+
className={classes}
|
|
30
|
+
isVerticalPool={isVerticalPool}
|
|
31
|
+
minHeight={minHeight}
|
|
32
|
+
>
|
|
30
33
|
{children}
|
|
31
34
|
</PlaceHolder>
|
|
32
35
|
</div>,
|
package/src/placeholder.jsx
CHANGED
|
@@ -3,9 +3,23 @@ import { withStyles } from '@material-ui/core/styles';
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import grey from '@material-ui/core/colors/grey';
|
|
6
|
+
import { color } from '@pie-lib/render-ui';
|
|
6
7
|
|
|
7
8
|
export const PlaceHolder = (props) => {
|
|
8
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
children,
|
|
11
|
+
classes,
|
|
12
|
+
className,
|
|
13
|
+
isOver,
|
|
14
|
+
type,
|
|
15
|
+
grid,
|
|
16
|
+
disabled,
|
|
17
|
+
choiceBoard,
|
|
18
|
+
isCategorize,
|
|
19
|
+
isVerticalPool,
|
|
20
|
+
minHeight,
|
|
21
|
+
} = props;
|
|
22
|
+
|
|
9
23
|
const names = classNames(
|
|
10
24
|
classes.placeholder,
|
|
11
25
|
disabled && classes.disabled,
|
|
@@ -19,14 +33,33 @@ export const PlaceHolder = (props) => {
|
|
|
19
33
|
if (grid && grid.columns) {
|
|
20
34
|
style.gridTemplateColumns = `repeat(${grid.columns}, 1fr)`;
|
|
21
35
|
}
|
|
36
|
+
|
|
22
37
|
if (grid && grid.rows) {
|
|
23
38
|
const repeatValue = grid.rowsRepeatValue || '1fr';
|
|
24
39
|
|
|
25
40
|
style.gridTemplateRows = `repeat(${grid.rows}, ${repeatValue})`;
|
|
26
41
|
}
|
|
27
42
|
|
|
43
|
+
// The "type" is only sent through placement-ordering / placeholder
|
|
44
|
+
// It can be "choice" or "target"
|
|
45
|
+
// We apply a different style for the "choice" type
|
|
46
|
+
// For any other type, use a dashed black border and a white fill
|
|
47
|
+
if (type === 'choice') {
|
|
48
|
+
style.border = `1px solid ${color.borderLight()}`;
|
|
49
|
+
style.background = color.backgroundDark();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const boardStyle = isCategorize ? classes.categorizeBoard : classes.board;
|
|
53
|
+
|
|
28
54
|
return (
|
|
29
|
-
<div
|
|
55
|
+
<div
|
|
56
|
+
style={{ ...style, minHeight: minHeight }}
|
|
57
|
+
className={classNames(
|
|
58
|
+
classes.noSelectStyles,
|
|
59
|
+
choiceBoard ? boardStyle : names,
|
|
60
|
+
isVerticalPool && classes.verticalPool,
|
|
61
|
+
)}
|
|
62
|
+
>
|
|
30
63
|
{children}
|
|
31
64
|
</div>
|
|
32
65
|
);
|
|
@@ -47,20 +80,31 @@ PlaceHolder.propTypes = {
|
|
|
47
80
|
index: PropTypes.number,
|
|
48
81
|
type: PropTypes.string,
|
|
49
82
|
disabled: PropTypes.bool,
|
|
83
|
+
isCategorize: PropTypes.bool,
|
|
84
|
+
isVerticalPool: PropTypes.bool,
|
|
85
|
+
minHeight: PropTypes.number,
|
|
50
86
|
};
|
|
51
87
|
|
|
52
88
|
const styles = (theme) => ({
|
|
89
|
+
noSelectStyles: {
|
|
90
|
+
WebkitTouchCallout: 'none',
|
|
91
|
+
WebkitUserSelect: 'none',
|
|
92
|
+
KhtmlUserSelect: 'none',
|
|
93
|
+
MozUserSelect: 'none',
|
|
94
|
+
MsUserSelect: 'none',
|
|
95
|
+
userSelect: 'none',
|
|
96
|
+
},
|
|
53
97
|
placeholder: {
|
|
54
98
|
width: '100%',
|
|
55
99
|
height: '100%',
|
|
56
|
-
background:
|
|
57
|
-
border: '1px solid #D1D1D1',
|
|
100
|
+
background: color.white(),
|
|
58
101
|
transition: 'background-color 200ms linear, border-color 200ms linear',
|
|
59
102
|
boxSizing: 'border-box',
|
|
60
103
|
display: 'grid',
|
|
61
104
|
gridRowGap: `${theme.spacing.unit}px`,
|
|
62
105
|
gridColumnGap: `${theme.spacing.unit}px`,
|
|
63
106
|
padding: theme.spacing.unit * 1,
|
|
107
|
+
border: `2px dashed ${color.black()}`,
|
|
64
108
|
},
|
|
65
109
|
disabled: {
|
|
66
110
|
boxShadow: 'none',
|
|
@@ -71,15 +115,30 @@ const styles = (theme) => ({
|
|
|
71
115
|
backgroundColor: `${grey[300]}`,
|
|
72
116
|
},
|
|
73
117
|
board: {
|
|
74
|
-
border: '1px solid #D1D1D1',
|
|
75
118
|
padding: theme.spacing.unit,
|
|
76
119
|
display: 'flex',
|
|
77
120
|
flexWrap: 'wrap',
|
|
78
121
|
alignItems: 'center',
|
|
79
|
-
minHeight: '
|
|
122
|
+
minHeight: '100px',
|
|
123
|
+
justifyContent: 'center',
|
|
124
|
+
overflow: 'hidden',
|
|
125
|
+
touchAction: 'none',
|
|
126
|
+
backgroundColor: color.backgroundDark(),
|
|
127
|
+
},
|
|
128
|
+
categorizeBoard: {
|
|
129
|
+
padding: theme.spacing.unit / 2,
|
|
130
|
+
display: 'flex',
|
|
131
|
+
flexWrap: 'wrap',
|
|
132
|
+
alignItems: 'center',
|
|
133
|
+
minHeight: '100px',
|
|
80
134
|
justifyContent: 'center',
|
|
81
135
|
overflow: 'hidden',
|
|
82
136
|
touchAction: 'none',
|
|
137
|
+
backgroundColor: color.backgroundDark(),
|
|
138
|
+
},
|
|
139
|
+
verticalPool: {
|
|
140
|
+
display: 'flex',
|
|
141
|
+
flexFlow: 'column wrap',
|
|
83
142
|
},
|
|
84
143
|
});
|
|
85
144
|
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react';
|
|
1
|
+
import React, { useEffect, useRef, useState, useCallback } from 'react';
|
|
2
2
|
import { usePreview } from 'react-dnd-multi-backend';
|
|
3
|
-
import { PreviewPrompt } from '@pie-lib/render-ui';
|
|
3
|
+
import { PreviewPrompt, color } from '@pie-lib/render-ui';
|
|
4
4
|
import { renderMath } from '@pie-lib/math-rendering';
|
|
5
|
-
import { color } from '@pie-lib/render-ui';
|
|
6
5
|
|
|
7
6
|
const styles = {
|
|
8
7
|
maskBlank: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
// this style is applied only on small screens and for touch devices when dragging, for drag-in-the-blank.
|
|
9
|
+
// It is styled to be identical to the drag-in-the-blank chip
|
|
10
|
+
backgroundColor: color.white(),
|
|
11
|
+
border: `1px solid ${color.text()}`,
|
|
12
|
+
color: color.text(),
|
|
13
|
+
alignItems: 'center',
|
|
14
|
+
display: 'inline-flex',
|
|
15
|
+
height: 'initial',
|
|
12
16
|
minHeight: '32px',
|
|
13
|
-
|
|
17
|
+
fontSize: 'inherit',
|
|
18
|
+
whiteSpace: 'pre-wrap',
|
|
14
19
|
maxWidth: '374px',
|
|
15
|
-
|
|
16
|
-
padding: '
|
|
17
|
-
alignItems: 'center',
|
|
18
|
-
justifyContent: 'center',
|
|
19
|
-
borderRadius: '16px',
|
|
20
|
+
borderRadius: '3px',
|
|
21
|
+
padding: '12px',
|
|
20
22
|
},
|
|
21
23
|
ica: {
|
|
22
24
|
backgroundColor: color.background(),
|
|
23
|
-
border: `1px solid ${color.
|
|
25
|
+
border: `1px solid ${color.borderDark()}`,
|
|
24
26
|
display: 'flex',
|
|
25
27
|
alignItems: 'center',
|
|
26
28
|
justifyContent: 'center',
|
|
@@ -71,36 +73,73 @@ const getPrompt = (itemType, item) => {
|
|
|
71
73
|
}
|
|
72
74
|
};
|
|
73
75
|
|
|
74
|
-
const getCustomStyle = (itemType, item, style) => {
|
|
75
|
-
const
|
|
76
|
-
|
|
76
|
+
const getCustomStyle = (itemType, item, touchPosition, style) => {
|
|
77
|
+
const transform = `translate(${touchPosition.x}px, ${touchPosition.y}px)`;
|
|
78
|
+
const top = style?.top || 0;
|
|
79
|
+
const left = style?.left || 0;
|
|
80
|
+
const position = style?.position || 'fixed';
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
position,
|
|
84
|
+
top,
|
|
85
|
+
left,
|
|
86
|
+
transform,
|
|
77
87
|
...(itemType === 'MaskBlank' ? styles.maskBlank : {}),
|
|
78
88
|
...(item?.itemType === 'categorize' ? styles.categorize : {}),
|
|
79
89
|
...(itemType === 'Answer' ? styles.matchList : {}),
|
|
80
90
|
...(itemType === 'Tile' ? styles.placementOrdering : {}),
|
|
81
91
|
...(itemType === 'react-dnd-response' ? styles.ica : {}),
|
|
82
92
|
};
|
|
83
|
-
|
|
84
|
-
return baseStyle;
|
|
85
93
|
};
|
|
86
94
|
|
|
87
95
|
const PreviewComponent = () => {
|
|
88
96
|
const preview = usePreview();
|
|
89
97
|
const { itemType, item, style, display } = preview;
|
|
98
|
+
const [touchPosition, setTouchPosition] = useState({ x: 0, y: 0 });
|
|
99
|
+
const [zoomLevel, setZoomLevel] = useState(1);
|
|
100
|
+
|
|
101
|
+
const handleTouchMove = useCallback(
|
|
102
|
+
(event) => {
|
|
103
|
+
if (event.touches.length > 0) {
|
|
104
|
+
const touch = event.touches[0];
|
|
105
|
+
const touchOffset = 1;
|
|
106
|
+
setTouchPosition({
|
|
107
|
+
x: (touch.clientX + touchOffset) / zoomLevel,
|
|
108
|
+
y: (touch.clientY + touchOffset) / zoomLevel,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
[zoomLevel],
|
|
113
|
+
);
|
|
90
114
|
|
|
91
115
|
const root = useRef(null);
|
|
92
116
|
|
|
93
117
|
useEffect(() => {
|
|
94
118
|
if (display && root.current) {
|
|
95
119
|
renderMath(root.current);
|
|
120
|
+
|
|
121
|
+
// Adjusted for precise zoom level calculation in Online Testing, targeting the specific class pattern .asmt-zoomable.asmt-zoom-NR .asmt-question .padding
|
|
122
|
+
const zoomAffectedElement = document.querySelector('.padding') || document.body;
|
|
123
|
+
|
|
124
|
+
setZoomLevel(parseFloat(getComputedStyle(zoomAffectedElement).zoom) || 1);
|
|
96
125
|
}
|
|
97
126
|
}, [display, item?.choice?.value, item?.value, itemType, item]);
|
|
98
127
|
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
const touchMoveListener = (event) => handleTouchMove(event);
|
|
130
|
+
if (display) {
|
|
131
|
+
window.addEventListener('touchmove', touchMoveListener);
|
|
132
|
+
}
|
|
133
|
+
return () => {
|
|
134
|
+
window.removeEventListener('touchmove', touchMoveListener);
|
|
135
|
+
};
|
|
136
|
+
}, [display, handleTouchMove]);
|
|
137
|
+
|
|
99
138
|
if (!display) {
|
|
100
139
|
return null;
|
|
101
140
|
}
|
|
102
141
|
|
|
103
|
-
const customStyle = getCustomStyle(itemType, item, style);
|
|
142
|
+
const customStyle = getCustomStyle(itemType, item, touchPosition, style);
|
|
104
143
|
|
|
105
144
|
const prompt = getPrompt(itemType, item);
|
|
106
145
|
|
package/src/with-drag-context.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import MultiBackend, { TouchTransition } from 'react-dnd-multi-backend';
|
|
2
|
+
import MultiBackend, { TouchTransition, MouseTransition } from 'react-dnd-multi-backend';
|
|
3
3
|
import { DndProvider } from 'react-dnd';
|
|
4
4
|
import { TouchBackend } from 'react-dnd-touch-backend';
|
|
5
5
|
import { HTML5Backend } from 'react-dnd-html5-backend';
|
|
@@ -7,7 +7,10 @@ import { HTML5Backend } from 'react-dnd-html5-backend';
|
|
|
7
7
|
import PreviewComponent from './preview-component';
|
|
8
8
|
|
|
9
9
|
const backends = [
|
|
10
|
-
{
|
|
10
|
+
{
|
|
11
|
+
backend: HTML5Backend,
|
|
12
|
+
transition: MouseTransition,
|
|
13
|
+
},
|
|
11
14
|
{
|
|
12
15
|
backend: TouchBackend,
|
|
13
16
|
options: { enableMouseEvents: true, enableTouchEvents: true },
|
|
@@ -17,9 +20,13 @@ const backends = [
|
|
|
17
20
|
},
|
|
18
21
|
];
|
|
19
22
|
|
|
20
|
-
export default (Component) => (props) =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
export default (Component) => (props) => {
|
|
24
|
+
const isClient = typeof window !== 'undefined';
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<DndProvider backend={MultiBackend} options={{ backends }} {...(isClient && { context: window })}>
|
|
28
|
+
<Component {...props} />
|
|
29
|
+
<PreviewComponent />
|
|
30
|
+
</DndProvider>
|
|
31
|
+
);
|
|
32
|
+
};
|
package/README.md
DELETED