@pie-lib/mask-markup 1.13.47-next.1 → 1.14.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 +15 -56
- package/NEXT.CHANGELOG.json +1 -0
- package/package.json +9 -5
- package/src/__tests__/__snapshots__/drag-in-the-blank.test.js.snap +316 -0
- package/src/__tests__/__snapshots__/mask.test.js.snap +55 -0
- package/src/__tests__/__snapshots__/with-mask.test.js.snap +62 -0
- package/src/__tests__/drag-in-the-blank.test.js +71 -0
- package/src/__tests__/index.test.js +39 -0
- package/src/__tests__/mask.test.js +152 -0
- package/src/__tests__/serialization.test.js +54 -0
- package/src/__tests__/utils.js +1 -0
- package/src/__tests__/with-mask.test.js +51 -0
- package/src/choices/__tests__/__snapshots__/index.test.js.snap +209 -0
- package/src/choices/__tests__/index.test.js +62 -0
- package/src/choices/choice.jsx +60 -6
- package/src/choices/index.jsx +2 -2
- package/src/components/__tests__/__snapshots__/blank.test.js.snap +111 -0
- package/src/components/__tests__/__snapshots__/correct-input.test.js.snap +64 -0
- package/src/components/__tests__/__snapshots__/dropdown.test.js.snap +133 -0
- package/src/components/__tests__/__snapshots__/input.test.js.snap +34 -0
- package/src/components/__tests__/blank.test.js +202 -0
- package/src/components/__tests__/correct-input.test.js +49 -0
- package/src/components/__tests__/dropdown.test.js +51 -0
- package/src/components/__tests__/input.test.js +50 -0
- package/src/components/blank.jsx +139 -28
- package/src/components/correct-input.jsx +6 -1
- package/src/components/dropdown.jsx +192 -71
- package/src/constructed-response.jsx +76 -18
- package/src/customizable.jsx +35 -0
- package/src/drag-in-the-blank.jsx +26 -3
- package/src/index.js +10 -1
- package/src/inline-dropdown.jsx +2 -0
- package/src/mask.jsx +30 -5
- package/src/with-mask.jsx +39 -2
- package/README.md +0 -14
- package/lib/choices/choice.js +0 -158
- package/lib/choices/choice.js.map +0 -1
- package/lib/choices/index.js +0 -127
- package/lib/choices/index.js.map +0 -1
- package/lib/componentize.js +0 -25
- package/lib/componentize.js.map +0 -1
- package/lib/components/blank.js +0 -303
- package/lib/components/blank.js.map +0 -1
- package/lib/components/correct-input.js +0 -113
- package/lib/components/correct-input.js.map +0 -1
- package/lib/components/dropdown.js +0 -216
- package/lib/components/dropdown.js.map +0 -1
- package/lib/components/input.js +0 -57
- package/lib/components/input.js.map +0 -1
- package/lib/constructed-response.js +0 -52
- package/lib/constructed-response.js.map +0 -1
- package/lib/drag-in-the-blank.js +0 -191
- package/lib/drag-in-the-blank.js.map +0 -1
- package/lib/index.js +0 -54
- package/lib/index.js.map +0 -1
- package/lib/inline-dropdown.js +0 -46
- package/lib/inline-dropdown.js.map +0 -1
- package/lib/mask.js +0 -215
- package/lib/mask.js.map +0 -1
- package/lib/serialization.js +0 -207
- package/lib/serialization.js.map +0 -1
- package/lib/with-mask.js +0 -93
- package/lib/with-mask.js.map +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import componentize from '../componentize';
|
|
3
|
+
import { deserialize } from '../serialization';
|
|
4
|
+
|
|
5
|
+
describe('index', () => {
|
|
6
|
+
describe('componentize', () => {
|
|
7
|
+
it('should return an array with the appropriate markup', () => {
|
|
8
|
+
const dropDownMarkup = componentize('{{0}} foo {{1}}', 'dropdown');
|
|
9
|
+
|
|
10
|
+
expect(dropDownMarkup).toEqual({
|
|
11
|
+
markup:
|
|
12
|
+
'<span data-component="dropdown" data-id="0"></span> foo <span data-component="dropdown" data-id="1"></span>',
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('serialization', () => {
|
|
18
|
+
it('should have default node a span', () => {
|
|
19
|
+
expect(deserialize('something')).toEqual(
|
|
20
|
+
expect.objectContaining({
|
|
21
|
+
object: 'value',
|
|
22
|
+
document: {
|
|
23
|
+
object: 'document',
|
|
24
|
+
data: {},
|
|
25
|
+
nodes: [
|
|
26
|
+
{
|
|
27
|
+
object: 'block',
|
|
28
|
+
data: {},
|
|
29
|
+
isVoid: false,
|
|
30
|
+
type: 'span',
|
|
31
|
+
nodes: [{ object: 'text', leaves: [{ text: 'something' }] }],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { shallow } from 'enzyme';
|
|
3
|
+
import Mask from '../mask';
|
|
4
|
+
|
|
5
|
+
describe('Mask', () => {
|
|
6
|
+
const renderChildren = jest.fn();
|
|
7
|
+
const onChange = jest.fn();
|
|
8
|
+
const defaultProps = {
|
|
9
|
+
renderChildren,
|
|
10
|
+
onChange,
|
|
11
|
+
layout: {
|
|
12
|
+
nodes: [
|
|
13
|
+
{
|
|
14
|
+
object: 'text',
|
|
15
|
+
leaves: [
|
|
16
|
+
{
|
|
17
|
+
text: 'Foo',
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
value: {},
|
|
24
|
+
};
|
|
25
|
+
let wrapper;
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
wrapper = shallow(<Mask {...defaultProps} />);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('render', () => {
|
|
32
|
+
it('renders correctly with default props', () => {
|
|
33
|
+
expect(wrapper).toMatchSnapshot();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('renders correctly a paragraph', () => {
|
|
37
|
+
wrapper.setProps({
|
|
38
|
+
layout: {
|
|
39
|
+
nodes: [
|
|
40
|
+
{
|
|
41
|
+
type: 'p',
|
|
42
|
+
nodes: [
|
|
43
|
+
{
|
|
44
|
+
object: 'text',
|
|
45
|
+
leaves: [
|
|
46
|
+
{
|
|
47
|
+
text: 'Foo',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(wrapper).toMatchSnapshot();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('renders correctly a div', () => {
|
|
61
|
+
wrapper.setProps({
|
|
62
|
+
layout: {
|
|
63
|
+
nodes: [
|
|
64
|
+
{
|
|
65
|
+
type: 'div',
|
|
66
|
+
data: {
|
|
67
|
+
attributes: {},
|
|
68
|
+
},
|
|
69
|
+
nodes: [
|
|
70
|
+
{
|
|
71
|
+
type: 'p',
|
|
72
|
+
data: {
|
|
73
|
+
attributes: {},
|
|
74
|
+
},
|
|
75
|
+
nodes: [
|
|
76
|
+
{
|
|
77
|
+
object: 'text',
|
|
78
|
+
leaves: [
|
|
79
|
+
{
|
|
80
|
+
text: 'Foo',
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(wrapper).toMatchSnapshot();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it.only('renders correctly a em', () => {
|
|
96
|
+
wrapper.setProps({
|
|
97
|
+
layout: {
|
|
98
|
+
nodes: [
|
|
99
|
+
{
|
|
100
|
+
leaves: [{ text: 'Foo ' }],
|
|
101
|
+
object: 'text',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
leaves: [
|
|
105
|
+
{
|
|
106
|
+
marks: [
|
|
107
|
+
{
|
|
108
|
+
data: undefined,
|
|
109
|
+
type: 'italic',
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
text: 'x',
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
object: 'text',
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
leaves: [{ text: ' bar' }],
|
|
119
|
+
object: 'text',
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
object: 'block',
|
|
123
|
+
type: 'div',
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(wrapper).toMatchSnapshot();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const da = () => ({ data: { attributes: {} } });
|
|
131
|
+
it('renders without space under tbody', () => {
|
|
132
|
+
wrapper.setProps({
|
|
133
|
+
layout: {
|
|
134
|
+
nodes: [
|
|
135
|
+
{
|
|
136
|
+
type: 'tbody',
|
|
137
|
+
...da(),
|
|
138
|
+
nodes: [
|
|
139
|
+
{
|
|
140
|
+
object: 'text',
|
|
141
|
+
leaves: [{ text: ' ' }],
|
|
142
|
+
},
|
|
143
|
+
{ type: 'tr', ...da(), nodes: [] },
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
expect(wrapper).toMatchSnapshot();
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { deserialize } from '../serialization';
|
|
2
|
+
|
|
3
|
+
describe('serialization', () => {
|
|
4
|
+
it('ignores comments', () => {
|
|
5
|
+
const out = deserialize(`<!-- hi -->`);
|
|
6
|
+
expect(out.document.nodes[0]).toEqual(expect.objectContaining({ type: 'span' }));
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('ignores comments', () => {
|
|
10
|
+
const out = deserialize(`<!-- hi --><div>foo</div>`);
|
|
11
|
+
expect(out.document.nodes[0]).toEqual(
|
|
12
|
+
expect.objectContaining({
|
|
13
|
+
type: 'div',
|
|
14
|
+
nodes: [
|
|
15
|
+
expect.objectContaining({
|
|
16
|
+
object: 'text',
|
|
17
|
+
leaves: [{ text: 'foo' }],
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('deserializes an em', () => {
|
|
25
|
+
const out = deserialize(`<!-- hi --><div> <em>x</em> </div>`);
|
|
26
|
+
expect(out.document.nodes[0]).toEqual(
|
|
27
|
+
expect.objectContaining({
|
|
28
|
+
type: 'div',
|
|
29
|
+
nodes: [
|
|
30
|
+
expect.objectContaining({
|
|
31
|
+
object: 'text',
|
|
32
|
+
}),
|
|
33
|
+
expect.objectContaining({
|
|
34
|
+
leaves: [
|
|
35
|
+
{
|
|
36
|
+
marks: [
|
|
37
|
+
{
|
|
38
|
+
data: undefined,
|
|
39
|
+
type: 'italic',
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
text: 'x',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
object: 'text',
|
|
46
|
+
}),
|
|
47
|
+
expect.objectContaining({
|
|
48
|
+
object: 'text',
|
|
49
|
+
}),
|
|
50
|
+
],
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const choice = (v, id) => ({ label: v, value: v, id });
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { shallow } from 'enzyme';
|
|
3
|
+
import { withMask } from '../with-mask';
|
|
4
|
+
|
|
5
|
+
describe('WithMask', () => {
|
|
6
|
+
const onChange = jest.fn();
|
|
7
|
+
const defaultProps = {
|
|
8
|
+
markup: '<p>Foo bar {{0}} over the moon;</p>',
|
|
9
|
+
value: {
|
|
10
|
+
0: 'blank',
|
|
11
|
+
},
|
|
12
|
+
onChange,
|
|
13
|
+
};
|
|
14
|
+
const Masked = withMask('foo', (props) => (node) => {
|
|
15
|
+
const dataset = node.data ? node.data.dataset || {} : {};
|
|
16
|
+
|
|
17
|
+
if (dataset.component === 'foo') {
|
|
18
|
+
return <input type="text" value="Foo" />;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
let wrapper;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
wrapper = shallow(<Masked {...defaultProps} />);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('render', () => {
|
|
29
|
+
it('renders correctly with default props', () => {
|
|
30
|
+
expect(wrapper).toMatchSnapshot();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('onChange', () => {
|
|
35
|
+
const event = (value) => ({
|
|
36
|
+
target: { value },
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should call the function', () => {
|
|
40
|
+
const e = event('ceva');
|
|
41
|
+
|
|
42
|
+
wrapper.simulate('change', e);
|
|
43
|
+
|
|
44
|
+
expect(onChange).toHaveBeenCalledWith({
|
|
45
|
+
target: {
|
|
46
|
+
value: 'ceva',
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`index Choice render renders correctly with default props 1`] = `
|
|
4
|
+
<BlankContentComp
|
|
5
|
+
classes={
|
|
6
|
+
Object {
|
|
7
|
+
"chip": "BlankContentComp-chip-2",
|
|
8
|
+
"chipLabel": "BlankContentComp-chipLabel-3",
|
|
9
|
+
"choice": "BlankContentComp-choice-1",
|
|
10
|
+
"disabled": "BlankContentComp-disabled-4",
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
disabled={false}
|
|
14
|
+
label="Label"
|
|
15
|
+
targetId="1"
|
|
16
|
+
value="1"
|
|
17
|
+
/>
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
exports[`index Choice render renders correctly with disabled prop as true 1`] = `
|
|
21
|
+
<BlankContentComp
|
|
22
|
+
classes={
|
|
23
|
+
Object {
|
|
24
|
+
"chip": "BlankContentComp-chip-2",
|
|
25
|
+
"chipLabel": "BlankContentComp-chipLabel-3",
|
|
26
|
+
"choice": "BlankContentComp-choice-1",
|
|
27
|
+
"disabled": "BlankContentComp-disabled-4",
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
disabled={true}
|
|
31
|
+
label="Label"
|
|
32
|
+
targetId="1"
|
|
33
|
+
value="1"
|
|
34
|
+
/>
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
exports[`index Choices renders correctly with default props 1`] = `
|
|
38
|
+
<div
|
|
39
|
+
style={
|
|
40
|
+
Object {
|
|
41
|
+
"margin": "0 40px 0 0",
|
|
42
|
+
"minWidth": "100px",
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
>
|
|
46
|
+
<DropTarget(DroppablePlaceholder)
|
|
47
|
+
disabled={false}
|
|
48
|
+
>
|
|
49
|
+
<DragSource(WithStyles(BlankContentComp))
|
|
50
|
+
choice={
|
|
51
|
+
Object {
|
|
52
|
+
"id": "0",
|
|
53
|
+
"label": "Jumped",
|
|
54
|
+
"value": "Jumped",
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
disabled={false}
|
|
58
|
+
key="Jumped-0"
|
|
59
|
+
/>
|
|
60
|
+
<DragSource(WithStyles(BlankContentComp))
|
|
61
|
+
choice={
|
|
62
|
+
Object {
|
|
63
|
+
"id": "1",
|
|
64
|
+
"label": "Laughed",
|
|
65
|
+
"value": "Laughed",
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
disabled={false}
|
|
69
|
+
key="Laughed-1"
|
|
70
|
+
/>
|
|
71
|
+
<DragSource(WithStyles(BlankContentComp))
|
|
72
|
+
choice={
|
|
73
|
+
Object {
|
|
74
|
+
"id": "2",
|
|
75
|
+
"label": "Spoon",
|
|
76
|
+
"value": "Spoon",
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
disabled={false}
|
|
80
|
+
key="Spoon-2"
|
|
81
|
+
/>
|
|
82
|
+
</DropTarget(DroppablePlaceholder)>
|
|
83
|
+
</div>
|
|
84
|
+
`;
|
|
85
|
+
|
|
86
|
+
exports[`index Choices renders correctly with disabled prop as true 1`] = `
|
|
87
|
+
<div
|
|
88
|
+
style={
|
|
89
|
+
Object {
|
|
90
|
+
"margin": "0 40px 0 0",
|
|
91
|
+
"minWidth": "100px",
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
>
|
|
95
|
+
<DropTarget(DroppablePlaceholder)
|
|
96
|
+
disabled={true}
|
|
97
|
+
>
|
|
98
|
+
<DragSource(WithStyles(BlankContentComp))
|
|
99
|
+
choice={
|
|
100
|
+
Object {
|
|
101
|
+
"id": "0",
|
|
102
|
+
"label": "Jumped",
|
|
103
|
+
"value": "Jumped",
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
disabled={true}
|
|
107
|
+
key="Jumped-0"
|
|
108
|
+
/>
|
|
109
|
+
<DragSource(WithStyles(BlankContentComp))
|
|
110
|
+
choice={
|
|
111
|
+
Object {
|
|
112
|
+
"id": "1",
|
|
113
|
+
"label": "Laughed",
|
|
114
|
+
"value": "Laughed",
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
disabled={true}
|
|
118
|
+
key="Laughed-1"
|
|
119
|
+
/>
|
|
120
|
+
<DragSource(WithStyles(BlankContentComp))
|
|
121
|
+
choice={
|
|
122
|
+
Object {
|
|
123
|
+
"id": "2",
|
|
124
|
+
"label": "Spoon",
|
|
125
|
+
"value": "Spoon",
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
disabled={true}
|
|
129
|
+
key="Spoon-2"
|
|
130
|
+
/>
|
|
131
|
+
</DropTarget(DroppablePlaceholder)>
|
|
132
|
+
</div>
|
|
133
|
+
`;
|
|
134
|
+
|
|
135
|
+
exports[`index Choices renders with duplicates 1`] = `
|
|
136
|
+
<div
|
|
137
|
+
style={
|
|
138
|
+
Object {
|
|
139
|
+
"margin": "0 40px 0 0",
|
|
140
|
+
"minWidth": "100px",
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
>
|
|
144
|
+
<DropTarget(DroppablePlaceholder)
|
|
145
|
+
disabled={false}
|
|
146
|
+
>
|
|
147
|
+
<DragSource(WithStyles(BlankContentComp))
|
|
148
|
+
choice={
|
|
149
|
+
Object {
|
|
150
|
+
"id": "0",
|
|
151
|
+
"label": "Jumped",
|
|
152
|
+
"value": "Jumped",
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
disabled={false}
|
|
156
|
+
key="Jumped-0"
|
|
157
|
+
/>
|
|
158
|
+
<DragSource(WithStyles(BlankContentComp))
|
|
159
|
+
choice={
|
|
160
|
+
Object {
|
|
161
|
+
"id": "1",
|
|
162
|
+
"label": "Laughed",
|
|
163
|
+
"value": "Laughed",
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
disabled={false}
|
|
167
|
+
key="Laughed-1"
|
|
168
|
+
/>
|
|
169
|
+
<DragSource(WithStyles(BlankContentComp))
|
|
170
|
+
choice={
|
|
171
|
+
Object {
|
|
172
|
+
"id": "2",
|
|
173
|
+
"label": "Spoon",
|
|
174
|
+
"value": "Spoon",
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
disabled={false}
|
|
178
|
+
key="Spoon-2"
|
|
179
|
+
/>
|
|
180
|
+
</DropTarget(DroppablePlaceholder)>
|
|
181
|
+
</div>
|
|
182
|
+
`;
|
|
183
|
+
|
|
184
|
+
exports[`index Choices renders without duplicates 1`] = `
|
|
185
|
+
<div
|
|
186
|
+
style={
|
|
187
|
+
Object {
|
|
188
|
+
"margin": "0 40px 0 0",
|
|
189
|
+
"minWidth": "100px",
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
>
|
|
193
|
+
<DropTarget(DroppablePlaceholder)
|
|
194
|
+
disabled={false}
|
|
195
|
+
>
|
|
196
|
+
<DragSource(WithStyles(BlankContentComp))
|
|
197
|
+
choice={
|
|
198
|
+
Object {
|
|
199
|
+
"id": "2",
|
|
200
|
+
"label": "Spoon",
|
|
201
|
+
"value": "Spoon",
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
disabled={false}
|
|
205
|
+
key="Spoon-0"
|
|
206
|
+
/>
|
|
207
|
+
</DropTarget(DroppablePlaceholder)>
|
|
208
|
+
</div>
|
|
209
|
+
`;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { shallow } from 'enzyme';
|
|
3
|
+
import { BlankContent as Choice } from '../choice';
|
|
4
|
+
import { choice } from '../../__tests__/utils';
|
|
5
|
+
import Choices from '../index';
|
|
6
|
+
|
|
7
|
+
describe('index', () => {
|
|
8
|
+
describe('Choices', () => {
|
|
9
|
+
const defaultProps = {
|
|
10
|
+
disabled: false,
|
|
11
|
+
choices: [choice('Jumped', '0'), choice('Laughed', '1'), choice('Spoon', '2')],
|
|
12
|
+
};
|
|
13
|
+
let wrapper;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
wrapper = shallow(<Choices {...defaultProps} />);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('renders correctly with default props', () => {
|
|
20
|
+
expect(wrapper).toMatchSnapshot();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('renders correctly with disabled prop as true', () => {
|
|
24
|
+
wrapper.setProps({ disabled: true });
|
|
25
|
+
expect(wrapper).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
it('renders without duplicates', () => {
|
|
28
|
+
wrapper.setProps({ duplicates: undefined, value: { 0: '0', 1: '1' } });
|
|
29
|
+
expect(wrapper).toMatchSnapshot();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('renders with duplicates', () => {
|
|
33
|
+
wrapper.setProps({ duplicates: true, value: { 0: '0', 1: '1' } });
|
|
34
|
+
expect(wrapper).toMatchSnapshot();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('Choice', () => {
|
|
39
|
+
const defaultProps = {
|
|
40
|
+
disabled: false,
|
|
41
|
+
value: '1',
|
|
42
|
+
label: 'Label',
|
|
43
|
+
targetId: '1',
|
|
44
|
+
};
|
|
45
|
+
let wrapper;
|
|
46
|
+
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
wrapper = shallow(<Choice {...defaultProps} />);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('render', () => {
|
|
52
|
+
it('renders correctly with default props', () => {
|
|
53
|
+
expect(wrapper).toMatchSnapshot();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('renders correctly with disabled prop as true', () => {
|
|
57
|
+
wrapper.setProps({ disabled: true });
|
|
58
|
+
expect(wrapper).toMatchSnapshot();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
package/src/choices/choice.jsx
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { DragSource } from '@pie-lib/drag';
|
|
4
4
|
import { withStyles } from '@material-ui/core/styles';
|
|
5
5
|
import Chip from '@material-ui/core/Chip';
|
|
6
6
|
import classnames from 'classnames';
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
import { renderMath } from '@pie-lib/math-rendering';
|
|
9
9
|
import { color } from '@pie-lib/render-ui';
|
|
10
|
+
import { DragSource } from '@pie-lib/drag';
|
|
10
11
|
|
|
11
12
|
export const DRAG_TYPE = 'MaskBlank';
|
|
12
13
|
|
|
@@ -18,6 +19,45 @@ class BlankContentComp extends React.Component {
|
|
|
18
19
|
connectDragSource: PropTypes.func,
|
|
19
20
|
};
|
|
20
21
|
|
|
22
|
+
startDrag = () => {
|
|
23
|
+
const { connectDragSource, disabled } = this.props;
|
|
24
|
+
if (!disabled) {
|
|
25
|
+
connectDragSource(this.dragContainerRef);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// start drag after 500ms (touch and hold duration) for chromebooks and other touch devices PD-4888
|
|
30
|
+
handleTouchStart = (e) => {
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
this.longPressTimer = setTimeout(() => {
|
|
33
|
+
this.startDrag(e);
|
|
34
|
+
}, 500);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
handleTouchEnd = () => {
|
|
38
|
+
clearTimeout(this.longPressTimer);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
handleTouchMove = () => {
|
|
42
|
+
clearTimeout(this.longPressTimer);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
componentDidMount() {
|
|
46
|
+
if (this.dragContainerRef) {
|
|
47
|
+
this.dragContainerRef.addEventListener('touchstart', this.handleTouchStart, { passive: false });
|
|
48
|
+
this.dragContainerRef.addEventListener('touchend', this.handleTouchEnd);
|
|
49
|
+
this.dragContainerRef.addEventListener('touchmove', this.handleTouchMove);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
componentWillUnmount() {
|
|
54
|
+
if (this.dragContainerRef) {
|
|
55
|
+
this.dragContainerRef.removeEventListener('touchstart', this.handleTouchStart);
|
|
56
|
+
this.dragContainerRef.removeEventListener('touchend', this.handleTouchEnd);
|
|
57
|
+
this.dragContainerRef.removeEventListener('touchmove', this.handleTouchMove);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
21
61
|
componentDidUpdate() {
|
|
22
62
|
renderMath(this.rootRef);
|
|
23
63
|
}
|
|
@@ -28,7 +68,13 @@ class BlankContentComp extends React.Component {
|
|
|
28
68
|
// TODO the Chip element is causing drag problems on touch devices. Avoid using Chip and consider refactoring the code. Keep in mind that Chip is a span with a button role, which interferes with seamless touch device dragging.
|
|
29
69
|
|
|
30
70
|
return connectDragSource(
|
|
31
|
-
<span
|
|
71
|
+
<span
|
|
72
|
+
className={classnames(classes.choice, disabled && classes.disabled)}
|
|
73
|
+
ref={(ref) => {
|
|
74
|
+
//eslint-disable-next-line
|
|
75
|
+
this.dragContainerRef = ReactDOM.findDOMNode(ref);
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
32
78
|
<Chip
|
|
33
79
|
clickable={false}
|
|
34
80
|
disabled={true}
|
|
@@ -65,7 +111,7 @@ export const BlankContent = withStyles((theme) => ({
|
|
|
65
111
|
transform: 'translate(0, 0)',
|
|
66
112
|
},
|
|
67
113
|
chip: {
|
|
68
|
-
backgroundColor: color.
|
|
114
|
+
backgroundColor: color.white(),
|
|
69
115
|
border: `1px solid ${color.text()}`,
|
|
70
116
|
color: color.text(),
|
|
71
117
|
alignItems: 'center',
|
|
@@ -79,15 +125,23 @@ export const BlankContent = withStyles((theme) => ({
|
|
|
79
125
|
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
80
126
|
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
81
127
|
pointerEvents: 'none',
|
|
128
|
+
borderRadius: '3px',
|
|
129
|
+
paddingTop: '12px',
|
|
130
|
+
paddingBottom: '12px',
|
|
82
131
|
},
|
|
83
132
|
chipLabel: {
|
|
84
|
-
whiteSpace: '
|
|
133
|
+
whiteSpace: 'normal',
|
|
85
134
|
'& img': {
|
|
86
135
|
display: 'block',
|
|
87
136
|
padding: '2px 0',
|
|
88
137
|
},
|
|
138
|
+
'& mjx-frac': {
|
|
139
|
+
fontSize: '120% !important',
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
disabled: {
|
|
143
|
+
opacity: 0.6,
|
|
89
144
|
},
|
|
90
|
-
disabled: {},
|
|
91
145
|
}))(BlankContentComp);
|
|
92
146
|
|
|
93
147
|
const tileSource = {
|
package/src/choices/index.jsx
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import findKey from 'lodash/findKey';
|
|
4
4
|
import Choice from './choice';
|
|
5
|
-
import DragDroppablePlaceholder from '@pie-lib/drag
|
|
5
|
+
import { DragDroppablePlaceholder } from '@pie-lib/drag';
|
|
6
6
|
|
|
7
7
|
export default class Choices extends React.Component {
|
|
8
8
|
static propTypes = {
|
|
@@ -48,7 +48,7 @@ export default class Choices extends React.Component {
|
|
|
48
48
|
const foundChoice = findKey(value, (v) => v === c.id);
|
|
49
49
|
return foundChoice === undefined;
|
|
50
50
|
});
|
|
51
|
-
const elementStyle = this.getStyleForWrapper();
|
|
51
|
+
const elementStyle = { ...this.getStyleForWrapper(), minWidth: '100px' };
|
|
52
52
|
|
|
53
53
|
return (
|
|
54
54
|
<div style={elementStyle}>
|