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