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

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 (165) hide show
  1. package/lib/components/CharacterPicker.js +221 -0
  2. package/lib/components/CharacterPicker.js.map +1 -0
  3. package/lib/components/EditableHtml.js +323 -0
  4. package/lib/components/EditableHtml.js.map +1 -0
  5. package/lib/components/MenuBar.js +694 -0
  6. package/lib/components/MenuBar.js.map +1 -0
  7. package/lib/components/TiptapContainer.js +90 -0
  8. package/lib/components/TiptapContainer.js.map +1 -0
  9. package/lib/components/buttons/done-button.js +53 -0
  10. package/lib/components/characters/characterUtils.js +112 -0
  11. package/lib/components/characters/characterUtils.js.map +1 -0
  12. package/lib/components/characters/custom-popper.js +73 -0
  13. package/lib/components/characters/custom-popper.js.map +1 -0
  14. package/lib/components/common/done-button.js +53 -0
  15. package/lib/components/common/done-button.js.map +1 -0
  16. package/lib/components/common/toolbar-buttons.js +194 -0
  17. package/lib/components/icons/CssIcon.js +37 -0
  18. package/lib/components/icons/CssIcon.js.map +1 -0
  19. package/lib/components/icons/RespArea.js +95 -0
  20. package/lib/components/icons/RespArea.js.map +1 -0
  21. package/lib/components/icons/TableIcons.js +69 -0
  22. package/lib/components/icons/TableIcons.js.map +1 -0
  23. package/lib/components/icons/TextAlign.js +194 -0
  24. package/lib/components/icons/TextAlign.js.map +1 -0
  25. package/lib/components/icons/index.js +194 -0
  26. package/lib/components/image/AltDialog.js +129 -0
  27. package/lib/components/image/ImageToolbar.js +177 -0
  28. package/lib/components/image/ImageToolbar.js.map +1 -0
  29. package/lib/components/image/InsertImageHandler.js +115 -0
  30. package/lib/components/image/InsertImageHandler.js.map +1 -0
  31. package/lib/components/image/alt-dialog.js +2 -0
  32. package/lib/components/media/MediaDialog.js +709 -0
  33. package/lib/components/media/MediaDialog.js.map +1 -0
  34. package/lib/components/media/MediaToolbar.js +101 -0
  35. package/lib/components/media/MediaToolbar.js.map +1 -0
  36. package/lib/components/media/MediaWrapper.js +93 -0
  37. package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +94 -0
  38. package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +1 -0
  39. package/lib/components/respArea/DragInTheBlank/choice.js +289 -0
  40. package/lib/components/respArea/DragInTheBlank/choice.js.map +1 -0
  41. package/lib/components/respArea/DragInTheBlank.js +94 -0
  42. package/lib/components/respArea/ExplicitConstructedResponse.js +120 -0
  43. package/lib/components/respArea/ExplicitConstructedResponse.js.map +1 -0
  44. package/lib/components/respArea/InlineDropdown.js +126 -0
  45. package/lib/components/respArea/InlineDropdown.js.map +1 -0
  46. package/lib/components/respArea/ToolbarIcon.js +105 -0
  47. package/lib/components/respArea/ToolbarIcon.js.map +1 -0
  48. package/lib/components/respArea/choice.js +2 -0
  49. package/lib/constants.js.map +1 -0
  50. package/lib/extensions/component.js +5 -5
  51. package/lib/extensions/component.js.map +1 -0
  52. package/lib/extensions/css.js.map +1 -0
  53. package/lib/extensions/custom-toolbar-wrapper.js +2 -4
  54. package/lib/extensions/custom-toolbar-wrapper.js.map +1 -0
  55. package/lib/extensions/extended-table.js +30 -0
  56. package/lib/extensions/extended-table.js.map +1 -0
  57. package/lib/extensions/image.js +2 -8
  58. package/lib/extensions/image.js.map +1 -0
  59. package/lib/extensions/index.js +52 -0
  60. package/lib/extensions/index.js.map +1 -0
  61. package/lib/extensions/math.js.map +1 -0
  62. package/lib/extensions/media.js +7 -7
  63. package/lib/extensions/media.js.map +1 -0
  64. package/lib/extensions/responseArea.js +7 -7
  65. package/lib/extensions/responseArea.js.map +1 -0
  66. package/lib/index.js +16 -1481
  67. package/lib/index.js.map +1 -0
  68. package/lib/plugins/index.js +8 -80
  69. package/lib/styles/editorContainerStyles.js +200 -0
  70. package/lib/styles/editorContainerStyles.js.map +1 -0
  71. package/lib/theme.js.map +1 -0
  72. package/lib/utils/size.js +34 -0
  73. package/lib/utils/size.js.map +1 -0
  74. package/package.json +1 -1
  75. package/src/components/CharacterPicker.jsx +185 -0
  76. package/src/components/EditableHtml.jsx +306 -0
  77. package/src/components/MenuBar.jsx +630 -0
  78. package/src/components/TiptapContainer.jsx +96 -0
  79. package/src/components/characters/characterUtils.js +127 -0
  80. package/src/{plugins/image/image-toolbar.jsx → components/image/ImageToolbar.jsx} +2 -2
  81. package/src/{plugins/image/insert-image-handler.js → components/image/InsertImageHandler.js} +0 -1
  82. package/src/{plugins/media/media-dialog.js → components/media/MediaDialog.js} +2 -2
  83. package/src/{plugins/respArea/drag-in-the-blank → components/respArea/DragInTheBlank}/choice.jsx +1 -1
  84. package/src/{plugins/respArea/inline-dropdown/index.jsx → components/respArea/InlineDropdown.jsx} +1 -1
  85. package/src/components/respArea/ToolbarIcon.jsx +68 -0
  86. package/src/extensions/component.jsx +2 -2
  87. package/src/extensions/custom-toolbar-wrapper.jsx +6 -7
  88. package/src/extensions/extended-table.js +27 -0
  89. package/src/extensions/image.js +2 -2
  90. package/src/extensions/index.js +76 -0
  91. package/src/extensions/media.js +12 -7
  92. package/src/extensions/responseArea.js +7 -7
  93. package/src/index.jsx +3 -1440
  94. package/src/styles/editorContainerStyles.js +203 -0
  95. package/src/utils/size.js +32 -0
  96. package/src/__tests__/editor.test.jsx +0 -363
  97. package/src/__tests__/serialization.test.js +0 -291
  98. package/src/block-tags.js +0 -17
  99. package/src/editor.jsx +0 -1197
  100. package/src/extensions/characters.js +0 -46
  101. package/src/old-index.jsx +0 -162
  102. package/src/parse-html.js +0 -8
  103. package/src/plugins/README.md +0 -27
  104. package/src/plugins/characters/index.jsx +0 -284
  105. package/src/plugins/characters/utils.js +0 -447
  106. package/src/plugins/css/index.jsx +0 -340
  107. package/src/plugins/customPlugin/index.jsx +0 -85
  108. package/src/plugins/html/icons/index.jsx +0 -19
  109. package/src/plugins/html/index.jsx +0 -72
  110. package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +0 -51
  111. package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +0 -27
  112. package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +0 -44
  113. package/src/plugins/image/__tests__/component.test.jsx +0 -41
  114. package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +0 -42
  115. package/src/plugins/image/__tests__/image-toolbar.test.jsx +0 -11
  116. package/src/plugins/image/__tests__/index.test.js +0 -95
  117. package/src/plugins/image/__tests__/insert-image-handler.test.js +0 -113
  118. package/src/plugins/image/__tests__/mock-change.js +0 -15
  119. package/src/plugins/image/component.jsx +0 -343
  120. package/src/plugins/image/index.jsx +0 -227
  121. package/src/plugins/index.jsx +0 -377
  122. package/src/plugins/list/__tests__/index.test.js +0 -54
  123. package/src/plugins/list/index.jsx +0 -305
  124. package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +0 -48
  125. package/src/plugins/math/__tests__/index.test.jsx +0 -245
  126. package/src/plugins/math/index.jsx +0 -379
  127. package/src/plugins/media/__tests__/index.test.js +0 -75
  128. package/src/plugins/media/index.jsx +0 -325
  129. package/src/plugins/rendering/index.js +0 -31
  130. package/src/plugins/respArea/index.jsx +0 -299
  131. package/src/plugins/respArea/math-templated/index.jsx +0 -104
  132. package/src/plugins/respArea/utils.jsx +0 -90
  133. package/src/plugins/table/CustomTablePlugin.js +0 -113
  134. package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +0 -44
  135. package/src/plugins/table/__tests__/index.test.jsx +0 -401
  136. package/src/plugins/table/__tests__/table-toolbar.test.jsx +0 -42
  137. package/src/plugins/table/index.jsx +0 -427
  138. package/src/plugins/table/table-toolbar.jsx +0 -136
  139. package/src/plugins/textAlign/index.jsx +0 -23
  140. package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +0 -923
  141. package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +0 -20
  142. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +0 -36
  143. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +0 -46
  144. package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +0 -94
  145. package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +0 -37
  146. package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +0 -51
  147. package/src/plugins/toolbar/__tests__/toolbar.test.jsx +0 -106
  148. package/src/plugins/toolbar/default-toolbar.jsx +0 -206
  149. package/src/plugins/toolbar/editor-and-toolbar.jsx +0 -257
  150. package/src/plugins/toolbar/index.jsx +0 -23
  151. package/src/plugins/toolbar/toolbar.jsx +0 -338
  152. package/src/plugins/utils.js +0 -31
  153. package/src/serialization.jsx +0 -621
  154. /package/src/{plugins → components}/characters/custom-popper.js +0 -0
  155. /package/src/{plugins/toolbar → components/common}/done-button.jsx +0 -0
  156. /package/src/{plugins/toolbar → components/common}/toolbar-buttons.jsx +0 -0
  157. /package/src/{plugins/css/icons/index.jsx → components/icons/CssIcon.jsx} +0 -0
  158. /package/src/{plugins/respArea/icons/index.jsx → components/icons/RespArea.jsx} +0 -0
  159. /package/src/{plugins/table/icons/index.jsx → components/icons/TableIcons.jsx} +0 -0
  160. /package/src/{plugins/textAlign/icons/index.jsx → components/icons/TextAlign.jsx} +0 -0
  161. /package/src/{plugins/image/alt-dialog.jsx → components/image/AltDialog.jsx} +0 -0
  162. /package/src/{plugins/media/media-toolbar.jsx → components/media/MediaToolbar.jsx} +0 -0
  163. /package/src/{plugins/media/media-wrapper.jsx → components/media/MediaWrapper.jsx} +0 -0
  164. /package/src/{plugins/respArea/drag-in-the-blank/index.jsx → components/respArea/DragInTheBlank/DragInTheBlank.jsx} +0 -0
  165. /package/src/{plugins/respArea/explicit-constructed-response/index.jsx → components/respArea/ExplicitConstructedResponse.jsx} +0 -0
