@pie-lib/editable-html-tip-tap 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/dist/components/CharacterPicker.d.ts +31 -0
  2. package/dist/components/CharacterPicker.d.ts.map +1 -0
  3. package/dist/components/CharacterPicker.js +129 -0
  4. package/dist/components/EditableHtml.d.ts +11 -0
  5. package/dist/components/EditableHtml.d.ts.map +1 -0
  6. package/dist/components/EditableHtml.js +270 -0
  7. package/dist/components/MenuBar.d.ts +11 -0
  8. package/dist/components/MenuBar.d.ts.map +1 -0
  9. package/dist/components/MenuBar.js +460 -0
  10. package/dist/components/TiptapContainer.d.ts +11 -0
  11. package/dist/components/TiptapContainer.d.ts.map +1 -0
  12. package/dist/components/TiptapContainer.js +157 -0
  13. package/dist/components/characters/characterUtils.d.ts +36 -0
  14. package/dist/components/characters/characterUtils.d.ts.map +1 -0
  15. package/dist/components/characters/characterUtils.js +465 -0
  16. package/dist/components/characters/custom-popper.d.ts +14 -0
  17. package/dist/components/characters/custom-popper.d.ts.map +1 -0
  18. package/dist/components/characters/custom-popper.js +32 -0
  19. package/dist/components/common/done-button.d.ts +30 -0
  20. package/dist/components/common/done-button.d.ts.map +1 -0
  21. package/dist/components/common/done-button.js +26 -0
  22. package/dist/components/common/toolbar-buttons.d.ts +39 -0
  23. package/dist/components/common/toolbar-buttons.d.ts.map +1 -0
  24. package/dist/components/common/toolbar-buttons.js +91 -0
  25. package/dist/components/icons/CssIcon.d.ts +11 -0
  26. package/dist/components/icons/CssIcon.d.ts.map +1 -0
  27. package/dist/components/icons/CssIcon.js +14 -0
  28. package/dist/components/icons/RespArea.d.ts +26 -0
  29. package/dist/components/icons/RespArea.d.ts.map +1 -0
  30. package/dist/components/icons/RespArea.js +42 -0
  31. package/dist/components/icons/TableIcons.d.ts +14 -0
  32. package/dist/components/icons/TableIcons.d.ts.map +1 -0
  33. package/dist/components/icons/TableIcons.js +32 -0
  34. package/dist/components/icons/TextAlign.d.ts +18 -0
  35. package/dist/components/icons/TextAlign.d.ts.map +1 -0
  36. package/dist/components/icons/TextAlign.js +134 -0
  37. package/dist/components/image/AltDialog.d.ts +23 -0
  38. package/dist/components/image/AltDialog.d.ts.map +1 -0
  39. package/dist/components/image/AltDialog.js +61 -0
  40. package/dist/components/image/ImageToolbar.d.ts +25 -0
  41. package/dist/components/image/ImageToolbar.d.ts.map +1 -0
  42. package/dist/components/image/ImageToolbar.js +80 -0
  43. package/dist/components/image/InsertImageHandler.d.ts +33 -0
  44. package/dist/components/image/InsertImageHandler.d.ts.map +1 -0
  45. package/dist/components/image/InsertImageHandler.js +55 -0
  46. package/dist/components/media/MediaDialog.d.ts +44 -0
  47. package/dist/components/media/MediaDialog.d.ts.map +1 -0
  48. package/dist/components/media/MediaDialog.js +389 -0
  49. package/dist/components/media/MediaToolbar.d.ts +20 -0
  50. package/dist/components/media/MediaToolbar.d.ts.map +1 -0
  51. package/dist/components/media/MediaToolbar.js +41 -0
  52. package/dist/components/media/MediaWrapper.d.ts +20 -0
  53. package/dist/components/media/MediaWrapper.d.ts.map +1 -0
  54. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts +23 -0
  55. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts.map +1 -0
  56. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +58 -0
  57. package/dist/components/respArea/DragInTheBlank/choice.d.ts +56 -0
  58. package/dist/components/respArea/DragInTheBlank/choice.d.ts.map +1 -0
  59. package/dist/components/respArea/DragInTheBlank/choice.js +156 -0
  60. package/dist/components/respArea/ExplicitConstructedResponse.d.ts +20 -0
  61. package/dist/components/respArea/ExplicitConstructedResponse.d.ts.map +1 -0
  62. package/dist/components/respArea/ExplicitConstructedResponse.js +67 -0
  63. package/dist/components/respArea/InlineDropdown.d.ts +18 -0
  64. package/dist/components/respArea/InlineDropdown.d.ts.map +1 -0
  65. package/dist/components/respArea/InlineDropdown.js +91 -0
  66. package/dist/components/respArea/MathTemplated.d.ts +19 -0
  67. package/dist/components/respArea/MathTemplated.d.ts.map +1 -0
  68. package/dist/components/respArea/MathTemplated.js +97 -0
  69. package/dist/components/respArea/ToolbarIcon.d.ts +14 -0
  70. package/dist/components/respArea/ToolbarIcon.d.ts.map +1 -0
  71. package/dist/components/respArea/ToolbarIcon.js +17 -0
  72. package/dist/constants.d.ts +14 -0
  73. package/dist/constants.d.ts.map +1 -0
  74. package/dist/constants.js +4 -0
  75. package/dist/extensions/css.d.ts +12 -0
  76. package/dist/extensions/css.d.ts.map +1 -0
  77. package/dist/extensions/css.js +115 -0
  78. package/dist/extensions/custom-toolbar-wrapper.d.ts +11 -0
  79. package/dist/extensions/custom-toolbar-wrapper.d.ts.map +1 -0
  80. package/dist/extensions/custom-toolbar-wrapper.js +58 -0
  81. package/dist/extensions/div-node.d.ts +11 -0
  82. package/dist/extensions/div-node.d.ts.map +1 -0
  83. package/dist/extensions/div-node.js +25 -0
  84. package/dist/extensions/extended-table.d.ts +11 -0
  85. package/dist/extensions/extended-table.d.ts.map +1 -0
  86. package/dist/extensions/extended-table.js +15 -0
  87. package/dist/extensions/image-component.d.ts +22 -0
  88. package/dist/extensions/image-component.d.ts.map +1 -0
  89. package/dist/extensions/image-component.js +200 -0
  90. package/dist/extensions/image.d.ts +11 -0
  91. package/dist/extensions/image.d.ts.map +1 -0
  92. package/dist/extensions/image.js +42 -0
  93. package/dist/extensions/index.d.ts +17 -0
  94. package/dist/extensions/index.d.ts.map +1 -0
  95. package/dist/extensions/index.js +65 -0
  96. package/dist/extensions/math.d.ts +15 -0
  97. package/dist/extensions/math.d.ts.map +1 -0
  98. package/dist/extensions/math.js +150 -0
  99. package/dist/extensions/media.d.ts +19 -0
  100. package/dist/extensions/media.d.ts.map +1 -0
  101. package/dist/extensions/media.js +147 -0
  102. package/dist/extensions/responseArea.d.ts +28 -0
  103. package/dist/extensions/responseArea.d.ts.map +1 -0
  104. package/dist/extensions/responseArea.js +259 -0
  105. package/dist/index.d.ts +13 -0
  106. package/dist/index.d.ts.map +1 -0
  107. package/dist/index.js +6 -0
  108. package/dist/styles/editorContainerStyles.d.ts +135 -0
  109. package/dist/styles/editorContainerStyles.d.ts.map +1 -0
  110. package/dist/theme.d.ts +10 -0
  111. package/dist/theme.d.ts.map +1 -0
  112. package/dist/utils/helper.d.ts +10 -0
  113. package/dist/utils/helper.d.ts.map +1 -0
  114. package/dist/utils/helper.js +7 -0
  115. package/dist/utils/size.d.ts +10 -0
  116. package/dist/utils/size.d.ts.map +1 -0
  117. package/dist/utils/size.js +14 -0
  118. package/package.json +71 -0
  119. package/src/components/CharacterPicker.tsx +210 -0
  120. package/src/components/EditableHtml.tsx +416 -0
  121. package/src/components/MenuBar.tsx +558 -0
  122. package/src/components/TiptapContainer.tsx +228 -0
  123. package/src/components/characters/characterUtils.ts +457 -0
  124. package/src/components/characters/custom-popper.tsx +48 -0
  125. package/src/components/common/done-button.tsx +37 -0
  126. package/src/components/common/toolbar-buttons.tsx +132 -0
  127. package/src/components/icons/CssIcon.tsx +25 -0
  128. package/src/components/icons/RespArea.tsx +81 -0
  129. package/src/components/icons/TableIcons.tsx +62 -0
  130. package/src/components/icons/TextAlign.tsx +124 -0
  131. package/src/components/image/AltDialog.tsx +92 -0
  132. package/src/components/image/ImageToolbar.tsx +109 -0
  133. package/src/components/image/InsertImageHandler.ts +121 -0
  134. package/src/components/media/MediaDialog.tsx +606 -0
  135. package/src/components/media/MediaToolbar.tsx +59 -0
  136. package/src/components/media/MediaWrapper.tsx +49 -0
  137. package/src/components/respArea/DragInTheBlank/DragInTheBlank.tsx +86 -0
  138. package/src/components/respArea/DragInTheBlank/choice.tsx +266 -0
  139. package/src/components/respArea/ExplicitConstructedResponse.tsx +122 -0
  140. package/src/components/respArea/InlineDropdown.tsx +152 -0
  141. package/src/components/respArea/MathTemplated.tsx +134 -0
  142. package/src/components/respArea/ToolbarIcon.tsx +76 -0
  143. package/src/constants.ts +15 -0
  144. package/src/extensions/css.tsx +230 -0
  145. package/src/extensions/custom-toolbar-wrapper.tsx +88 -0
  146. package/src/extensions/div-node.tsx +46 -0
  147. package/src/extensions/extended-table.ts +34 -0
  148. package/src/extensions/image-component.tsx +303 -0
  149. package/src/extensions/image.tsx +64 -0
  150. package/src/extensions/index.tsx +91 -0
  151. package/src/extensions/math.tsx +285 -0
  152. package/src/extensions/media.tsx +198 -0
  153. package/src/extensions/responseArea.tsx +404 -0
  154. package/src/index.tsx +15 -0
  155. package/src/styles/editorContainerStyles.ts +155 -0
  156. package/src/theme.ts +11 -0
  157. package/src/utils/helper.tsx +27 -0
  158. package/src/utils/size.ts +42 -0
