@pie-lib/editable-html-tip-tap 1.0.2 → 1.0.3

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.
Files changed (129) hide show
  1. package/lib/components/CharacterPicker.js +221 -0
  2. package/lib/components/EditableHtml.js +323 -0
  3. package/lib/components/MenuBar.js +693 -0
  4. package/lib/components/TiptapContainer.js +90 -0
  5. package/lib/components/buttons/done-button.js +53 -0
  6. package/lib/components/characters/characterUtils.js +112 -0
  7. package/lib/components/characters/custom-popper.js +73 -0
  8. package/lib/components/common/done-button.js +53 -0
  9. package/lib/components/icons/CssIcon.js +37 -0
  10. package/lib/components/icons/RespArea.js +95 -0
  11. package/lib/components/icons/TableIcons.js +69 -0
  12. package/lib/components/icons/TextAlign.js +194 -0
  13. package/lib/components/icons/index.js +194 -0
  14. package/lib/components/image/ImageToolbar.js +16 -0
  15. package/lib/components/image/InsertImageHandler.js +16 -0
  16. package/lib/components/media/MediaDialog.js +16 -0
  17. package/lib/components/media/MediaToolbar.js +16 -0
  18. package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +94 -0
  19. package/lib/components/respArea/DragInTheBlank/choice.js +289 -0
  20. package/lib/components/respArea/DragInTheBlank.js +94 -0
  21. package/lib/components/respArea/ExplicitConstructedResponse.js +120 -0
  22. package/lib/components/respArea/InlineDropdown.js +126 -0
  23. package/lib/components/respArea/ToolbarIcon.js +105 -0
  24. package/lib/components/respArea/choice.js +2 -0
  25. package/lib/extensions/component.js +5 -5
  26. package/lib/extensions/custom-toolbar-wrapper.js +2 -4
  27. package/lib/extensions/extended-table.js +30 -0
  28. package/lib/extensions/index.js +52 -0
  29. package/lib/extensions/media.js +5 -5
  30. package/lib/extensions/responseArea.js +7 -7
  31. package/lib/index.js +16 -1481
  32. package/lib/plugins/index.js +8 -80
  33. package/lib/styles/editorContainerStyles.js +200 -0
  34. package/lib/utils/size.js +34 -0
  35. package/package.json +1 -1
  36. package/src/components/CharacterPicker.jsx +185 -0
  37. package/src/components/EditableHtml.jsx +306 -0
  38. package/src/components/MenuBar.jsx +630 -0
  39. package/src/components/TiptapContainer.jsx +96 -0
  40. package/src/components/characters/characterUtils.js +127 -0
  41. package/src/components/image/ImageToolbar.jsx +1 -0
  42. package/src/components/image/InsertImageHandler.js +1 -0
  43. package/src/components/media/MediaDialog.js +1 -0
  44. package/src/components/media/MediaToolbar.jsx +1 -0
  45. package/src/{plugins/respArea/drag-in-the-blank → components/respArea/DragInTheBlank}/choice.jsx +1 -1
  46. package/src/{plugins/respArea/inline-dropdown/index.jsx → components/respArea/InlineDropdown.jsx} +1 -1
  47. package/src/components/respArea/ToolbarIcon.jsx +68 -0
  48. package/src/extensions/component.jsx +2 -2
  49. package/src/extensions/custom-toolbar-wrapper.jsx +6 -7
  50. package/src/extensions/extended-table.js +27 -0
  51. package/src/extensions/index.js +76 -0
  52. package/src/extensions/media.js +10 -4
  53. package/src/extensions/responseArea.js +7 -7
  54. package/src/index.jsx +3 -1440
  55. package/src/styles/editorContainerStyles.js +203 -0
  56. package/src/utils/size.js +32 -0
  57. package/src/__tests__/editor.test.jsx +0 -363
  58. package/src/__tests__/serialization.test.js +0 -291
  59. package/src/block-tags.js +0 -17
  60. package/src/editor.jsx +0 -1197
  61. package/src/extensions/characters.js +0 -46
  62. package/src/old-index.jsx +0 -162
  63. package/src/parse-html.js +0 -8
  64. package/src/plugins/README.md +0 -27
  65. package/src/plugins/characters/index.jsx +0 -284
  66. package/src/plugins/characters/utils.js +0 -447
  67. package/src/plugins/css/index.jsx +0 -340
  68. package/src/plugins/customPlugin/index.jsx +0 -85
  69. package/src/plugins/html/icons/index.jsx +0 -19
  70. package/src/plugins/html/index.jsx +0 -72
  71. package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +0 -51
  72. package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +0 -27
  73. package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +0 -44
  74. package/src/plugins/image/__tests__/component.test.jsx +0 -41
  75. package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +0 -42
  76. package/src/plugins/image/__tests__/image-toolbar.test.jsx +0 -11
  77. package/src/plugins/image/__tests__/index.test.js +0 -95
  78. package/src/plugins/image/__tests__/insert-image-handler.test.js +0 -113
  79. package/src/plugins/image/__tests__/mock-change.js +0 -15
  80. package/src/plugins/image/alt-dialog.jsx +0 -82
  81. package/src/plugins/image/component.jsx +0 -343
  82. package/src/plugins/image/image-toolbar.jsx +0 -100
  83. package/src/plugins/image/index.jsx +0 -227
  84. package/src/plugins/image/insert-image-handler.js +0 -79
  85. package/src/plugins/index.jsx +0 -377
  86. package/src/plugins/list/__tests__/index.test.js +0 -54
  87. package/src/plugins/list/index.jsx +0 -305
  88. package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +0 -48
  89. package/src/plugins/math/__tests__/index.test.jsx +0 -245
  90. package/src/plugins/math/index.jsx +0 -379
  91. package/src/plugins/media/__tests__/index.test.js +0 -75
  92. package/src/plugins/media/index.jsx +0 -325
  93. package/src/plugins/media/media-dialog.js +0 -624
  94. package/src/plugins/media/media-toolbar.jsx +0 -56
  95. package/src/plugins/media/media-wrapper.jsx +0 -43
  96. package/src/plugins/rendering/index.js +0 -31
  97. package/src/plugins/respArea/index.jsx +0 -299
  98. package/src/plugins/respArea/math-templated/index.jsx +0 -104
  99. package/src/plugins/respArea/utils.jsx +0 -90
  100. package/src/plugins/table/CustomTablePlugin.js +0 -113
  101. package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +0 -44
  102. package/src/plugins/table/__tests__/index.test.jsx +0 -401
  103. package/src/plugins/table/__tests__/table-toolbar.test.jsx +0 -42
  104. package/src/plugins/table/index.jsx +0 -427
  105. package/src/plugins/table/table-toolbar.jsx +0 -136
  106. package/src/plugins/textAlign/index.jsx +0 -23
  107. package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +0 -923
  108. package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +0 -20
  109. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +0 -36
  110. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +0 -46
  111. package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +0 -94
  112. package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +0 -37
  113. package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +0 -51
  114. package/src/plugins/toolbar/__tests__/toolbar.test.jsx +0 -106
  115. package/src/plugins/toolbar/default-toolbar.jsx +0 -206
  116. package/src/plugins/toolbar/editor-and-toolbar.jsx +0 -257
  117. package/src/plugins/toolbar/index.jsx +0 -23
  118. package/src/plugins/toolbar/toolbar-buttons.jsx +0 -138
  119. package/src/plugins/toolbar/toolbar.jsx +0 -338
  120. package/src/plugins/utils.js +0 -31
  121. package/src/serialization.jsx +0 -621
  122. /package/src/{plugins → components}/characters/custom-popper.js +0 -0
  123. /package/src/{plugins/toolbar → components/common}/done-button.jsx +0 -0
  124. /package/src/{plugins/css/icons/index.jsx → components/icons/CssIcon.jsx} +0 -0
  125. /package/src/{plugins/respArea/icons/index.jsx → components/icons/RespArea.jsx} +0 -0
  126. /package/src/{plugins/table/icons/index.jsx → components/icons/TableIcons.jsx} +0 -0
  127. /package/src/{plugins/textAlign/icons/index.jsx → components/icons/TextAlign.jsx} +0 -0
  128. /package/src/{plugins/respArea/drag-in-the-blank/index.jsx → components/respArea/DragInTheBlank/DragInTheBlank.jsx} +0 -0
  129. /package/src/{plugins/respArea/explicit-constructed-response/index.jsx → components/respArea/ExplicitConstructedResponse.jsx} +0 -0
