@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,338 +0,0 @@
1
- import React from 'react';
2
- import { Change } from 'slate';
3
- import Delete from '@material-ui/icons/Delete';
4
- import IconButton from '@material-ui/core/IconButton';
5
- import PropTypes from 'prop-types';
6
- import classNames from 'classnames';
7
- import debug from 'debug';
8
- import SlatePropTypes from 'slate-prop-types';
9
- import debounce from 'lodash/debounce';
10
-
11
- import { DoneButton } from './done-button';
12
-
13
- import { findSingleNode, findParentNode } from '../utils';
14
- import { withStyles } from '@material-ui/core/styles';
15
- import DefaultToolbar from './default-toolbar';
16
- import { removeDialogs as removeCharacterDialogs } from '../characters';
17
- import { PIE_TOOLBAR__CLASS } from '../../constants';
18
-
19
- const log = debug('@pie-lib:editable-html:plugins:toolbar');
20
-
21
- const getCustomToolbar = (plugin, node, value, handleDone, getFocusedValue, onDataChange) => {
22
- if (!plugin) {
23
- return;
24
- }
25
-
26
- if (!plugin.toolbar) {
27
- return;
28
- }
29
-
30
- if (plugin.toolbar.CustomToolbarComp) {
31
- /**
32
- * Using a pre-defined Component should be preferred
33
- * as the rendering of it (and it's children) can be optimized by React.
34
- * If you keep re-defining the comp with an inline function
35
- * then react will have to re-render.
36
- */
37
- return plugin.toolbar.CustomToolbarComp;
38
- } else if (typeof plugin.toolbar.customToolbar === 'function') {
39
- log('deprecated - use CustomToolbarComp');
40
- return plugin.toolbar.customToolbar(node, value, handleDone, getFocusedValue, onDataChange);
41
- }
42
- };
43
-
44
- export class Toolbar extends React.Component {
45
- static propTypes = {
46
- zIndex: PropTypes.number,
47
- value: SlatePropTypes.value.isRequired,
48
- plugins: PropTypes.array,
49
- plugin: PropTypes.object,
50
- onImageClick: PropTypes.func,
51
- onDone: PropTypes.func.isRequired,
52
- toolbarRef: PropTypes.func.isRequired,
53
- classes: PropTypes.object.isRequired,
54
- isFocused: PropTypes.bool,
55
- autoWidth: PropTypes.bool,
56
- onChange: PropTypes.func.isRequired,
57
- getFocusedValue: PropTypes.func.isRequired,
58
- pluginProps: PropTypes.object,
59
- toolbarOpts: PropTypes.shape({
60
- position: PropTypes.oneOf(['bottom', 'top']),
61
- alignment: PropTypes.oneOf(['left', 'right']),
62
- alwaysVisible: PropTypes.bool,
63
- ref: PropTypes.func,
64
- showDone: PropTypes.bool,
65
- minWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
66
- isHidden: PropTypes.bool,
67
- }),
68
- onDataChange: PropTypes.func,
69
- doneButtonRef: PropTypes.func,
70
- onBlur: PropTypes.func,
71
- onFocus: PropTypes.func,
72
- };
73
-
74
- constructor(props) {
75
- super(props);
76
- this.state = {
77
- change: null,
78
- };
79
- }
80
-
81
- componentWillUnmount() {
82
- removeCharacterDialogs();
83
- }
84
-
85
- hasMark = (type) => {
86
- const { value } = this.props;
87
- return value.marks.some((mark) => mark.type == type);
88
- };
89
-
90
- hasBlock = (type) => {
91
- const { value } = this.props;
92
- return value.blocks.some((node) => node.type == type);
93
- };
94
-
95
- onToggle = (plugin) => {
96
- const { value, onChange } = this.props;
97
-
98
- if (!plugin.onToggle) return;
99
-
100
- const change = plugin.onToggle(value.change());
101
- onChange(change);
102
- };
103
-
104
- onClick = (e) => {
105
- log('[onClick]');
106
- e.preventDefault();
107
- };
108
-
109
- onButtonClick = (fn) => {
110
- return (e) => {
111
- e.preventDefault();
112
- fn();
113
- };
114
- };
115
-
116
- onToolbarDone = (change, finishEditing) => {
117
- log('[onToolbarDone] change: ', change, 'finishEditing: ', finishEditing);
118
- const { onChange, onDone } = this.props;
119
-
120
- // use handler only if this is an actual Slate Change
121
- if (change instanceof Change) {
122
- onChange(change, () => {
123
- if (finishEditing) {
124
- onDone();
125
- }
126
- });
127
- } else {
128
- if (finishEditing) {
129
- log('[onToolbarChange] call onDone');
130
- onDone();
131
- }
132
- }
133
- };
134
-
135
- onDeleteClick = debounce((e, plugin, node, value, onChange) => plugin.deleteNode(e, node, value, onChange), 500);
136
-
137
- onDeleteMouseDown = (e, plugin, node, value, onChange) => {
138
- e.persist();
139
- this.onDeleteClick(e, plugin, node, value, onChange);
140
- };
141
-
142
- render() {
143
- const {
144
- classes,
145
- plugins,
146
- pluginProps,
147
- toolbarOpts,
148
- value,
149
- autoWidth,
150
- onChange,
151
- getFocusedValue,
152
- isFocused,
153
- onDone,
154
- toolbarRef,
155
- doneButtonRef,
156
- onBlur,
157
- onFocus,
158
- } = this.props;
159
-
160
- const node = findSingleNode(value);
161
- const parentNode = findParentNode(value, node);
162
-
163
- log(' --------------> [render] node: ', node);
164
- log('[render] node: ', node);
165
-
166
- const plugin = plugins.find((p) => {
167
- if (!node) {
168
- return;
169
- }
170
-
171
- if (p.toolbar) {
172
- return p.toolbar.supports && p.toolbar.supports(node, value);
173
- }
174
- });
175
- const parentPlugin = plugins.find((p) => {
176
- if (!parentNode) {
177
- return;
178
- }
179
-
180
- if (p.toolbar) {
181
- return p.toolbar.supports && p.toolbar.supports(parentNode, value);
182
- }
183
- });
184
-
185
- log('[render] plugin: ', plugin);
186
-
187
- const handleDone = (change, done) => {
188
- let handler = onDone;
189
-
190
- if (plugin && plugin.toolbar && plugin.toolbar.customToolbar) {
191
- handler = this.onToolbarDone;
192
- }
193
-
194
- handler(change, done);
195
-
196
- if (parentPlugin && parentPlugin.handleDone) {
197
- parentPlugin.handleDone(value, node, plugin, onChange);
198
- }
199
- };
200
-
201
- const handleDataChange = (key, data) => {
202
- this.props.onDataChange(key, data);
203
- };
204
-
205
- const CustomToolbar = getCustomToolbar(plugin, node, value, handleDone, getFocusedValue, this.props.onDataChange);
206
-
207
- const filteredPlugins = plugin && plugin.filterPlugins ? plugin.filterPlugins(node, plugins) : plugins;
208
-
209
- log('[render] CustomToolbar: ', CustomToolbar);
210
- const parentExtraStyles =
211
- parentPlugin && parentPlugin.pluginStyles ? parentPlugin.pluginStyles(node, parentNode, plugin) : {};
212
- const pluginExtraStyles = plugin && plugin.pluginStyles ? plugin.pluginStyles(node, parentNode, plugin) : {};
213
- const extraStyles = {
214
- ...pluginExtraStyles,
215
- ...parentExtraStyles,
216
- };
217
-
218
- const deletable = node && plugin && plugin.deleteNode;
219
- const customToolbarShowDone =
220
- node && plugin && plugin.toolbar && plugin.toolbar.showDone && !toolbarOpts.alwaysVisible;
221
-
222
- // If there is a toolbarOpts we check if the showDone is not equal to false
223
- const defaultToolbarShowDone = !toolbarOpts || toolbarOpts.showDone !== false;
224
-
225
- const hasDoneButton = defaultToolbarShowDone || customToolbarShowDone;
226
-
227
- const names = classNames(classes.toolbar, PIE_TOOLBAR__CLASS, {
228
- [classes.toolbarWithNoDone]: !hasDoneButton,
229
- [classes.toolbarTop]: toolbarOpts.position === 'top',
230
- [classes.toolbarRight]: toolbarOpts.alignment === 'right',
231
- [classes.focused]: toolbarOpts.alwaysVisible || isFocused,
232
- [classes.autoWidth]: autoWidth,
233
- [classes.fullWidth]: !autoWidth,
234
- [classes.hidden]: toolbarOpts.isHidden === true,
235
- });
236
- const customStyles = toolbarOpts.minWidth !== undefined ? { minWidth: toolbarOpts.minWidth } : {};
237
-
238
- return (
239
- <div className={names} style={{ ...extraStyles, ...customStyles }} onClick={this.onClick} ref={toolbarRef}>
240
- {CustomToolbar ? (
241
- <CustomToolbar
242
- node={node}
243
- value={value}
244
- getFocusedValue={getFocusedValue}
245
- onToolbarDone={this.onToolbarDone}
246
- onDataChange={handleDataChange}
247
- pluginProps={pluginProps}
248
- />
249
- ) : (
250
- <DefaultToolbar
251
- plugins={filteredPlugins}
252
- pluginProps={pluginProps}
253
- value={value}
254
- onChange={onChange}
255
- getFocusedValue={getFocusedValue}
256
- showDone={defaultToolbarShowDone}
257
- onDone={handleDone}
258
- deletable={deletable}
259
- isHtmlMode={toolbarOpts.isHtmlMode}
260
- onFocus={onFocus}
261
- doneButtonRef={doneButtonRef}
262
- onBlur={onBlur}
263
- />
264
- )}
265
-
266
- <div className={classes.shared}>
267
- {deletable && (
268
- <IconButton
269
- aria-label="Delete"
270
- className={classes.iconRoot}
271
- onMouseDown={(e) => this.onDeleteMouseDown(e, plugin, node, value, onChange)}
272
- classes={{
273
- root: classes.iconRoot,
274
- }}
275
- >
276
- <Delete />
277
- </IconButton>
278
- )}
279
- {customToolbarShowDone && <DoneButton doneButtonRef={doneButtonRef} onClick={handleDone} />}
280
- </div>
281
- </div>
282
- );
283
- }
284
- }
285
-
286
- const style = {
287
- toolbar: {
288
- position: 'absolute',
289
- zIndex: 10,
290
- cursor: 'pointer',
291
- justifyContent: 'space-between',
292
- background: 'var(--editable-html-toolbar-bg, #efefef)',
293
- minWidth: '280px',
294
- margin: '5px 0 0 0',
295
- padding: '2px',
296
- boxShadow:
297
- '0px 1px 5px 0px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)',
298
- boxSizing: 'border-box',
299
- display: 'flex',
300
- opacity: 0,
301
- pointerEvents: 'none',
302
- },
303
- toolbarWithNoDone: {
304
- minWidth: '265px',
305
- },
306
- toolbarTop: {
307
- top: '-45px',
308
- },
309
- toolbarRight: {
310
- right: 0,
311
- },
312
- fullWidth: {
313
- width: '100%',
314
- },
315
- hidden: {
316
- visibility: 'hidden',
317
- },
318
- autoWidth: {
319
- width: 'auto',
320
- },
321
- focused: {
322
- opacity: 1,
323
- pointerEvents: 'auto',
324
- },
325
- iconRoot: {
326
- width: '28px',
327
- height: '28px',
328
- padding: '4px',
329
- verticalAlign: 'top',
330
- },
331
- label: {
332
- color: 'var(--editable-html-toolbar-check, #00bb00)',
333
- },
334
- shared: {
335
- display: 'flex',
336
- },
337
- };
338
- export default withStyles(style, { index: 1000 })(Toolbar);
@@ -1,31 +0,0 @@
1
- export const findSingleNode = (value) => {
2
- if (!value || !value.isCollapsed || !value.startKey) {
3
- return;
4
- }
5
-
6
- const inline = value.document.getClosestInline(value.startKey);
7
-
8
- if (inline) {
9
- return inline;
10
- }
11
-
12
- const block = value.document.getClosestBlock(value.startKey);
13
-
14
- if (block) {
15
- return block;
16
- }
17
- };
18
-
19
- export const findParentNode = (value, node) => {
20
- if (!value || !node) {
21
- return;
22
- }
23
-
24
- return value.document.getParent(node.key);
25
- };
26
-
27
- export const hasMark = (value, type) => value && value.marks.some((mark) => mark.type == type);
28
-
29
- export const hasBlock = (value, type) => value && value.blocks.some((node) => node.type == type);
30
-
31
- export const hasNode = ({ document }, type) => document && document.nodes.some((node) => node.type == type);