@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
@@ -1,100 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import React from 'react';
3
- import debug from 'debug';
4
- import ReactDOM from 'react-dom';
5
- import { withStyles } from '@material-ui/core/styles';
6
- import classNames from 'classnames';
7
-
8
- import { MarkButton } from '../toolbar/toolbar-buttons';
9
- import AltDialog from './alt-dialog';
10
-
11
- const log = debug('@pie-lib:editable-html:plugins:image:image-toolbar');
12
-
13
- const AlignmentButton = ({ alignment, active, onClick }) => {
14
- return (
15
- <MarkButton active={active} onToggle={() => onClick(alignment)} label={alignment}>
16
- {alignment}
17
- </MarkButton>
18
- );
19
- };
20
-
21
- AlignmentButton.propTypes = {
22
- alignment: PropTypes.string.isRequired,
23
- active: PropTypes.bool.isRequired,
24
- onClick: PropTypes.func.isRequired,
25
- };
26
-
27
- export class ImageToolbar extends React.Component {
28
- static propTypes = {
29
- onChange: PropTypes.func.isRequired,
30
- classes: PropTypes.object.isRequired,
31
- alignment: PropTypes.string,
32
- alt: PropTypes.string,
33
- imageLoaded: PropTypes.bool,
34
- disableImageAlignmentButtons: PropTypes.bool,
35
- };
36
-
37
- onAltTextDone = (newAlt) => {
38
- log('[onAltTextDone]: alt:', newAlt);
39
-
40
- this.props.onChange({ alt: newAlt }, true);
41
- };
42
-
43
- onAlignmentClick = (alignment) => {
44
- log('[onAlignmentClick]: alignment:', alignment);
45
- this.props.onChange({ alignment });
46
- };
47
-
48
- renderDialog = () => {
49
- const { alt } = this.props;
50
- const popoverEl = document.createElement('div');
51
-
52
- const el = <AltDialog alt={alt} onDone={this.onAltTextDone} />;
53
-
54
- ReactDOM.render(el, popoverEl);
55
-
56
- document.body.appendChild(popoverEl);
57
- };
58
-
59
- render() {
60
- const { classes, alignment, imageLoaded, disableImageAlignmentButtons } = this.props;
61
- return (
62
- <div className={classes.holder}>
63
- {!disableImageAlignmentButtons && (
64
- <>
65
- <AlignmentButton alignment={'left'} active={alignment === 'left'} onClick={this.onAlignmentClick} />
66
- <AlignmentButton alignment={'center'} active={alignment === 'center'} onClick={this.onAlignmentClick} />
67
- <AlignmentButton alignment={'right'} active={alignment === 'right'} onClick={this.onAlignmentClick} />
68
- </>
69
- )}
70
- <span
71
- className={classNames({
72
- [classes.disabled]: !imageLoaded,
73
- [classes.altButton]: !disableImageAlignmentButtons,
74
- })}
75
- onMouseDown={(event) => imageLoaded && this.renderDialog(event)}
76
- >
77
- Alt text
78
- </span>
79
- </div>
80
- );
81
- }
82
- }
83
-
84
- const styles = (theme) => ({
85
- holder: {
86
- paddingLeft: theme.spacing.unit,
87
- display: 'flex',
88
- alignItems: 'center',
89
- },
90
- disabled: {
91
- opacity: 0.5,
92
- },
93
- altButton: {
94
- borderLeft: '1px solid grey',
95
- paddingLeft: 8,
96
- marginLeft: 4,
97
- },
98
- });
99
-
100
- export default withStyles(styles)(ImageToolbar);
@@ -1,227 +0,0 @@
1
- import { Data, Inline } from 'slate';
2
-
3
- import Image from '@material-ui/icons/Image';
4
- import ImageComponent from './component';
5
- import ImageToolbar from './image-toolbar';
6
- import InsertImageHandler from './insert-image-handler';
7
- import React from 'react';
8
- import debug from 'debug';
9
-
10
- const log = debug('@pie-lib:editable-html:plugins:image');
11
-
12
- export default function ImagePlugin(opts) {
13
- const toolbar = opts.insertImageRequested && {
14
- icon: <Image />,
15
- ariaLabel: 'Insert Image',
16
- onClick: (value, onChange) => {
17
- log('[toolbar] onClick');
18
- const inline = Inline.create({
19
- type: 'image',
20
- isVoid: true,
21
- data: {
22
- loaded: false,
23
- src: undefined,
24
- },
25
- });
26
-
27
- const change = value.change().insertInline(inline);
28
-
29
- onChange(change);
30
- opts.insertImageRequested(
31
- inline,
32
- (onFinish, getValue) => new InsertImageHandler(inline, onFinish, getValue, onChange),
33
- );
34
- },
35
- supports: (node) => node.object === 'inline' && node.type === 'image',
36
- customToolbar: (node, value, onToolbarDone) => {
37
- const alignment = node.data.get('alignment');
38
- const alt = node.data.get('alt');
39
- const imageLoaded = node.data.get('loaded') !== false;
40
- const onChange = (newValues, done) => {
41
- const update = {
42
- ...node.data.toObject(),
43
- ...newValues,
44
- };
45
-
46
- const change = value.change().setNodeByKey(node.key, { data: update });
47
- onToolbarDone(change, done);
48
- };
49
-
50
- const Tb = () => (
51
- <ImageToolbar
52
- disableImageAlignmentButtons={opts.disableImageAlignmentButtons}
53
- alt={alt}
54
- imageLoaded={imageLoaded}
55
- alignment={alignment || 'left'}
56
- onChange={onChange}
57
- />
58
- );
59
- return Tb;
60
- },
61
- showDone: true,
62
- };
63
-
64
- return {
65
- name: 'image',
66
- toolbar,
67
- deleteNode: (e, node, value, onChange) => {
68
- e.preventDefault();
69
- if (opts.onDelete) {
70
- const update = node.data.merge(Data.create({ deleteStatus: 'pending' }));
71
-
72
- let change = value.change().setNodeByKey(node.key, { data: update });
73
-
74
- onChange(change);
75
- opts.onDelete(node, (err, v) => {
76
- if (!err) {
77
- change = v.change().removeNodeByKey(node.key);
78
- } else {
79
- log('[error]: ', err);
80
- change = v.change().setNodeByKey(node.key, node.data.merge(Data.create({ deleteStatus: 'failed' })));
81
- }
82
- onChange(change);
83
- });
84
- } else {
85
- let change = value.change().removeNodeByKey(node.key);
86
- onChange(change);
87
- }
88
- },
89
- stopReset: (value) => {
90
- const imgPendingInsertion = value.document.findDescendant((n) => {
91
- if (n.type !== 'image') {
92
- return;
93
- }
94
- return n.data.get('loaded') === false;
95
- });
96
- /** don't reset if there is an image pending insertion */
97
- return imgPendingInsertion !== undefined && imgPendingInsertion !== null;
98
- },
99
- renderNode(props) {
100
- if (props.node.type === 'image') {
101
- const all = Object.assign(
102
- {
103
- onDelete: opts.onDelete,
104
- onFocus: opts.onFocus,
105
- onBlur: opts.onBlur,
106
- maxImageWidth: opts.maxImageWidth,
107
- maxImageHeight: opts.maxImageHeight,
108
- },
109
- props,
110
- );
111
- return <ImageComponent {...all} />;
112
- }
113
- },
114
- normalizeNode: (node) => {
115
- const textNodeMap = {};
116
- const updateNodesArray = [];
117
- let index = 0;
118
-
119
- if (node.object !== 'document') return;
120
-
121
- node.findDescendant((d) => {
122
- if (d.object === 'text') {
123
- textNodeMap[index] = d;
124
- }
125
-
126
- if (d.type === 'image') {
127
- if (index > 0 && textNodeMap[index - 1] && textNodeMap[index - 1].text === '') {
128
- updateNodesArray.push(textNodeMap[index - 1]);
129
- }
130
- }
131
-
132
- index++;
133
- });
134
-
135
- if (!updateNodesArray.length) return;
136
-
137
- return (change) => {
138
- change.withoutNormalization(() => {
139
- updateNodesArray.forEach((n) => change.insertTextByKey(n.key, 0, ' '));
140
- });
141
- };
142
- },
143
- };
144
- }
145
-
146
- export const serialization = {
147
- deserialize(el /*, next*/) {
148
- const name = el.tagName.toLowerCase();
149
- if (name !== 'img') return;
150
-
151
- log('deserialize: ', name);
152
- const style = el.style || { width: '', height: '', margin: '', justifyContent: '' };
153
- const width = parseInt(style.width.replace('px', ''), 10) || null;
154
- const height = parseInt(style.height.replace('px', ''), 10) || null;
155
-
156
- const out = {
157
- object: 'inline',
158
- type: 'image',
159
- isVoid: true,
160
- data: {
161
- src: el.getAttribute('src'),
162
- width,
163
- height,
164
- margin: el.style.margin,
165
- justifyContent: el.style.justifyContent,
166
- alignment: el.getAttribute('alignment'),
167
- alt: el.getAttribute('alt'),
168
- },
169
- };
170
- log('return object: ', out);
171
- return out;
172
- },
173
- serialize(object /*, children*/) {
174
- if (object.type !== 'image') return;
175
-
176
- const { data } = object;
177
- const src = data.get('src');
178
- const width = data.get('width');
179
- const height = data.get('height');
180
- const alignment = data.get('alignment') || 'left';
181
- const margin = data.get('margin');
182
- const justifyContent = data.get('margin');
183
- const alt = data.get('alt');
184
- const style = {};
185
- if (width) {
186
- style.width = `${width}px`;
187
- }
188
-
189
- if (height) {
190
- style.height = `${height}px`;
191
- }
192
-
193
- style.margin = margin;
194
- style.justifyContent = justifyContent;
195
-
196
- if (alignment) {
197
- switch (alignment) {
198
- case 'left':
199
- style.justifyContent = 'flex-start';
200
- style.margin = '0';
201
- break;
202
- case 'center':
203
- style.justifyContent = 'center';
204
- style.margin = '0 auto';
205
- break;
206
- case 'right':
207
- style.justifyContent = 'flex-end';
208
- style.margin = 'auto 0 0 auto';
209
- break;
210
- default:
211
- style.justifyContent = 'flex-start';
212
- break;
213
- }
214
- }
215
-
216
- style.objectFit = 'contain';
217
-
218
- const props = {
219
- src,
220
- style,
221
- alignment,
222
- alt,
223
- };
224
-
225
- return <img {...props} />;
226
- },
227
- };
@@ -1,79 +0,0 @@
1
- import { Data } from 'slate';
2
- import debug from 'debug';
3
-
4
- const log = debug('@pie-lib:editable-html:image:insert-image-handler');
5
-
6
- /**
7
- * Handles user selection, insertion (or cancellation) of an image into the editor.
8
- * @param {Block} placeholderBlock - a block that has been added to the editor as a place holder for the image
9
- * @param {Function} onFinish - a function to call if uploading fails or succeeds
10
- * @param {Function} getValue - a function to return the value of the editor
11
- * @param {Function} onChange - callback to notify changes applied by the handler
12
- * @param {Boolean} isPasted - a boolean that keeps track if the file is pasted
13
- */
14
- class InsertImageHandler {
15
- constructor(editor, onFinish, isPasted = false) {
16
- this.editor = editor;
17
- this.onFinish = onFinish;
18
- this.isPasted = isPasted;
19
- this.chosenFile = null;
20
- }
21
-
22
- cancel() {
23
- log('insert cancelled');
24
-
25
- try {
26
- this.editor.commands.deleteNode('imageUploadNode');
27
- this.onFinish(false);
28
- } catch (err) {
29
- //
30
- }
31
- }
32
-
33
- done(err, src) {
34
- log('done: err:', err);
35
- if (err) {
36
- //eslint-disable-next-line
37
- console.log(err);
38
- this.onFinish(false);
39
- } else {
40
- this.editor.commands.updateAttributes('imageUploadNode', { loaded: true, src, percent: 100 });
41
- this.onFinish(true);
42
- }
43
- }
44
-
45
- /**
46
- * Notify handler that the user chose a file - will create a change with a preview in the editor.
47
- *
48
- * @param {File} file - the file that the user chose using a file input.
49
- */
50
- fileChosen(file) {
51
- if (!file) {
52
- return;
53
- }
54
-
55
- // Save the chosen file to this.chosenFile
56
- this.chosenFile = file;
57
-
58
- log('[fileChosen] file: ', file);
59
- const reader = new FileReader();
60
- reader.onload = () => {
61
- const dataURL = reader.result;
62
-
63
- this.editor.commands.updateAttributes('imageUploadNode', { src: dataURL });
64
- };
65
- reader.readAsDataURL(file);
66
- }
67
-
68
- progress(percent, bytes, total) {
69
- log('progress: ', percent, bytes, total);
70
- this.editor.commands.updateAttributes('imageUploadNode', { percent });
71
- }
72
-
73
- // Add a getter method to retrieve the chosen file
74
- getChosenFile() {
75
- return this.chosenFile;
76
- }
77
- }
78
-
79
- export default InsertImageHandler;