@@ -0,0 +1,558 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/components/MenuBar.jsx
4
+ * @auto-generated
5
+ *
6
+ * This file is automatically synced from pie-elements and converted to TypeScript.
7
+ * Manual edits will be overwritten on next sync.
8
+ * To make changes, edit the upstream JavaScript file and run sync again.
9
+ */
10
+
11
+ import React, { useMemo, useState } from 'react';
12
+ import classNames from 'classnames';
13
+ import { styled, useTheme } from '@mui/material/styles';
14
+ import { NodeSelection } from 'prosemirror-state';
15
+
16
+ import Bold from '@mui/icons-material/FormatBold';
17
+ import Italic from '@mui/icons-material/FormatItalic';
18
+ import Strikethrough from '@mui/icons-material/FormatStrikethrough';
19
+ import Code from '@mui/icons-material/Code';
20
+ import GridOn from '@mui/icons-material/GridOn';
21
+ import BulletedListIcon from '@mui/icons-material/FormatListBulleted';
22
+ import NumberedListIcon from '@mui/icons-material/FormatListNumbered';
23
+ import Underline from '@mui/icons-material/FormatUnderlined';
24
+ import Functions from '@mui/icons-material/Functions';
25
+ import ImageIcon from '@mui/icons-material/Image';
26
+ import Redo from '@mui/icons-material/Redo';
27
+ import Undo from '@mui/icons-material/Undo';
28
+ import FormatQuote from '@mui/icons-material/FormatQuote';
29
+ import TheatersIcon from '@mui/icons-material/Theaters';
30
+ import VolumeUpIcon from '@mui/icons-material/VolumeUp';
31
+ import BorderAll from '@mui/icons-material/BorderAll';
32
+ import Delete from '@mui/icons-material/Delete';
33
+
34
+ import { useEditorState } from '@tiptap/react';
35
+
36
+ import { PIE_TOOLBAR__CLASS } from '../constants.js';
37
+ import { ToolbarIcon } from './respArea/ToolbarIcon.js';
38
+ import { spanishConfig, specialConfig } from './characters/characterUtils.js';
39
+ import TextAlignIcon from './icons/TextAlign.js';
40
+ import CSSIcon from './icons/CssIcon.js';
41
+ import { AddColumn, AddRow, RemoveColumn, RemoveRow, RemoveTable } from './icons/TableIcons.js';
42
+
43
+ import { CharacterIcon, CharacterPicker } from './CharacterPicker.js';
44
+ import { DoneButton } from './common/done-button.js';
45
+
46
+ const SuperscriptIcon = () => (
47
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="none">
48
+ <path
49
+ 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"
50
+ fill="currentColor"
51
+ />
52
+ </svg>
53
+ );
54
+
55
+ const SubscriptIcon = () => (
56
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="none">
57
+ <path
58
+ 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"
59
+ fill="currentColor"
60
+ />
61
+ </svg>
62
+ );
63
+
64
+ const HeadingIcon = () => (
65
+ <svg
66
+ width="30"
67
+ height="28"
68
+ viewBox="0 0 30 28"
69
+ fill="none"
70
+ xmlns="http://www.w3.org/2000/svg"
71
+ style={{ width: '20px', height: '18px' }}
72
+ >
73
+ <path
74
+ 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"
75
+ fill="currentColor"
76
+ />
77
+ </svg>
78
+ );
79
+
80
+ function MenuBar({
81
+ editor,
82
+ classes,
83
+ activePlugins,
84
+ toolbarOpts: toolOpts,
85
+ responseAreaProps,
86
+ onChange,
87
+ autoWidthToolbar,
88
+ }) {
89
+ const [showPicker, setShowPicker] = useState(false);
90
+ const toolbarOpts = toolOpts ?? {};
91
+
92
+ const editorState = useEditorState({
93
+ editor,
94
+ selector: (ctx) => {
95
+ const { selection } = ctx.editor?.state || {};
96
+
97
+ let currentNode;
98
+
99
+ if (selection instanceof NodeSelection) {
100
+ currentNode = selection.node; // the selected node
101
+ }
102
+
103
+ const hideDefaultToolbar =
104
+ ctx.editor?.isActive('math') ||
105
+ ctx.editor?.isActive('explicit_constructed_response') ||
106
+ ctx.editor?.isActive('imageUploadNode') ||
107
+ ctx.editor?.isActive('drag_in_the_blank');
108
+
109
+ const hasTextSelectionInTable = selection && selection.empty === false && ctx.editor.isActive('table');
110
+
111
+ return {
112
+ currentNode,
113
+ hideDefaultToolbar,
114
+ hasTextSelectionInTable,
115
+ isFocused: ctx.editor?.isFocused,
116
+ isBold: ctx.editor.isActive('bold') ?? false,
117
+ canBold: ctx.editor.can().chain().toggleBold().run() ?? false,
118
+ isTable: ctx.editor.isActive('table') ?? false,
119
+ tableHasBorder: ctx.editor.getAttributes('table')?.border === '1' ?? false,
120
+ canTable: ctx.editor.can().chain().insertTable().run() ?? false,
121
+ isItalic: ctx.editor.isActive('italic') ?? false,
122
+ canItalic: ctx.editor.can().chain().toggleItalic().run() ?? false,
123
+ isStrike: ctx.editor.isActive('strike') ?? false,
124
+ canStrike: ctx.editor.can().chain().toggleStrike().run() ?? false,
125
+ isCode: ctx.editor.isActive('code') ?? false,
126
+ canCode: ctx.editor.can().chain().toggleCode().run() ?? false,
127
+ canClearMarks: ctx.editor.can().chain().unsetAllMarks().run() ?? false,
128
+ isUnderline: ctx.editor.isActive('underline') ?? false,
129
+ isSubScript: ctx.editor.isActive('subscript') ?? false,
130
+ isSuperScript: ctx.editor.isActive('superscript') ?? false,
131
+ isParagraph: ctx.editor.isActive('paragraph') ?? false,
132
+ isHeading1: ctx.editor.isActive('heading', { level: 1 }) ?? false,
133
+ isHeading2: ctx.editor.isActive('heading', { level: 2 }) ?? false,
134
+ isHeading3: ctx.editor.isActive('heading', { level: 3 }) ?? false,
135
+ isHeading4: ctx.editor.isActive('heading', { level: 4 }) ?? false,
136
+ isHeading5: ctx.editor.isActive('heading', { level: 5 }) ?? false,
137
+ isHeading6: ctx.editor.isActive('heading', { level: 6 }) ?? false,
138
+ isBulletList: ctx.editor.isActive('bulletList') ?? false,
139
+ isOrderedList: ctx.editor.isActive('orderedList') ?? false,
140
+ isCodeBlock: ctx.editor.isActive('codeBlock') ?? false,
141
+ isBlockquote: ctx.editor.isActive('blockquote') ?? false,
142
+ canUndo: ctx.editor.can().chain().undo().run() ?? false,
143
+ canRedo: ctx.editor.can().chain().redo().run() ?? false,
144
+ };
145
+ },
146
+ });
147
+
148
+ const hasDoneButton = false;
149
+ const autoWidth = !!autoWidthToolbar;
150
+
151
+ const names = classNames(classes.toolbar, PIE_TOOLBAR__CLASS, {
152
+ [classes.toolbarWithNoDone]: !hasDoneButton,
153
+ [classes.toolbarTop]: toolbarOpts.position === 'top',
154
+ [classes.toolbarRight]: toolbarOpts.alignment === 'right',
155
+ [classes.focused]: toolbarOpts.alwaysVisible || (editorState.isFocused && !editor._toolbarOpened),
156
+ [classes.autoWidth]: autoWidth,
157
+ [classes.fullWidth]: !autoWidth,
158
+ [classes.hidden]: toolbarOpts.isHidden === true,
159
+ });
160
+
161
+ const customStyles = toolbarOpts.minWidth !== undefined ? { minWidth: toolbarOpts.minWidth } : {};
162
+
163
+ const handleMouseDown = (e) => {
164
+ e.preventDefault();
165
+ };
166
+
167
+ const toolbarButtons = useMemo(
168
+ () => [
169
+ {
170
+ icon: <GridOn />,
171
+ onClick: (editor) => editor.chain().focus().insertTable({ rows: 2, cols: 2, withHeaderRow: false }).run(),
172
+ hidden: (state) => !activePlugins?.includes('table') || state.isTable,
173
+ isActive: (state) => state.isTable,
174
+ isDisabled: (state) => !state.canTable,
175
+ },
176
+ {
177
+ icon: <AddRow />,
178
+ onClick: (editor) => editor.chain().focus().addRowAfter().run(),
179
+ hidden: (state) => !(state.isTable && !state.hasTextSelectionInTable),
180
+ isActive: (state) => state.isTable,
181
+ isDisabled: (state) => !state.canTable,
182
+ },
183
+ {
184
+ icon: <RemoveRow />,
185
+ onClick: (editor) => editor.chain().focus().deleteRow().run(),
186
+ hidden: (state) => !(state.isTable && !state.hasTextSelectionInTable),
187
+ isActive: (state) => state.isTable,
188
+ isDisabled: (state) => !state.canTable,
189
+ },
190
+ {
191
+ icon: <AddColumn />,
192
+ onClick: (editor) => editor.chain().focus().addColumnAfter().run(),
193
+ hidden: (state) => !(state.isTable && !state.hasTextSelectionInTable),
194
+ isActive: (state) => state.isTable,
195
+ isDisabled: (state) => !state.canTable,
196
+ },
197
+ {
198
+ icon: <RemoveColumn />,
199
+ onClick: (editor) => editor.chain().focus().deleteColumn().run(),
200
+ hidden: (state) => !(state.isTable && !state.hasTextSelectionInTable),
201
+ isActive: (state) => state.isTable,
202
+ isDisabled: (state) => !state.canTable,
203
+ },
204
+ {
205
+ icon: <RemoveTable />,
206
+ onClick: (editor) => editor.chain().focus().deleteTable().run(),
207
+ hidden: (state) => !(state.isTable && !state.hasTextSelectionInTable),
208
+ isActive: (state) => state.isTable,
209
+ isDisabled: (state) => !state.canTable,
210
+ },
211
+ {
212
+ icon: <BorderAll />,
213
+ onClick: (editor) => {
214
+ const tableAttrs = editor.getAttributes('table');
215
+
216
+ const update = {
217
+ ...tableAttrs,
218
+ border: tableAttrs.border !== '0' ? '0' : '1',
219
+ };
220
+
221
+ editor.commands.updateAttributes('table', update);
222
+ },
223
+ hidden: (state) => !(state.isTable && !state.hasTextSelectionInTable),
224
+ isActive: (state) => state.tableHasBorder,
225
+ isDisabled: (state) => !state.canTable,
226
+ },
227
+ {
228
+ icon: <Bold />,
229
+ onClick: (editor) => editor.chain().focus().toggleBold().run(),
230
+ hidden: () => !activePlugins?.includes('bold'),
231
+ isActive: (state) => state.isBold,
232
+ isDisabled: (state) => !state.canBold,
233
+ },
234
+ {
235
+ icon: <Italic />,
236
+ onClick: (editor) => editor.chain().focus().toggleItalic().run(),
237
+ hidden: () => !activePlugins?.includes('italic'),
238
+ isActive: (state) => state.isItalic,
239
+ isDisabled: (state) => !state.canItalic,
240
+ },
241
+ {
242
+ icon: <Strikethrough />,
243
+ onClick: (editor) => editor.chain().focus().toggleStrike().run(),
244
+ hidden: () => !activePlugins?.includes('strikethrough'),
245
+ isActive: (state) => state.isStrike,
246
+ isDisabled: (state) => !state.canStrike,
247
+ },
248
+ {
249
+ icon: <Code />,
250
+ onClick: (editor) => editor.chain().focus().toggleCode().run(),
251
+ hidden: () => !activePlugins?.includes('code'),
252
+ isActive: (state) => state.isCode,
253
+ isDisabled: (state) => !state.canCode,
254
+ },
255
+ {
256
+ icon: <Underline />,
257
+ onClick: (editor) => editor.chain().focus().toggleUnderline().run(),
258
+ hidden: () => !activePlugins?.includes('underline'),
259
+ isActive: (state) => state.isUnderline,
260
+ },
261
+ {
262
+ icon: <SubscriptIcon />,
263
+ onClick: (editor) => editor.chain().focus().toggleSubscript().run(),
264
+ hidden: () => !activePlugins?.includes('subscript'),
265
+ isActive: (state) => state.isSubScript,
266
+ },
267
+ {
268
+ icon: <SuperscriptIcon />,
269
+ onClick: (editor) => editor.chain().focus().toggleSuperscript().run(),
270
+ hidden: () => !activePlugins?.includes('superscript'),
271
+ isActive: (state) => state.isSuperScript,
272
+ },
273
+ {
274
+ icon: <ImageIcon />,
275
+ hidden: () => !activePlugins?.includes('image'),
276
+ onClick: (editor) => editor.chain().focus().setImageUploadNode().run(),
277
+ },
278
+ {
279
+ icon: <TheatersIcon />,
280
+ hidden: () => !activePlugins?.includes('video'),
281
+ onClick: (editor) => editor.chain().focus().insertMedia({ type: 'video' }).run(),
282
+ },
283
+ {
284
+ icon: <VolumeUpIcon />,
285
+ hidden: () => !activePlugins?.includes('audio'),
286
+ onClick: (editor) => editor.chain().focus().insertMedia({ type: 'audio', tag: 'audio' }).run(),
287
+ },
288
+ {
289
+ icon: <CSSIcon />,
290
+ hidden: () => !activePlugins?.includes('css'),
291
+ onClick: (editor) => editor.commands.openCSSClassDialog(),
292
+ },
293
+ {
294
+ icon: <FormatQuote />,
295
+ hidden: () => !activePlugins?.includes('blockquote'),
296
+ onClick: (editor) => editor.chain().focus().toggleBlockquote().run(),
297
+ isActive: (state) => state.isBlockquote,
298
+ },
299
+ {
300
+ icon: <HeadingIcon />,
301
+ hidden: () => !activePlugins?.includes('h3'),
302
+ onClick: (editor) => editor.chain().focus().toggleHeading({ level: 3 }).run(),
303
+ isActive: (state) => state.isHeading3,
304
+ },
305
+ {
306
+ icon: <Functions />,
307
+ hidden: () => !activePlugins?.includes('math'),
308
+ onClick: (editor) => editor.chain().focus().insertMath('').run(),
309
+ },
310
+ {
311
+ icon: <CharacterIcon letter="ñ" />,
312
+ hidden: () => !activePlugins?.includes('languageCharacters'),
313
+ onClick: () => setShowPicker(spanishConfig),
314
+ },
315
+ {
316
+ icon: <CharacterIcon letter="€" />,
317
+ hidden: () => activePlugins?.filter((p) => p === 'languageCharacters').length !== 2,
318
+ onClick: () => setShowPicker(specialConfig),
319
+ },
320
+ {
321
+ icon: <TextAlignIcon editor={editor} />,
322
+ hidden: () => !activePlugins?.includes('text-align'),
323
+ onClick: () => {},
324
+ },
325
+ {
326
+ icon: <BulletedListIcon />,
327
+ hidden: () => !activePlugins?.includes('bulleted-list'),
328
+ onClick: (editor) => editor.chain().focus().toggleBulletList().run(),
329
+ isActive: (state) => state.isBulletList,
330
+ },
331
+ {
332
+ icon: <NumberedListIcon />,
333
+ hidden: () => !activePlugins?.includes('numbered-list'),
334
+ onClick: (editor) => editor.chain().focus().toggleOrderedList().run(),
335
+ isActive: (state) => state.isOrderedList,
336
+ },
337
+ {
338
+ icon: <Undo />,
339
+ hidden: () => !activePlugins?.includes('undo'),
340
+ onClick: (editor) => editor.chain().focus().undo().run(),
341
+ isDisabled: (state) => !state.canUndo,
342
+ },
343
+ {
344
+ icon: <Redo />,
345
+ hidden: () => !activePlugins?.includes('redo'),
346
+ onClick: (editor) => editor.chain().focus().redo().run(),
347
+ isDisabled: (state) => !state.canRedo,
348
+ },
349
+ ],
350
+ [activePlugins, editor],
351
+ );
352
+
353
+ const isDragInTheBlankSelected =
354
+ editorState.hideDefaultToolbar && editorState.currentNode?.type?.name === 'drag_in_the_blank';
355
+
356
+ return (
357
+ <div className={names} style={{ ...customStyles }} onMouseDown={handleMouseDown}>
358
+ {isDragInTheBlankSelected && (
359
+ <div className={classes.defaultToolbar} tabIndex="1">
360
+ <div className={classes.buttonsContainer}>
361
+ <button
362
+ type="button"
363
+ className={classes.button}
364
+ onClick={(e) => {
365
+ e.preventDefault();
366
+ editor.chain().focus().deleteSelection().run();
367
+ onChange?.(editor.getHTML());
368
+ }}
369
+ aria-label="Delete response area"
370
+ >
371
+ <Delete />
372
+ </button>
373
+ </div>
374
+ </div>
375
+ )}
376
+ {!editorState.hideDefaultToolbar && (
377
+ <div className={classes.defaultToolbar} tabIndex="1">
378
+ <div className={classes.buttonsContainer}>
379
+ {toolbarButtons
380
+ .filter((btn) => !btn.hidden?.(editorState))
381
+ .map((btn, index) => {
382
+ const disabled = btn.isDisabled?.(editorState);
383
+ const active = btn.isActive?.(editorState);
384
+
385
+ return (
386
+ <button
387
+ key={index}
388
+ disabled={disabled}
389
+ onClick={(e) => {
390
+ e.preventDefault();
391
+ btn.onClick(editor);
392
+ }}
393
+ className={classNames(classes.button, { [classes.active]: active })}
394
+ >
395
+ {btn.icon}
396
+ </button>
397
+ );
398
+ })}
399
+ </div>
400
+ {activePlugins?.includes('responseArea') && (
401
+ <button
402
+ onClick={() => {
403
+ editor.chain().focus().insertResponseArea(responseAreaProps.type).run();
404
+ }}
405
+ className={classes.button}
406
+ >
407
+ <ToolbarIcon />
408
+ </button>
409
+ )}
410
+
411
+ {toolbarOpts.showDone && (
412
+ <DoneButton
413
+ onClick={() => {
414
+ onChange?.(editor.getHTML());
415
+ editor.commands.blur();
416
+ }}
417
+ />
418
+ )}
419
+ </div>
420
+ )}
421
+ {showPicker && (
422
+ <CharacterPicker
423
+ editor={editor}
424
+ opts={{
425
+ ...showPicker,
426
+ renderPopOver: (ev, ch) => console.log('Show popover', ch),
427
+ closePopOver: () => console.log('Close popover'),
428
+ }}
429
+ onClose={() => setShowPicker(false)}
430
+ />
431
+ )}
432
+ </div>
433
+ );
434
+ }
435
+
436
+ // Wrapper component that provides classes object using styled API
437
+ const StyledMenuBar = (props) => {
438
+ const theme = useTheme();
439
+
440
+ const classes = {
441
+ defaultToolbar: 'defaultToolbar',
442
+ buttonsContainer: 'buttonsContainer',
443
+ button: 'button',
444
+ active: 'active',
445
+ disabled: 'disabled',
446
+ isActive: 'isActive',
447
+ toolbar: 'toolbar',
448
+ toolbarWithNoDone: 'toolbarWithNoDone',
449
+ toolbarTop: 'toolbarTop',
450
+ toolbarRight: 'toolbarRight',
451
+ fullWidth: 'fullWidth',
452
+ hidden: 'hidden',
453
+ autoWidth: 'autoWidth',
454
+ focused: 'focused',
455
+ iconRoot: 'iconRoot',
456
+ label: 'label',
457
+ shared: 'shared',
458
+ };
459
+
460
+ return (
461
+ <StyledMenuBarRoot>
462
+ <MenuBar {...props} classes={classes} />
463
+ </StyledMenuBarRoot>
464
+ );
465
+ };
466
+
467
+ const StyledMenuBarRoot: any = styled('div')(({ theme }) => ({
468
+ '& .defaultToolbar': {
469
+ display: 'flex',
470
+ width: '100%',
471
+ justifyContent: 'space-between',
472
+ },
473
+ '& .buttonsContainer': {
474
+ alignItems: 'center',
475
+ display: 'flex',
476
+ width: '100%',
477
+ },
478
+ '& .button': {
479
+ color: 'grey',
480
+ display: 'inline-flex',
481
+ padding: '2px',
482
+ background: 'none',
483
+ border: 'none',
484
+ cursor: 'pointer',
485
+ '&:hover': {
486
+ color: 'black',
487
+ },
488
+ '&:focus': {
489
+ outline: `2px solid ${theme.palette.grey[700]}`,
490
+ },
491
+ },
492
+ '& .active': {
493
+ color: 'black',
494
+ },
495
+ '& .disabled': {
496
+ opacity: 0.7,
497
+ cursor: 'not-allowed',
498
+ '& :hover': {
499
+ color: 'grey',
500
+ },
501
+ },
502
+ '& .isActive': {
503
+ background: 'var(--purple)',
504
+ color: 'var(--white)',
505
+ },
506
+ '& .toolbar': {
507
+ position: 'absolute',
508
+ zIndex: 20,
509
+ cursor: 'pointer',
510
+ justifyContent: 'space-between',
511
+ background: 'var(--editable-html-toolbar-bg, #efefef)',
512
+ minWidth: '280px',
513
+ margin: '5px 0 0 0',
514
+ padding: '2px',
515
+ boxShadow:
516
+ '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)',
517
+ boxSizing: 'border-box',
518
+ display: 'flex',
519
+ opacity: 0,
520
+ pointerEvents: 'none',
521
+ },
522
+ '& .toolbarWithNoDone': {
523
+ minWidth: '265px',
524
+ },
525
+ '& .toolbarTop': {
526
+ top: '-45px',
527
+ },
528
+ '& .toolbarRight': {
529
+ right: 0,
530
+ },
531
+ '& .fullWidth': {
532
+ width: '100%',
533
+ },
534
+ '& .hidden': {
535
+ visibility: 'hidden',
536
+ },
537
+ '& .autoWidth': {
538
+ width: 'auto',
539
+ },
540
+ '& .focused': {
541
+ opacity: 1,
542
+ pointerEvents: 'auto',
543
+ },
544
+ '& .iconRoot': {
545
+ width: '28px',
546
+ height: '28px',
547
+ padding: '4px',
548
+ verticalAlign: 'top',
549
+ },
550
+ '& .label': {
551
+ color: 'var(--editable-html-toolbar-check, #00bb00)',
552
+ },
553
+ '& .shared': {
554
+ display: 'flex',
555
+ },
556
+ }));
557
+
558
+ export default StyledMenuBar;