@@ -0,0 +1,203 @@
1
+ import { color } from '@pie-lib/render-ui';
2
+ import { primary } from '../theme';
3
+
4
+ const styles = (theme) => ({
5
+ root: {
6
+ position: 'relative',
7
+ padding: '0px',
8
+ border: '1px solid #ccc',
9
+ borderRadius: '4px',
10
+ cursor: 'text',
11
+ '& [data-slate-editor="true"]': {
12
+ wordBreak: 'break-word',
13
+ overflow: 'visible',
14
+ maxHeight: '500px',
15
+ // needed in order to be able to put the focus before a void element when it is the first one in the editor
16
+ padding: '5px',
17
+ },
18
+
19
+ '&:first-child': {
20
+ marginTop: 0,
21
+ },
22
+
23
+ '& ul, & ol': {
24
+ padding: '0 1rem',
25
+ margin: '1.25rem 1rem 1.25rem 0.4rem',
26
+ },
27
+
28
+ '& ul li p, & ol li p': {
29
+ marginTop: '0.25em',
30
+ marginBottom: '0.25em',
31
+ },
32
+
33
+ '& h1, & h2, & h3, & h4, & h5, & h6': {
34
+ lineHeight: 1.1,
35
+ marginTop: '2.5rem',
36
+ textWrap: 'pretty',
37
+ },
38
+
39
+ '& h1, & h2': {
40
+ marginTop: '3.5rem',
41
+ marginBottom: '1.5rem',
42
+ },
43
+
44
+ '& h1': {
45
+ fontSize: '1.4rem',
46
+ },
47
+
48
+ '& h2': {
49
+ fontSize: '1.2rem',
50
+ },
51
+
52
+ '& h3': {
53
+ fontSize: '1.1rem',
54
+ },
55
+
56
+ '& h4, & h5, & h6': {
57
+ fontSize: '1rem',
58
+ },
59
+
60
+ '& code': {
61
+ backgroundColor: 'var(--purple-light)',
62
+ borderRadius: '0.4rem',
63
+ color: 'var(--black)',
64
+ fontSize: '0.85rem',
65
+ padding: '0.25em 0.3em',
66
+ },
67
+
68
+ '& pre': {
69
+ background: 'var(--black)',
70
+ borderRadius: '0.5rem',
71
+ color: 'var(--white)',
72
+ fontFamily: "'JetBrainsMono', monospace",
73
+ margin: '1.5rem 0',
74
+ padding: '0.75rem 1rem',
75
+
76
+ '& code': {
77
+ background: 'none',
78
+ color: 'inherit',
79
+ fontSize: '0.8rem',
80
+ padding: 0,
81
+ },
82
+ },
83
+
84
+ '& blockquote': {
85
+ borderLeft: '3px solid var(--gray-3)',
86
+ margin: '1.5rem 0',
87
+ paddingLeft: '1rem',
88
+ },
89
+
90
+ '& hr': {
91
+ border: 'none',
92
+ borderTop: '1px solid var(--gray-2)',
93
+ margin: '2rem 0',
94
+ },
95
+
96
+ '& table': {
97
+ tableLayout: 'fixed',
98
+ width: '100%',
99
+ borderCollapse: 'collapse',
100
+ color: color.text(),
101
+ backgroundColor: color.background(),
102
+ },
103
+ '& table:not([border="1"]) tr': {
104
+ borderTop: '1px solid #dfe2e5',
105
+ },
106
+ '& td, th': {
107
+ padding: '.6em 1em',
108
+ textAlign: 'center',
109
+ },
110
+ '& table:not([border="1"]) td, th': {
111
+ border: '1px solid #dfe2e5',
112
+ },
113
+ },
114
+ children: {
115
+ padding: '10px 16px',
116
+ },
117
+ editorHolder: {
118
+ position: 'relative',
119
+ padding: '0px',
120
+ // overflowY: 'auto',
121
+ overflow: 'visible',
122
+ color: color.text(),
123
+ backgroundColor: color.background(),
124
+ '&::before': {
125
+ left: '0',
126
+ right: '0',
127
+ bottom: '0',
128
+ height: '1px',
129
+ content: '""',
130
+ position: 'absolute',
131
+ transition: 'background-color 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
132
+ pointerEvents: 'none',
133
+ backgroundColor: 'rgba(0, 0, 0, 0.42)',
134
+ },
135
+ '&::after': {
136
+ left: '0',
137
+ right: '0',
138
+ bottom: '0',
139
+ height: '1px',
140
+ content: '""',
141
+ position: 'absolute',
142
+ transform: 'scaleX(0)',
143
+ transition: 'transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms, background-color 200ms linear',
144
+ backgroundColor: 'rgba(0, 0, 0, 0.42)',
145
+ },
146
+ },
147
+ disabledUnderline: {
148
+ '&::before': {
149
+ display: 'none',
150
+ },
151
+ '&::after': {
152
+ display: 'none',
153
+ },
154
+ },
155
+ disabledScrollbar: {
156
+ '&::-webkit-scrollbar': {
157
+ display: 'none',
158
+ },
159
+ scrollbarWidth: 'none',
160
+ '-ms-overflow-style': 'none',
161
+ },
162
+ readOnly: {
163
+ '&::before': {
164
+ background: 'transparent',
165
+ backgroundSize: '5px 1px',
166
+ backgroundImage: 'linear-gradient(to right, rgba(0, 0, 0, 0.42) 33%, transparent 0%)',
167
+ backgroundRepeat: 'repeat-x',
168
+ backgroundPosition: 'left top',
169
+ },
170
+ '&::after': {
171
+ left: '0',
172
+ right: '0',
173
+ bottom: '0',
174
+ height: '1px',
175
+ content: '""',
176
+ position: 'absolute',
177
+ transform: 'scaleX(0)',
178
+ transition: 'transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms, background-color 0ms linear',
179
+ backgroundColor: 'rgba(0, 0, 0, 0)',
180
+ },
181
+ '&:hover': {
182
+ '&::after': {
183
+ transform: 'scaleX(0)',
184
+ backgroundColor: theme.palette.common.black,
185
+ height: '2px',
186
+ },
187
+ },
188
+ },
189
+ error: {
190
+ border: `2px solid ${theme.palette.error.main} !important`,
191
+ },
192
+ noBorder: {
193
+ border: 'none',
194
+ },
195
+ noPadding: {
196
+ padding: 0,
197
+ },
198
+ toolbarOnTop: {
199
+ marginTop: '45px',
200
+ },
201
+ });
202
+
203
+ export default styles;
@@ -0,0 +1,32 @@
1
+ export const valueToSize = (v) => {
2
+ if (!v) {
3
+ return;
4
+ }
5
+
6
+ const calcRegex = /^calc\((.*)\)$/;
7
+
8
+ if (typeof v === 'string') {
9
+ if (v.endsWith('%')) {
10
+ return undefined;
11
+ }
12
+
13
+ if (
14
+ v.endsWith('px') ||
15
+ v.endsWith('vh') ||
16
+ v.endsWith('vw') ||
17
+ v.endsWith('ch') ||
18
+ v.endsWith('em') ||
19
+ v.match(calcRegex)
20
+ ) {
21
+ return v;
22
+ }
23
+
24
+ const value = parseInt(v, 10);
25
+
26
+ return Number.isNaN(value) ? value : `${value}px`;
27
+ }
28
+
29
+ if (typeof v === 'number') {
30
+ return `${v}px`;
31
+ }
32
+ };
@@ -1,363 +0,0 @@
1
- import React from 'react';
2
- import { htmlToValue, valueToHtml } from '../index';
3
- import { Editor } from '../editor';
4
- import { shallow, configure } from 'enzyme';
5
- import debug from 'debug';
6
-
7
- import { mockComponents } from './utils';
8
-
9
- const log = debug('@pie-lib:editable-html:test');
10
-
11
- const value = htmlToValue('hi');
12
-
13
- const resizeWindow = (width, height) => {
14
- window.innerWidth = width;
15
- window.innerHeight = height;
16
- window.dispatchEvent(new Event('resize'));
17
- };
18
- jest.mock('@pie-lib/math-toolbar', () => ({}));
19
- jest.mock('@pie-lib/math-input', () => {
20
- HorizontalKeypad: () => <div>HorizontalKeypad</div>;
21
- });
22
-
23
- expect.extend({
24
- toEqualHtml(value, html) {
25
- const v = valueToHtml(value);
26
- const pass = v === html;
27
-
28
- return {
29
- pass,
30
- message: () => `expected ${html} to match ${v}`,
31
- };
32
- },
33
- });
34
-
35
- describe('logic', () => {
36
- test('onFocus/onBlur saves the value', async () => {
37
- const wrapper = shallow(
38
- <Editor editorRef={jest.fn()} value={value} classes={{}} onChange={jest.fn()} onRef={jest.fn()} />,
39
- );
40
-
41
- await wrapper.instance().onFocus();
42
-
43
- const v = htmlToValue('hi');
44
-
45
- expect(wrapper.state('stashedValue')).toEqualHtml('<div>hi</div>');
46
-
47
- wrapper.instance().onChange({ value: htmlToValue('new value') });
48
-
49
- expect(wrapper.state('value')).toEqualHtml('<div>new value</div>');
50
-
51
- return wrapper
52
- .instance()
53
- .onBlur({})
54
- .then(() => {
55
- expect(wrapper.state('value')).toEqualHtml('<div>new value</div>');
56
- });
57
- });
58
- });
59
-
60
- test('onFocus does not change focus if related target is a button from language keypad', async () => {
61
- const wrapper = shallow(
62
- <Editor editorRef={jest.fn()} value={value} classes={{}} onChange={jest.fn()} onRef={jest.fn()} />,
63
- );
64
-
65
- const event = {
66
- relatedTarget: {
67
- tagName: 'button',
68
- },
69
- };
70
-
71
- const change = {
72
- focus: jest.fn(),
73
- };
74
-
75
- wrapper.instance().keypadInteractionDetected = true;
76
-
77
- await wrapper.instance().onFocus(event, change);
78
-
79
- expect(change.focus).not.toHaveBeenCalled();
80
- });
81
-
82
- test('onFocus changes focus if related target is not a button from language keypad', async () => {
83
- const wrapper = shallow(
84
- <Editor editorRef={jest.fn()} value={value} classes={{}} onChange={jest.fn()} onRef={jest.fn()} />,
85
- );
86
-
87
- const event = {
88
- relatedTarget: {
89
- tagName: 'div',
90
- },
91
- };
92
-
93
- const change = {
94
- focus: jest.fn(),
95
- };
96
-
97
- await wrapper.instance().onFocus(event, change);
98
-
99
- expect(change.focus).toHaveBeenCalled();
100
- });
101
-
102
- test('onFocus stashes the value', async () => {
103
- const wrapper = shallow(
104
- <Editor editorRef={jest.fn()} value={value} classes={{}} onChange={jest.fn()} onRef={jest.fn()} />,
105
- );
106
-
107
- await wrapper.instance().onFocus();
108
-
109
- expect(wrapper.state('stashedValue')).toEqualHtml('<div>hi</div>');
110
- });
111
-
112
- test('onBlur does not set focusToolbar if related target is RawDoneButton', async () => {
113
- const wrapper = shallow(
114
- <Editor editorRef={jest.fn()} value={value} classes={{}} onChange={jest.fn()} onRef={jest.fn()} />,
115
- );
116
-
117
- const toolbarElement = document.createElement('div');
118
- const relatedTarget = document.createElement('button');
119
- relatedTarget.className = 'RawDoneButton';
120
- toolbarElement.className = 'toolbar';
121
- toolbarElement.appendChild(relatedTarget);
122
-
123
- wrapper.instance().toolbarRef = toolbarElement;
124
- wrapper.instance().doneButtonRef.current = relatedTarget;
125
-
126
- const event = { relatedTarget };
127
-
128
- await wrapper.instance().onBlur(event);
129
-
130
- expect(wrapper.state('focusToolbar')).toBe(false);
131
- });
132
-
133
- test('handleToolbarFocus sets focusToolbar to true', () => {
134
- const wrapper = shallow(
135
- <Editor editorRef={jest.fn()} value={value} classes={{}} onChange={jest.fn()} onRef={jest.fn()} />,
136
- );
137
-
138
- wrapper.instance().handleToolbarFocus();
139
- expect(wrapper.state('focusToolbar')).toBe(true);
140
- });
141
-
142
- test('handleToolbarBlur sets focusToolbar to false if toolbar does not contain focus', (done) => {
143
- const wrapper = shallow(
144
- <Editor editorRef={jest.fn()} value={value} classes={{}} onChange={jest.fn()} onRef={jest.fn()} />,
145
- );
146
-
147
- wrapper.instance().toolbarContainsFocus = jest.fn().mockReturnValue(false);
148
-
149
- wrapper.instance().handleToolbarBlur();
150
-
151
- setTimeout(() => {
152
- expect(wrapper.state('focusToolbar')).toBe(false);
153
- done();
154
- }, 20);
155
- });
156
-
157
- test('handleToolbarBlur does not set focusToolbar to false if toolbar contains focus', (done) => {
158
- const wrapper = shallow(
159
- <Editor editorRef={jest.fn()} value={value} classes={{}} onChange={jest.fn()} onRef={jest.fn()} />,
160
- );
161
-
162
- wrapper.instance().toolbarContainsFocus = jest.fn().mockReturnValue(true);
163
-
164
- wrapper.setState({ focusToolbar: true });
165
-
166
- wrapper.instance().handleToolbarBlur();
167
-
168
- setTimeout(() => {
169
- expect(wrapper.state('focusToolbar')).toBe(true);
170
- done();
171
- }, 20);
172
- });
173
-
174
- test('toolbarContainsFocus correctly detects focus within toolbar', () => {
175
- const wrapper = shallow(
176
- <Editor editorRef={jest.fn()} value={value} classes={{}} onChange={jest.fn()} onRef={jest.fn()} />,
177
- );
178
-
179
- const toolbarElement = document.createElement('div');
180
- const activeElement = document.createElement('button');
181
- toolbarElement.appendChild(activeElement);
182
-
183
- Object.defineProperty(document, 'activeElement', {
184
- value: activeElement,
185
- configurable: true,
186
- });
187
-
188
- wrapper.instance().toolbarRef = toolbarElement;
189
-
190
- expect(wrapper.instance().toolbarContainsFocus()).toBe(true);
191
-
192
- Object.defineProperty(document, 'activeElement', {
193
- value: document.createElement('div'),
194
- configurable: true,
195
- });
196
-
197
- expect(wrapper.instance().toolbarContainsFocus()).toBe(false);
198
- });
199
-
200
- test('onBlur sets focusToolbar to true if related target is within toolbar', async () => {
201
- const wrapper = shallow(
202
- <Editor editorRef={jest.fn()} value={value} classes={{}} onChange={jest.fn()} onRef={jest.fn()} />,
203
- );
204
-
205
- const toolbarElement = document.createElement('div');
206
- const relatedTarget = document.createElement('button');
207
- toolbarElement.className = 'toolbar';
208
- toolbarElement.appendChild(relatedTarget);
209
-
210
- wrapper.instance().toolbarRef = toolbarElement;
211
-
212
- const event = { relatedTarget };
213
-
214
- await wrapper.instance().onBlur(event);
215
-
216
- expect(wrapper.state('focusToolbar')).toBe(true);
217
- });
218
-
219
- describe('buildSizeStyle', () => {
220
- const wrapper = (extras) => {
221
- const props = Object.assign({}, extras);
222
- return shallow(
223
- <Editor editorRef={jest.fn()} value={value} classes={{}} onChange={jest.fn()} onRef={jest.fn()} {...props} />,
224
- );
225
- };
226
-
227
- it('builds width with px', () => {
228
- const w = wrapper({ width: 100 });
229
- expect(w.instance().buildSizeStyle()).toEqual({
230
- width: '100px',
231
- height: undefined,
232
- minHeight: undefined,
233
- maxHeight: undefined,
234
- });
235
- });
236
-
237
- it('returns undefined for % ', () => {
238
- const w = wrapper({ height: '100%', width: '100%' });
239
- expect(w.instance().buildSizeStyle()).toEqual({
240
- width: undefined,
241
- height: undefined,
242
- minHeight: undefined,
243
- maxHeight: undefined,
244
- });
245
- });
246
-
247
- it('builds height', () => {
248
- const w = wrapper({ height: 100 });
249
- expect(w.instance().buildSizeStyle()).toEqual({
250
- width: undefined,
251
- height: '100px',
252
- minHeight: undefined,
253
- maxHeight: undefined,
254
- });
255
- });
256
-
257
- it('builds minHeight', () => {
258
- const w = wrapper({ minHeight: 100 });
259
- expect(w.instance().buildSizeStyle()).toEqual({
260
- width: undefined,
261
- height: undefined,
262
- minHeight: '100px',
263
- maxHeight: undefined,
264
- });
265
- });
266
-
267
- it('builds maxHeight', () => {
268
- const w = wrapper({ maxHeight: 100 });
269
- expect(w.instance().buildSizeStyle()).toEqual({
270
- width: undefined,
271
- height: undefined,
272
- minHeight: undefined,
273
- maxHeight: '100px',
274
- });
275
- });
276
-
277
- it('builds width with calc()', () => {
278
- const w = wrapper({ width: 'calc(10em + 42px)' });
279
- expect(w.instance().buildSizeStyle()).toEqual({
280
- width: 'calc(10em + 42px)',
281
- height: undefined,
282
- minHeight: undefined,
283
- maxHeight: undefined,
284
- });
285
- });
286
-
287
- it('builds width with ch', () => {
288
- const w = wrapper({ width: '9ch' });
289
- expect(w.instance().buildSizeStyle()).toEqual({
290
- width: '9ch',
291
- height: undefined,
292
- minHeight: undefined,
293
- maxHeight: undefined,
294
- });
295
- });
296
-
297
- it('builds', () => {
298
- const w = wrapper({});
299
- expect(w.instance().buildSizeStyle()).toEqual({
300
- width: undefined,
301
- height: undefined,
302
- minHeight: undefined,
303
- maxHeight: undefined,
304
- });
305
- });
306
- });
307
-
308
- describe('onResize', () => {
309
- it('should display html of current state on Resize', () => {
310
- const wrapper = shallow(
311
- <Editor editorRef={jest.fn()} value={value} classes={{}} onChange={jest.fn()} onRef={jest.fn()} />,
312
- );
313
-
314
- resizeWindow(500, 300);
315
- expect(wrapper.state('value')).toEqualHtml('<div>hi</div>');
316
-
317
- wrapper.instance().onChange({ value: htmlToValue('new value') });
318
- resizeWindow(1024, 768);
319
- expect(wrapper.state('value')).toEqualHtml('<div>new value</div>');
320
-
321
- resizeWindow(500, 300);
322
- expect(wrapper.state('value')).toEqualHtml('<div>new value</div>');
323
- });
324
- });
325
-
326
- describe('MathMl', () => {
327
- beforeEach(() => {});
328
-
329
- it('should not call runSerializationOnMarkup if mathMl props are not there', () => {
330
- const runSerializationOnMarkup = jest.fn();
331
-
332
- const wrapper = shallow(
333
- <Editor
334
- editorRef={jest.fn()}
335
- value={value}
336
- classes={{}}
337
- onChange={jest.fn()}
338
- onRef={jest.fn()}
339
- runSerializationOnMarkup={runSerializationOnMarkup}
340
- />,
341
- );
342
-
343
- expect(runSerializationOnMarkup).not.toHaveBeenCalled();
344
- });
345
-
346
- it('should call runSerializationOnMarkup if mmlEditing or mmlOutput are true', () => {
347
- const runSerializationOnMarkup = jest.fn();
348
-
349
- const wrapper = shallow(
350
- <Editor
351
- editorRef={jest.fn()}
352
- value={value}
353
- classes={{}}
354
- onChange={jest.fn()}
355
- onRef={jest.fn()}
356
- runSerializationOnMarkup={runSerializationOnMarkup}
357
- mathMlOptions={{ mmlOutput: true }}
358
- />,
359
- );
360
-
361
- expect(runSerializationOnMarkup).toHaveBeenCalled();
362
- });
363
- });