@@ -0,0 +1,630 @@
1
+ import React, { useMemo, useState } from 'react';
2
+ import classNames from 'classnames';
3
+ import { withStyles } from '@material-ui/core/styles';
4
+ import { NodeSelection } from 'prosemirror-state';
5
+
6
+ import Bold from '@material-ui/icons/FormatBold';
7
+ import Italic from '@material-ui/icons/FormatItalic';
8
+ import Strikethrough from '@material-ui/icons/FormatStrikethrough';
9
+ import Code from '@material-ui/icons/Code';
10
+ import GridOn from '@material-ui/icons/GridOn';
11
+ import BulletedListIcon from '@material-ui/icons/FormatListBulleted';
12
+ import NumberedListIcon from '@material-ui/icons/FormatListNumbered';
13
+ import Underline from '@material-ui/icons/FormatUnderlined';
14
+ import Functions from '@material-ui/icons/Functions';
15
+ import ImageIcon from '@material-ui/icons/Image';
16
+ import Redo from '@material-ui/icons/Redo';
17
+ import Undo from '@material-ui/icons/Undo';
18
+ import TheatersIcon from '@material-ui/icons/Theaters';
19
+ import VolumeUpIcon from '@material-ui/icons/VolumeUp';
20
+ import BorderAll from '@material-ui/icons/BorderAll';
21
+
22
+ import { EditorContent, useEditorState } from '@tiptap/react';
23
+
24
+ import { PIE_TOOLBAR__CLASS } from '../constants';
25
+ import { ToolbarIcon } from './respArea/ToolbarIcon';
26
+ import { spanishConfig, specialConfig } from './characters/characterUtils';
27
+ import TextAlignIcon from './icons/TextAlign';
28
+ import CSSIcon from './icons/CssIcon';
29
+ import { AddColumn, AddRow, RemoveColumn, RemoveRow, RemoveTable } from './icons/tableIcons';
30
+
31
+ import { CharacterIcon, CharacterPicker } from './CharacterPicker';
32
+ import { DoneButton } from './common/done-button';
33
+
34
+ const SuperscriptIcon = () => (
35
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="none">
36
+ <path
37
+ d="M22,7h-2v1h3v1h-4V7c0-0.55,0.45-1,1-1h2V5h-3V4h3c0.55,0,1,0.45,1,1v1C23,6.55,22.55,7,22,7z M5.88,20h2.66l3.4-5.42h0.12 l3.4,5.42h2.66l-4.65-7.27L17.81,6h-2.68l-3.07,4.99h-0.12L8.85,6H6.19l4.32,6.73L5.88,20z"
38
+ fill="currentColor"
39
+ />
40
+ </svg>
41
+ );
42
+
43
+ const SubscriptIcon = () => (
44
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="none">
45
+ <path
46
+ d="M22,18h-2v1h3v1h-4v-2c0-0.55,0.45-1,1-1h2v-1h-3v-1h3c0.55,0,1,0.45,1,1v1C23,17.55,22.55,18,22,18z M5.88,18h2.66 l3.4-5.42h0.12l3.4,5.42h2.66l-4.65-7.27L17.81,4h-2.68l-3.07,4.99h-0.12L8.85,4H6.19l4.32,6.73L5.88,18z"
47
+ fill="currentColor"
48
+ />
49
+ </svg>
50
+ );
51
+
52
+ const HeadingIcon = () => (
53
+ <svg
54
+ width="30"
55
+ height="28"
56
+ viewBox="0 0 30 28"
57
+ fill="none"
58
+ xmlns="http://www.w3.org/2000/svg"
59
+ style={{ width: '20px', height: '18px' }}
60
+ >
61
+ <path
62
+ d="M27 4V24H29C29.5 24 30 24.5 30 25V27C30 27.5625 29.5 28 29 28H19C18.4375 28 18 27.5625 18 27V25C18 24.5 18.4375 24 19 24H21V16H9V24H11C11.5 24 12 24.5 12 25V27C12 27.5625 11.5 28 11 28H1C0.4375 28 0 27.5625 0 27V25C0 24.5 0.4375 24 1 24H3V4H1C0.4375 4 0 3.5625 0 3V1C0 0.5 0.4375 0 1 0H11C11.5 0 12 0.5 12 1V3C12 3.5625 11.5 4 11 4H9V12H21V4H19C18.4375 4 18 3.5625 18 3V1C18 0.5 18.4375 0 19 0H29C29.5 0 30 0.5 30 1V3C30 3.5625 29.5 4 29 4H27Z"
63
+ fill="currentColor"
64
+ />
65
+ </svg>
66
+ );
67
+
68
+ function MenuBar({ editor, classes, activePlugins, toolbarOpts: toolOpts, responseAreaProps, onChange }) {
69
+ const [showPicker, setShowPicker] = useState(false);
70
+ const toolbarOpts = toolOpts ?? {};
71
+
72
+ const editorState = useEditorState({
73
+ editor,
74
+ selector: (ctx) => {
75
+ const { selection } = ctx.editor?.state || {};
76
+
77
+ let currentNode;
78
+
79
+ if (selection instanceof NodeSelection) {
80
+ currentNode = selection.node; // the selected node
81
+ }
82
+
83
+ const hideDefaultToolbar =
84
+ ctx.editor?.isActive('math') ||
85
+ ctx.editor?.isActive('explicit_constructed_response') ||
86
+ ctx.editor?.isActive('imageUploadNode');
87
+
88
+ return {
89
+ currentNode,
90
+ hideDefaultToolbar,
91
+ isFocused: ctx.editor?.isFocused,
92
+ isBold: ctx.editor.isActive('bold') ?? false,
93
+ canBold:
94
+ ctx.editor
95
+ .can()
96
+ .chain()
97
+ .toggleBold()
98
+ .run() ?? false,
99
+ isTable: ctx.editor.isActive('table') ?? false,
100
+ tableHasBorder: ctx.editor.getAttributes('table')?.border === '1' ?? false,
101
+ canTable:
102
+ ctx.editor
103
+ .can()
104
+ .chain()
105
+ .insertTable()
106
+ .run() ?? false,
107
+ isItalic: ctx.editor.isActive('italic') ?? false,
108
+ canItalic:
109
+ ctx.editor
110
+ .can()
111
+ .chain()
112
+ .toggleItalic()
113
+ .run() ?? false,
114
+ isStrike: ctx.editor.isActive('strike') ?? false,
115
+ canStrike:
116
+ ctx.editor
117
+ .can()
118
+ .chain()
119
+ .toggleStrike()
120
+ .run() ?? false,
121
+ isCode: ctx.editor.isActive('code') ?? false,
122
+ canCode:
123
+ ctx.editor
124
+ .can()
125
+ .chain()
126
+ .toggleCode()
127
+ .run() ?? false,
128
+ canClearMarks:
129
+ ctx.editor
130
+ .can()
131
+ .chain()
132
+ .unsetAllMarks()
133
+ .run() ?? false,
134
+ isUnderline: ctx.editor.isActive('underline') ?? false,
135
+ isSubScript: ctx.editor.isActive('subscript') ?? false,
136
+ isSuperScript: ctx.editor.isActive('superscript') ?? false,
137
+ isParagraph: ctx.editor.isActive('paragraph') ?? false,
138
+ isHeading1: ctx.editor.isActive('heading', { level: 1 }) ?? false,
139
+ isHeading2: ctx.editor.isActive('heading', { level: 2 }) ?? false,
140
+ isHeading3: ctx.editor.isActive('heading', { level: 3 }) ?? false,
141
+ isHeading4: ctx.editor.isActive('heading', { level: 4 }) ?? false,
142
+ isHeading5: ctx.editor.isActive('heading', { level: 5 }) ?? false,
143
+ isHeading6: ctx.editor.isActive('heading', { level: 6 }) ?? false,
144
+ isBulletList: ctx.editor.isActive('bulletList') ?? false,
145
+ isOrderedList: ctx.editor.isActive('orderedList') ?? false,
146
+ isCodeBlock: ctx.editor.isActive('codeBlock') ?? false,
147
+ isBlockquote: ctx.editor.isActive('blockquote') ?? false,
148
+ canUndo:
149
+ ctx.editor
150
+ .can()
151
+ .chain()
152
+ .undo()
153
+ .run() ?? false,
154
+ canRedo:
155
+ ctx.editor
156
+ .can()
157
+ .chain()
158
+ .redo()
159
+ .run() ?? false,
160
+ };
161
+ },
162
+ });
163
+
164
+ const hasDoneButton = false;
165
+ const autoWidth = false;
166
+
167
+ const names = classNames(classes.toolbar, PIE_TOOLBAR__CLASS, {
168
+ [classes.toolbarWithNoDone]: !hasDoneButton,
169
+ [classes.toolbarTop]: toolbarOpts.position === 'top',
170
+ [classes.toolbarRight]: toolbarOpts.alignment === 'right',
171
+ [classes.focused]: toolbarOpts.alwaysVisible || (editorState.isFocused && !editor._toolbarOpened),
172
+ [classes.autoWidth]: autoWidth,
173
+ [classes.fullWidth]: !autoWidth,
174
+ [classes.hidden]: toolbarOpts.isHidden === true,
175
+ });
176
+
177
+ const customStyles = toolbarOpts.minWidth !== undefined ? { minWidth: toolbarOpts.minWidth } : {};
178
+
179
+ const handleMouseDown = (e) => {
180
+ e.preventDefault();
181
+ };
182
+
183
+ const toolbarButtons = useMemo(
184
+ () => [
185
+ {
186
+ icon: <GridOn />,
187
+ onClick: (editor) =>
188
+ editor
189
+ .chain()
190
+ .focus()
191
+ .insertTable({ rows: 2, cols: 2, withHeaderRow: false })
192
+ .run(),
193
+ hidden: (state) => !activePlugins?.includes('table') || state.isTable,
194
+ isActive: (state) => state.isTable,
195
+ isDisabled: (state) => !state.canTable,
196
+ },
197
+ {
198
+ icon: <AddRow />,
199
+ onClick: (editor) =>
200
+ editor
201
+ .chain()
202
+ .focus()
203
+ .addRowAfter()
204
+ .run(),
205
+ hidden: (state) => !state.isTable,
206
+ isActive: (state) => state.isTable,
207
+ isDisabled: (state) => !state.canTable,
208
+ },
209
+ {
210
+ icon: <RemoveRow />,
211
+ onClick: (editor) =>
212
+ editor
213
+ .chain()
214
+ .focus()
215
+ .deleteRow()
216
+ .run(),
217
+ hidden: (state) => !state.isTable,
218
+ isActive: (state) => state.isTable,
219
+ isDisabled: (state) => !state.canTable,
220
+ },
221
+ {
222
+ icon: <AddColumn />,
223
+ onClick: (editor) =>
224
+ editor
225
+ .chain()
226
+ .focus()
227
+ .addColumnAfter()
228
+ .run(),
229
+ hidden: (state) => !state.isTable,
230
+ isActive: (state) => state.isTable,
231
+ isDisabled: (state) => !state.canTable,
232
+ },
233
+ {
234
+ icon: <RemoveColumn />,
235
+ onClick: (editor) =>
236
+ editor
237
+ .chain()
238
+ .focus()
239
+ .deleteColumn()
240
+ .run(),
241
+ hidden: (state) => !state.isTable,
242
+ isActive: (state) => state.isTable,
243
+ isDisabled: (state) => !state.canTable,
244
+ },
245
+ {
246
+ icon: <RemoveTable />,
247
+ onClick: (editor) =>
248
+ editor
249
+ .chain()
250
+ .focus()
251
+ .deleteTable()
252
+ .run(),
253
+ hidden: (state) => !state.isTable,
254
+ isActive: (state) => state.isTable,
255
+ isDisabled: (state) => !state.canTable,
256
+ },
257
+ {
258
+ icon: <BorderAll />,
259
+ onClick: (editor) => {
260
+ const tableAttrs = editor.getAttributes('table');
261
+
262
+ const update = {
263
+ ...tableAttrs,
264
+ border: tableAttrs.border !== '0' ? '0' : '1',
265
+ };
266
+
267
+ editor.commands.updateAttributes('table', update);
268
+ },
269
+ hidden: (state) => !state.isTable,
270
+ isActive: (state) => state.tableHasBorder,
271
+ isDisabled: (state) => !state.canTable,
272
+ },
273
+ {
274
+ icon: <Bold />,
275
+ onClick: (editor) =>
276
+ editor
277
+ .chain()
278
+ .focus()
279
+ .toggleBold()
280
+ .run(),
281
+ hidden: (state) => !activePlugins?.includes('bold') || state.isTable,
282
+ isActive: (state) => state.isBold,
283
+ isDisabled: (state) => !state.canBold,
284
+ },
285
+ {
286
+ icon: <Italic />,
287
+ onClick: (editor) =>
288
+ editor
289
+ .chain()
290
+ .focus()
291
+ .toggleItalic()
292
+ .run(),
293
+ hidden: (state) => !activePlugins?.includes('italic') || state.isTable,
294
+ isActive: (state) => state.isItalic,
295
+ isDisabled: (state) => !state.canItalic,
296
+ },
297
+ {
298
+ icon: <Strikethrough />,
299
+ onClick: (editor) =>
300
+ editor
301
+ .chain()
302
+ .focus()
303
+ .toggleStrike()
304
+ .run(),
305
+ hidden: (state) => !activePlugins?.includes('strikethrough') || state.isTable,
306
+ isActive: (state) => state.isStrike,
307
+ isDisabled: (state) => !state.canStrike,
308
+ },
309
+ {
310
+ icon: <Code />,
311
+ onClick: (editor) =>
312
+ editor
313
+ .chain()
314
+ .focus()
315
+ .toggleCode()
316
+ .run(),
317
+ hidden: (state) => !activePlugins?.includes('code') || state.isTable,
318
+ isActive: (state) => state.isCode,
319
+ isDisabled: (state) => !state.canCode,
320
+ },
321
+ {
322
+ icon: <Underline />,
323
+ onClick: (editor) =>
324
+ editor
325
+ .chain()
326
+ .focus()
327
+ .toggleUnderline()
328
+ .run(),
329
+ hidden: (state) => !activePlugins?.includes('underline') || state.isTable,
330
+ isActive: (state) => state.isUnderline,
331
+ },
332
+ {
333
+ icon: <SubscriptIcon />,
334
+ onClick: (editor) =>
335
+ editor
336
+ .chain()
337
+ .focus()
338
+ .toggleSubscript()
339
+ .run(),
340
+ hidden: (state) => !activePlugins?.includes('subscript') || state.isTable,
341
+ isActive: (state) => state.isSubScript,
342
+ },
343
+ {
344
+ icon: <SuperscriptIcon />,
345
+ onClick: (editor) =>
346
+ editor
347
+ .chain()
348
+ .focus()
349
+ .toggleSuperscript()
350
+ .run(),
351
+ hidden: (state) => !activePlugins?.includes('superscript') || state.isTable,
352
+ isActive: (state) => state.isSuperScript,
353
+ },
354
+ {
355
+ icon: <ImageIcon />,
356
+ hidden: (state) => !activePlugins?.includes('image') || state.isTable,
357
+ onClick: (editor) =>
358
+ editor
359
+ .chain()
360
+ .focus()
361
+ .setImageUploadNode()
362
+ .run(),
363
+ },
364
+ {
365
+ icon: <TheatersIcon />,
366
+ hidden: (state) => !activePlugins?.includes('video') || state.isTable,
367
+ onClick: (editor) =>
368
+ editor
369
+ .chain()
370
+ .focus()
371
+ .insertMedia({ type: 'video' })
372
+ .run(),
373
+ },
374
+ {
375
+ icon: <VolumeUpIcon />,
376
+ hidden: (state) => !activePlugins?.includes('audio') || state.isTable,
377
+ onClick: (editor) =>
378
+ editor
379
+ .chain()
380
+ .focus()
381
+ .insertMedia({ type: 'audio', tag: 'audio' })
382
+ .run(),
383
+ },
384
+ {
385
+ icon: <CSSIcon />,
386
+ hidden: (state) => !activePlugins?.includes('css') || state.isTable,
387
+ onClick: (editor) => editor.commands.openCSSClassDialog(),
388
+ },
389
+ {
390
+ icon: <HeadingIcon />,
391
+ hidden: (state) => !activePlugins?.includes('h3') || state.isTable,
392
+ onClick: (editor) =>
393
+ editor
394
+ .chain()
395
+ .focus()
396
+ .toggleHeading({ level: 3 })
397
+ .run(),
398
+ isActive: (state) => state.isHeading3,
399
+ },
400
+ {
401
+ icon: <Functions />,
402
+ hidden: () => !activePlugins?.includes('math'),
403
+ onClick: (editor) =>
404
+ editor
405
+ .chain()
406
+ .focus()
407
+ .insertMath('')
408
+ .run(),
409
+ },
410
+ {
411
+ icon: <CharacterIcon letter="ñ" />,
412
+ hidden: (state) => !activePlugins?.includes('languageCharacters') || state.isTable,
413
+ onClick: () => setShowPicker(spanishConfig),
414
+ },
415
+ {
416
+ icon: <CharacterIcon letter="€" />,
417
+ hidden: (state) => activePlugins?.filter((p) => p === 'languageCharacters').length !== 2 || state.isTable,
418
+ onClick: () => setShowPicker(specialConfig),
419
+ },
420
+ {
421
+ icon: <TextAlignIcon editor={editor} />,
422
+ hidden: (state) => !activePlugins?.includes('text-align') || state.isTable,
423
+ onClick: () => {},
424
+ },
425
+ {
426
+ icon: <BulletedListIcon />,
427
+ hidden: (state) => !activePlugins?.includes('bulleted-list') || state.isTable,
428
+ onClick: (editor) =>
429
+ editor
430
+ .chain()
431
+ .focus()
432
+ .toggleBulletList()
433
+ .run(),
434
+ isActive: (state) => state.isBulletList,
435
+ },
436
+ {
437
+ icon: <NumberedListIcon />,
438
+ hidden: (state) => !activePlugins?.includes('numbered-list') || state.isTable,
439
+ onClick: (editor) =>
440
+ editor
441
+ .chain()
442
+ .focus()
443
+ .toggleOrderedList()
444
+ .run(),
445
+ isActive: (state) => state.isOrderedList,
446
+ },
447
+ {
448
+ icon: <Undo />,
449
+ hidden: (state) => !activePlugins?.includes('undo') || state.isTable,
450
+ onClick: (editor) =>
451
+ editor
452
+ .chain()
453
+ .focus()
454
+ .undo()
455
+ .run(),
456
+ isDisabled: (state) => !state.canUndo,
457
+ },
458
+ {
459
+ icon: <Redo />,
460
+ hidden: (state) => !activePlugins?.includes('redo') || state.isTable,
461
+ onClick: (editor) =>
462
+ editor
463
+ .chain()
464
+ .focus()
465
+ .redo()
466
+ .run(),
467
+ isDisabled: (state) => !state.canRedo,
468
+ },
469
+ ],
470
+ [activePlugins, editor],
471
+ );
472
+
473
+ return (
474
+ <div className={names} style={{ ...customStyles }} onMouseDown={handleMouseDown}>
475
+ {!editorState.hideDefaultToolbar && (
476
+ <div className={classes.defaultToolbar} tabIndex="1">
477
+ <div className={classes.buttonsContainer}>
478
+ {toolbarButtons
479
+ .filter((btn) => !btn.hidden?.(editorState))
480
+ .map((btn, index) => {
481
+ const disabled = btn.isDisabled?.(editorState);
482
+ const active = btn.isActive?.(editorState);
483
+
484
+ return (
485
+ <button
486
+ key={index}
487
+ disabled={disabled}
488
+ onClick={(e) => {
489
+ e.preventDefault();
490
+ btn.onClick(editor);
491
+ }}
492
+ className={classNames(classes.button, { [classes.active]: active })}
493
+ >
494
+ {btn.icon}
495
+ </button>
496
+ );
497
+ })}
498
+ </div>
499
+ {activePlugins?.includes('responseArea') && (
500
+ <button
501
+ onClick={() => {
502
+ editor
503
+ .chain()
504
+ .focus()
505
+ .insertResponseArea(responseAreaProps.type)
506
+ .run();
507
+ }}
508
+ className={classes.button}
509
+ >
510
+ <ToolbarIcon />
511
+ </button>
512
+ )}
513
+
514
+ <DoneButton
515
+ onClick={() => {
516
+ onChange?.(editor.getHTML());
517
+ editor.commands.blur();
518
+ }}
519
+ />
520
+ </div>
521
+ )}
522
+ {showPicker && (
523
+ <CharacterPicker
524
+ editor={editor}
525
+ opts={{
526
+ ...showPicker,
527
+ renderPopOver: (ev, ch) => console.log('Show popover', ch),
528
+ closePopOver: () => console.log('Close popover'),
529
+ }}
530
+ onClose={() => setShowPicker(false)}
531
+ />
532
+ )}
533
+ </div>
534
+ );
535
+ }
536
+
537
+ const style = (theme) => ({
538
+ defaultToolbar: {
539
+ display: 'flex',
540
+ width: '100%',
541
+ justifyContent: 'space-between',
542
+ },
543
+ buttonsContainer: {
544
+ alignItems: 'center',
545
+ display: 'flex',
546
+ width: '100%',
547
+ },
548
+ button: {
549
+ color: 'grey',
550
+ display: 'inline-flex',
551
+ padding: '2px',
552
+ background: 'none',
553
+ border: 'none',
554
+ cursor: 'pointer',
555
+ '&:hover': {
556
+ color: 'black',
557
+ },
558
+ '&:focus': {
559
+ outline: `2px solid ${theme.palette.grey[700]}`,
560
+ },
561
+ },
562
+ active: {
563
+ color: 'black',
564
+ },
565
+ disabled: {
566
+ opacity: 0.7,
567
+ cursor: 'not-allowed',
568
+ '& :hover': {
569
+ color: 'grey',
570
+ },
571
+ },
572
+ isActive: {
573
+ background: 'var(--purple)',
574
+ color: 'var(--white)',
575
+ },
576
+ toolbar: {
577
+ position: 'absolute',
578
+ zIndex: 20,
579
+ cursor: 'pointer',
580
+ justifyContent: 'space-between',
581
+ background: 'var(--editable-html-toolbar-bg, #efefef)',
582
+ minWidth: '280px',
583
+ margin: '5px 0 0 0',
584
+ padding: '2px',
585
+ boxShadow:
586
+ '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)',
587
+ boxSizing: 'border-box',
588
+ display: 'flex',
589
+ opacity: 0,
590
+ pointerEvents: 'none',
591
+ },
592
+ toolbarWithNoDone: {
593
+ minWidth: '265px',
594
+ },
595
+ toolbarTop: {
596
+ top: '-45px',
597
+ },
598
+ toolbarRight: {
599
+ right: 0,
600
+ },
601
+ fullWidth: {
602
+ width: '100%',
603
+ },
604
+ hidden: {
605
+ visibility: 'hidden',
606
+ },
607
+ autoWidth: {
608
+ width: 'auto',
609
+ },
610
+ focused: {
611
+ opacity: 1,
612
+ pointerEvents: 'auto',
613
+ },
614
+ iconRoot: {
615
+ width: '28px',
616
+ height: '28px',
617
+ padding: '4px',
618
+ verticalAlign: 'top',
619
+ },
620
+ label: {
621
+ color: 'var(--editable-html-toolbar-check, #00bb00)',
622
+ },
623
+ shared: {
624
+ display: 'flex',
625
+ },
626
+ });
627
+
628
+ const StyledMenuBar = withStyles(style, { index: 1000 })(MenuBar);
629
+
630
+ export default StyledMenuBar;