@pie-lib/editable-html 11.21.2 → 11.21.3-next.155
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/CHANGELOG.md +6 -76
- package/esm/package.json +3 -0
- package/lib/block-tags.js +2 -3
- package/lib/block-tags.js.map +1 -1
- package/lib/constants.js +3 -6
- package/lib/constants.js.map +1 -1
- package/lib/editor.js +350 -481
- package/lib/editor.js.map +1 -1
- package/lib/index.js +18 -79
- package/lib/index.js.map +1 -1
- package/lib/parse-html.js +7 -7
- package/lib/parse-html.js.map +1 -1
- package/lib/plugins/characters/custom-popper.js +28 -44
- package/lib/plugins/characters/custom-popper.js.map +1 -1
- package/lib/plugins/characters/index.js +23 -63
- package/lib/plugins/characters/index.js.map +1 -1
- package/lib/plugins/characters/utils.js +3 -6
- package/lib/plugins/characters/utils.js.map +1 -1
- package/lib/plugins/css/icons/index.js +13 -25
- package/lib/plugins/css/icons/index.js.map +1 -1
- package/lib/plugins/css/index.js +34 -93
- package/lib/plugins/css/index.js.map +1 -1
- package/lib/plugins/customPlugin/index.js +10 -26
- package/lib/plugins/customPlugin/index.js.map +1 -1
- package/lib/plugins/html/icons/index.js +17 -25
- package/lib/plugins/html/icons/index.js.map +1 -1
- package/lib/plugins/html/index.js +4 -13
- package/lib/plugins/html/index.js.map +1 -1
- package/lib/plugins/image/alt-dialog.js +20 -49
- package/lib/plugins/image/alt-dialog.js.map +1 -1
- package/lib/plugins/image/component.js +118 -194
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js +48 -88
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js +6 -46
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/image/insert-image-handler.js +10 -31
- package/lib/plugins/image/insert-image-handler.js.map +1 -1
- package/lib/plugins/index.js +46 -106
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/list/index.js +27 -73
- package/lib/plugins/list/index.js.map +1 -1
- package/lib/plugins/math/index.js +64 -116
- package/lib/plugins/math/index.js.map +1 -1
- package/lib/plugins/media/index.js +27 -84
- package/lib/plugins/media/index.js.map +1 -1
- package/lib/plugins/media/media-dialog.js +192 -307
- package/lib/plugins/media/media-dialog.js.map +1 -1
- package/lib/plugins/media/media-toolbar.js +40 -65
- package/lib/plugins/media/media-toolbar.js.map +1 -1
- package/lib/plugins/media/media-wrapper.js +20 -49
- package/lib/plugins/media/media-wrapper.js.map +1 -1
- package/lib/plugins/rendering/index.js +5 -15
- package/lib/plugins/rendering/index.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/choice.js +233 -251
- package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/index.js +17 -59
- package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/utils.js +38 -0
- package/lib/plugins/respArea/drag-in-the-blank/utils.js.map +1 -0
- package/lib/plugins/respArea/explicit-constructed-response/index.js +3 -10
- package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
- package/lib/plugins/respArea/icons/index.js +22 -45
- package/lib/plugins/respArea/icons/index.js.map +1 -1
- package/lib/plugins/respArea/index.js +5 -59
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/respArea/inline-dropdown/index.js +2 -10
- package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
- package/lib/plugins/respArea/math-templated/index.js +91 -109
- package/lib/plugins/respArea/math-templated/index.js.map +1 -1
- package/lib/plugins/respArea/utils.js +12 -42
- package/lib/plugins/respArea/utils.js.map +1 -1
- package/lib/plugins/table/CustomTablePlugin.js +24 -41
- package/lib/plugins/table/CustomTablePlugin.js.map +1 -1
- package/lib/plugins/table/icons/index.js +21 -35
- package/lib/plugins/table/icons/index.js.map +1 -1
- package/lib/plugins/table/index.js +48 -118
- package/lib/plugins/table/index.js.map +1 -1
- package/lib/plugins/table/table-toolbar.js +37 -86
- package/lib/plugins/table/table-toolbar.js.map +1 -1
- package/lib/plugins/textAlign/icons/index.js +25 -64
- package/lib/plugins/textAlign/icons/index.js.map +1 -1
- package/lib/plugins/textAlign/index.js +0 -8
- package/lib/plugins/textAlign/index.js.map +1 -1
- package/lib/plugins/toolbar/default-toolbar.js +30 -79
- package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/done-button.js +16 -34
- package/lib/plugins/toolbar/done-button.js.map +1 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js +174 -202
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/index.js +0 -5
- package/lib/plugins/toolbar/index.js.map +1 -1
- package/lib/plugins/toolbar/toolbar-buttons.js +59 -108
- package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
- package/lib/plugins/toolbar/toolbar.js +93 -162
- package/lib/plugins/toolbar/toolbar.js.map +1 -1
- package/lib/plugins/utils.js +5 -25
- package/lib/plugins/utils.js.map +1 -1
- package/lib/serialization.js +47 -153
- package/lib/serialization.js.map +1 -1
- package/lib/shared/alert-dialog.js +35 -42
- package/lib/theme.js +1 -2
- package/lib/theme.js.map +1 -1
- package/package.json +26 -14
- package/src/__tests__/editor-utils.test.js +162 -0
- package/src/__tests__/utils.js +1 -1
- package/src/editor.jsx +175 -153
- package/src/index.jsx +0 -3
- package/src/plugins/characters/custom-popper.js +25 -25
- package/src/plugins/characters/index.jsx +15 -5
- package/src/plugins/css/icons/index.jsx +11 -13
- package/src/plugins/css/index.jsx +16 -11
- package/src/plugins/html/icons/index.jsx +17 -14
- package/src/plugins/image/__tests__/component.test.jsx +61 -29
- package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +69 -17
- package/src/plugins/image/__tests__/image-toolbar.test.jsx +6 -4
- package/src/plugins/image/alt-dialog.jsx +9 -8
- package/src/plugins/image/component.jsx +68 -92
- package/src/plugins/image/image-toolbar.jsx +31 -28
- package/src/plugins/image/index.jsx +1 -1
- package/src/plugins/index.jsx +12 -10
- package/src/plugins/math/__tests__/index.test.jsx +45 -26
- package/src/plugins/math/index.jsx +1 -1
- package/src/plugins/media/index.jsx +6 -5
- package/src/plugins/media/media-dialog.js +65 -76
- package/src/plugins/media/media-toolbar.jsx +32 -33
- package/src/plugins/media/media-wrapper.jsx +10 -13
- package/src/plugins/respArea/drag-in-the-blank/choice.jsx +240 -167
- package/src/plugins/respArea/drag-in-the-blank/index.jsx +27 -56
- package/src/plugins/respArea/drag-in-the-blank/utils.js +14 -0
- package/src/plugins/respArea/icons/index.jsx +16 -16
- package/src/plugins/respArea/math-templated/index.jsx +88 -89
- package/src/plugins/respArea/utils.jsx +5 -3
- package/src/plugins/table/__tests__/table-toolbar.test.jsx +40 -7
- package/src/plugins/table/icons/index.jsx +16 -16
- package/src/plugins/table/index.jsx +35 -19
- package/src/plugins/table/table-toolbar.jsx +18 -19
- package/src/plugins/textAlign/icons/index.jsx +13 -4
- package/src/plugins/textAlign/index.jsx +0 -3
- package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +102 -69
- package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +14 -11
- package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +81 -35
- package/src/plugins/toolbar/__tests__/toolbar.test.jsx +44 -38
- package/src/plugins/toolbar/default-toolbar.jsx +18 -21
- package/src/plugins/toolbar/done-button.jsx +16 -22
- package/src/plugins/toolbar/editor-and-toolbar.jsx +134 -158
- package/src/plugins/toolbar/toolbar-buttons.jsx +30 -46
- package/src/plugins/toolbar/toolbar.jsx +57 -79
- package/src/serialization.jsx +3 -3
- package/src/__tests__/editor.test.jsx +0 -363
- package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +0 -51
- package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +0 -27
- package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +0 -44
- package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +0 -48
- package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +0 -44
- package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +0 -923
- package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +0 -20
- package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +0 -36
- package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +0 -46
|
@@ -1,15 +1,133 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import Toolbar from './toolbar';
|
|
3
|
-
import classNames from 'classnames';
|
|
4
3
|
import debug from 'debug';
|
|
5
4
|
import { primary } from '../../theme';
|
|
6
|
-
import {
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
7
6
|
import PropTypes from 'prop-types';
|
|
8
7
|
import SlatePropTypes from 'slate-prop-types';
|
|
9
8
|
import { color } from '@pie-lib/render-ui';
|
|
10
9
|
|
|
11
10
|
const log = debug('@pie-lib:editable-html:plugins:toolbar:editor-and-toolbar');
|
|
12
11
|
|
|
12
|
+
const Root = styled('div', {
|
|
13
|
+
shouldForwardProp: (prop) => !['noBorder', 'error'].includes(prop),
|
|
14
|
+
})(({ theme, noBorder, error }) => ({
|
|
15
|
+
position: 'relative',
|
|
16
|
+
padding: '0px',
|
|
17
|
+
border: noBorder ? 'none' : '1px solid #ccc',
|
|
18
|
+
borderRadius: '4px',
|
|
19
|
+
cursor: 'text',
|
|
20
|
+
borderColor: error ? `${theme.palette.error.main} !important` : undefined,
|
|
21
|
+
borderWidth: error ? '2px !important' : undefined,
|
|
22
|
+
'& [data-slate-editor="true"]': {
|
|
23
|
+
wordBreak: 'break-word',
|
|
24
|
+
overflow: 'visible',
|
|
25
|
+
maxHeight: '500px',
|
|
26
|
+
// needed in order to be able to put the focus before a void element when it is the first one in the editor
|
|
27
|
+
padding: '5px',
|
|
28
|
+
},
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
const EditorHolder = styled('div', {
|
|
32
|
+
shouldForwardProp: (prop) => !['inFocus', 'readOnly', 'disableUnderline', 'disableScrollbar'].includes(prop),
|
|
33
|
+
})(({ theme, inFocus, readOnly, disableUnderline, disableScrollbar }) => ({
|
|
34
|
+
position: 'relative',
|
|
35
|
+
padding: '0px',
|
|
36
|
+
overflowY: 'auto',
|
|
37
|
+
color: color.text(),
|
|
38
|
+
backgroundColor: color.background(),
|
|
39
|
+
...(disableScrollbar && {
|
|
40
|
+
'&::-webkit-scrollbar': {
|
|
41
|
+
display: 'none',
|
|
42
|
+
},
|
|
43
|
+
scrollbarWidth: 'none',
|
|
44
|
+
'-ms-overflow-style': 'none',
|
|
45
|
+
}),
|
|
46
|
+
...(!disableUnderline && {
|
|
47
|
+
'&::before': {
|
|
48
|
+
left: '0',
|
|
49
|
+
right: '0',
|
|
50
|
+
bottom: '0',
|
|
51
|
+
height: '1px',
|
|
52
|
+
content: '""',
|
|
53
|
+
position: 'absolute',
|
|
54
|
+
transition: 'background-color 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
|
|
55
|
+
pointerEvents: 'none',
|
|
56
|
+
backgroundColor: 'rgba(0, 0, 0, 0.42)',
|
|
57
|
+
},
|
|
58
|
+
'&::after': {
|
|
59
|
+
left: '0',
|
|
60
|
+
right: '0',
|
|
61
|
+
bottom: '0',
|
|
62
|
+
height: '1px',
|
|
63
|
+
content: '""',
|
|
64
|
+
position: 'absolute',
|
|
65
|
+
transform: 'scaleX(0)',
|
|
66
|
+
transition: 'transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms, background-color 200ms linear',
|
|
67
|
+
backgroundColor: 'rgba(0, 0, 0, 0.42)',
|
|
68
|
+
},
|
|
69
|
+
'&:focus': {
|
|
70
|
+
'&::after': {
|
|
71
|
+
transform: 'scaleX(1)',
|
|
72
|
+
backgroundColor: primary,
|
|
73
|
+
height: '2px',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
'&:hover': {
|
|
77
|
+
'&::after': {
|
|
78
|
+
transform: 'scaleX(1)',
|
|
79
|
+
backgroundColor: theme.palette.common.black,
|
|
80
|
+
height: '2px',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
}),
|
|
84
|
+
...(readOnly && {
|
|
85
|
+
'&::before': {
|
|
86
|
+
background: 'transparent',
|
|
87
|
+
backgroundSize: '5px 1px',
|
|
88
|
+
backgroundImage: 'linear-gradient(to right, rgba(0, 0, 0, 0.42) 33%, transparent 0%)',
|
|
89
|
+
backgroundRepeat: 'repeat-x',
|
|
90
|
+
backgroundPosition: 'left top',
|
|
91
|
+
},
|
|
92
|
+
'&::after': {
|
|
93
|
+
left: '0',
|
|
94
|
+
right: '0',
|
|
95
|
+
bottom: '0',
|
|
96
|
+
height: '1px',
|
|
97
|
+
content: '""',
|
|
98
|
+
position: 'absolute',
|
|
99
|
+
transform: 'scaleX(0)',
|
|
100
|
+
transition: 'transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms, background-color 0ms linear',
|
|
101
|
+
backgroundColor: 'rgba(0, 0, 0, 0)',
|
|
102
|
+
},
|
|
103
|
+
'&:hover': {
|
|
104
|
+
'&::after': {
|
|
105
|
+
transform: 'scaleX(0)',
|
|
106
|
+
backgroundColor: theme.palette.common.black,
|
|
107
|
+
height: '2px',
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
}),
|
|
111
|
+
...(inFocus && {
|
|
112
|
+
'&::after': {
|
|
113
|
+
transform: 'scaleX(1)',
|
|
114
|
+
backgroundColor: primary,
|
|
115
|
+
height: '2px',
|
|
116
|
+
},
|
|
117
|
+
'&:hover': {
|
|
118
|
+
'&::after': {
|
|
119
|
+
backgroundColor: primary,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
}),
|
|
123
|
+
}));
|
|
124
|
+
|
|
125
|
+
const ChildrenContainer = styled('div', {
|
|
126
|
+
shouldForwardProp: (prop) => !['noPadding'].includes(prop),
|
|
127
|
+
})(({ noPadding }) => ({
|
|
128
|
+
padding: noPadding ? 0 : '10px 16px',
|
|
129
|
+
}));
|
|
130
|
+
|
|
13
131
|
export class EditorAndToolbar extends React.Component {
|
|
14
132
|
static propTypes = {
|
|
15
133
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
@@ -25,7 +143,6 @@ export class EditorAndToolbar extends React.Component {
|
|
|
25
143
|
disableScrollbar: PropTypes.bool,
|
|
26
144
|
disableUnderline: PropTypes.bool,
|
|
27
145
|
autoWidth: PropTypes.bool,
|
|
28
|
-
classes: PropTypes.object.isRequired,
|
|
29
146
|
pluginProps: PropTypes.object,
|
|
30
147
|
toolbarOpts: PropTypes.shape({
|
|
31
148
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
@@ -42,7 +159,6 @@ export class EditorAndToolbar extends React.Component {
|
|
|
42
159
|
|
|
43
160
|
render() {
|
|
44
161
|
const {
|
|
45
|
-
classes,
|
|
46
162
|
children,
|
|
47
163
|
value,
|
|
48
164
|
plugins,
|
|
@@ -66,13 +182,6 @@ export class EditorAndToolbar extends React.Component {
|
|
|
66
182
|
|
|
67
183
|
let inFocus = value.isFocused || (focusedNode !== null && focusedNode !== undefined) || focusToolbar;
|
|
68
184
|
|
|
69
|
-
const holderNames = classNames(classes.editorHolder, {
|
|
70
|
-
[classes.editorInFocus]: inFocus,
|
|
71
|
-
[classes.readOnly]: readOnly,
|
|
72
|
-
[classes.disabledUnderline]: disableUnderline,
|
|
73
|
-
[classes.disabledScrollbar]: disableScrollbar,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
185
|
let clonedChildren = children;
|
|
77
186
|
|
|
78
187
|
if (typeof children !== 'string') {
|
|
@@ -84,27 +193,20 @@ export class EditorAndToolbar extends React.Component {
|
|
|
84
193
|
log('[render] inFocus: ', inFocus, 'value.isFocused:', value.isFocused, 'focused node: ', focusedNode);
|
|
85
194
|
|
|
86
195
|
return (
|
|
87
|
-
<
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
[classes.noBorder]: toolbarOpts && toolbarOpts.noBorder,
|
|
91
|
-
[classes.error]: toolbarOpts && toolbarOpts.error,
|
|
92
|
-
},
|
|
93
|
-
classes.root,
|
|
94
|
-
)}
|
|
196
|
+
<Root
|
|
197
|
+
noBorder={toolbarOpts && toolbarOpts.noBorder}
|
|
198
|
+
error={toolbarOpts && toolbarOpts.error}
|
|
95
199
|
>
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
)}
|
|
104
|
-
>
|
|
200
|
+
<EditorHolder
|
|
201
|
+
inFocus={inFocus}
|
|
202
|
+
readOnly={readOnly}
|
|
203
|
+
disableUnderline={disableUnderline}
|
|
204
|
+
disableScrollbar={disableScrollbar}
|
|
205
|
+
>
|
|
206
|
+
<ChildrenContainer noPadding={toolbarOpts && toolbarOpts.noPadding}>
|
|
105
207
|
{clonedChildren}
|
|
106
|
-
</
|
|
107
|
-
</
|
|
208
|
+
</ChildrenContainer>
|
|
209
|
+
</EditorHolder>
|
|
108
210
|
|
|
109
211
|
<Toolbar
|
|
110
212
|
autoWidth={autoWidth}
|
|
@@ -123,135 +225,9 @@ export class EditorAndToolbar extends React.Component {
|
|
|
123
225
|
pluginProps={pluginProps}
|
|
124
226
|
toolbarOpts={toolbarOpts}
|
|
125
227
|
/>
|
|
126
|
-
</
|
|
228
|
+
</Root>
|
|
127
229
|
);
|
|
128
230
|
}
|
|
129
231
|
}
|
|
130
232
|
|
|
131
|
-
|
|
132
|
-
root: {
|
|
133
|
-
position: 'relative',
|
|
134
|
-
padding: '0px',
|
|
135
|
-
border: '1px solid #ccc',
|
|
136
|
-
borderRadius: '4px',
|
|
137
|
-
cursor: 'text',
|
|
138
|
-
'& [data-slate-editor="true"]': {
|
|
139
|
-
wordBreak: 'break-word',
|
|
140
|
-
overflow: 'visible',
|
|
141
|
-
maxHeight: '500px',
|
|
142
|
-
// needed in order to be able to put the focus before a void element when it is the first one in the editor
|
|
143
|
-
padding: '5px',
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
|
-
children: {
|
|
147
|
-
padding: '10px 16px',
|
|
148
|
-
},
|
|
149
|
-
editorHolder: {
|
|
150
|
-
position: 'relative',
|
|
151
|
-
padding: '0px',
|
|
152
|
-
overflowY: 'auto',
|
|
153
|
-
color: color.text(),
|
|
154
|
-
backgroundColor: color.background(),
|
|
155
|
-
'&::before': {
|
|
156
|
-
left: '0',
|
|
157
|
-
right: '0',
|
|
158
|
-
bottom: '0',
|
|
159
|
-
height: '1px',
|
|
160
|
-
content: '""',
|
|
161
|
-
position: 'absolute',
|
|
162
|
-
transition: 'background-color 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
|
|
163
|
-
pointerEvents: 'none',
|
|
164
|
-
backgroundColor: 'rgba(0, 0, 0, 0.42)',
|
|
165
|
-
},
|
|
166
|
-
'&::after': {
|
|
167
|
-
left: '0',
|
|
168
|
-
right: '0',
|
|
169
|
-
bottom: '0',
|
|
170
|
-
height: '1px',
|
|
171
|
-
content: '""',
|
|
172
|
-
position: 'absolute',
|
|
173
|
-
transform: 'scaleX(0)',
|
|
174
|
-
transition: 'transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms, background-color 200ms linear',
|
|
175
|
-
backgroundColor: 'rgba(0, 0, 0, 0.42)',
|
|
176
|
-
},
|
|
177
|
-
'&:focus': {
|
|
178
|
-
'&::after': {
|
|
179
|
-
transform: 'scaleX(1)',
|
|
180
|
-
backgroundColor: primary,
|
|
181
|
-
height: '2px',
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
'&:hover': {
|
|
185
|
-
'&::after': {
|
|
186
|
-
transform: 'scaleX(1)',
|
|
187
|
-
backgroundColor: theme.palette.common.black,
|
|
188
|
-
height: '2px',
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
disabledUnderline: {
|
|
193
|
-
'&::before': {
|
|
194
|
-
display: 'none',
|
|
195
|
-
},
|
|
196
|
-
'&::after': {
|
|
197
|
-
display: 'none',
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
disabledScrollbar: {
|
|
201
|
-
'&::-webkit-scrollbar': {
|
|
202
|
-
display: 'none',
|
|
203
|
-
},
|
|
204
|
-
scrollbarWidth: 'none',
|
|
205
|
-
'-ms-overflow-style': 'none',
|
|
206
|
-
},
|
|
207
|
-
readOnly: {
|
|
208
|
-
'&::before': {
|
|
209
|
-
background: 'transparent',
|
|
210
|
-
backgroundSize: '5px 1px',
|
|
211
|
-
backgroundImage: 'linear-gradient(to right, rgba(0, 0, 0, 0.42) 33%, transparent 0%)',
|
|
212
|
-
backgroundRepeat: 'repeat-x',
|
|
213
|
-
backgroundPosition: 'left top',
|
|
214
|
-
},
|
|
215
|
-
'&::after': {
|
|
216
|
-
left: '0',
|
|
217
|
-
right: '0',
|
|
218
|
-
bottom: '0',
|
|
219
|
-
height: '1px',
|
|
220
|
-
content: '""',
|
|
221
|
-
position: 'absolute',
|
|
222
|
-
transform: 'scaleX(0)',
|
|
223
|
-
transition: 'transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms, background-color 0ms linear',
|
|
224
|
-
backgroundColor: 'rgba(0, 0, 0, 0)',
|
|
225
|
-
},
|
|
226
|
-
'&:hover': {
|
|
227
|
-
'&::after': {
|
|
228
|
-
transform: 'scaleX(0)',
|
|
229
|
-
backgroundColor: theme.palette.common.black,
|
|
230
|
-
height: '2px',
|
|
231
|
-
},
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
editorInFocus: {
|
|
235
|
-
'&::after': {
|
|
236
|
-
transform: 'scaleX(1)',
|
|
237
|
-
backgroundColor: primary,
|
|
238
|
-
height: '2px',
|
|
239
|
-
},
|
|
240
|
-
'&:hover': {
|
|
241
|
-
'&::after': {
|
|
242
|
-
backgroundColor: primary,
|
|
243
|
-
},
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
|
-
error: {
|
|
247
|
-
border: `2px solid ${theme.palette.error.main} !important`,
|
|
248
|
-
},
|
|
249
|
-
noBorder: {
|
|
250
|
-
border: 'none',
|
|
251
|
-
},
|
|
252
|
-
noPadding: {
|
|
253
|
-
padding: 0,
|
|
254
|
-
},
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
export default withStyles(style)(EditorAndToolbar);
|
|
233
|
+
export default EditorAndToolbar;
|
|
@@ -1,46 +1,37 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import debug from 'debug';
|
|
3
|
-
import {
|
|
4
|
-
import classNames from 'classnames';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
5
4
|
import PropTypes from 'prop-types';
|
|
6
5
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'
|
|
19
|
-
outline: `2px solid ${theme.palette.grey[700]}`,
|
|
20
|
-
},
|
|
6
|
+
const StyledButton = styled('button', {
|
|
7
|
+
shouldForwardProp: (prop) => !['active', 'disabled', 'extraStyles'].includes(prop),
|
|
8
|
+
})(({ theme, active, disabled, extraStyles }) => ({
|
|
9
|
+
color: active ? 'black' : 'grey',
|
|
10
|
+
display: 'inline-flex',
|
|
11
|
+
padding: '2px',
|
|
12
|
+
background: 'none',
|
|
13
|
+
border: 'none',
|
|
14
|
+
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
15
|
+
opacity: disabled ? 0.7 : 1,
|
|
16
|
+
'&:hover': {
|
|
17
|
+
color: disabled ? 'grey' : 'black',
|
|
21
18
|
},
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
'&:focus': {
|
|
20
|
+
outline: `2px solid ${theme.palette.grey[700]}`,
|
|
24
21
|
},
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
cursor: 'not-allowed',
|
|
28
|
-
'& :hover': {
|
|
29
|
-
color: 'grey',
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
});
|
|
22
|
+
...extraStyles,
|
|
23
|
+
}));
|
|
33
24
|
|
|
34
25
|
const log = debug('pie-elements:editable-html:raw-button');
|
|
35
26
|
|
|
36
27
|
export class RawButton extends React.Component {
|
|
37
28
|
static propTypes = {
|
|
38
29
|
onClick: PropTypes.func.isRequired,
|
|
39
|
-
classes: PropTypes.object.isRequired,
|
|
40
30
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
41
31
|
active: PropTypes.bool,
|
|
42
32
|
disabled: PropTypes.bool,
|
|
43
33
|
extraStyles: PropTypes.object,
|
|
34
|
+
ariaLabel: PropTypes.string,
|
|
44
35
|
};
|
|
45
36
|
|
|
46
37
|
constructor(props) {
|
|
@@ -64,31 +55,26 @@ export class RawButton extends React.Component {
|
|
|
64
55
|
};
|
|
65
56
|
|
|
66
57
|
render() {
|
|
67
|
-
const { active,
|
|
68
|
-
|
|
69
|
-
const names = classNames(classes.button, {
|
|
70
|
-
[classes.active]: active,
|
|
71
|
-
[classes.disabled]: disabled,
|
|
72
|
-
});
|
|
58
|
+
const { active, children, disabled, extraStyles, ariaLabel } = this.props;
|
|
73
59
|
|
|
74
60
|
return (
|
|
75
|
-
<
|
|
76
|
-
|
|
77
|
-
|
|
61
|
+
<StyledButton
|
|
62
|
+
active={active}
|
|
63
|
+
disabled={disabled}
|
|
64
|
+
extraStyles={extraStyles}
|
|
78
65
|
onMouseDown={this.onClick}
|
|
79
66
|
onKeyDown={this.onKeyDown}
|
|
80
|
-
disabled={disabled}
|
|
81
67
|
aria-label={ariaLabel}
|
|
82
68
|
aria-pressed={active}
|
|
83
69
|
tabIndex={0}
|
|
84
70
|
>
|
|
85
71
|
{children}
|
|
86
|
-
</
|
|
72
|
+
</StyledButton>
|
|
87
73
|
);
|
|
88
74
|
}
|
|
89
75
|
}
|
|
90
76
|
|
|
91
|
-
export const Button =
|
|
77
|
+
export const Button = RawButton;
|
|
92
78
|
|
|
93
79
|
export class RawMarkButton extends React.Component {
|
|
94
80
|
static propTypes = {
|
|
@@ -96,7 +82,6 @@ export class RawMarkButton extends React.Component {
|
|
|
96
82
|
mark: PropTypes.string,
|
|
97
83
|
label: PropTypes.string.isRequired,
|
|
98
84
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
99
|
-
classes: PropTypes.object.isRequired,
|
|
100
85
|
active: PropTypes.bool,
|
|
101
86
|
};
|
|
102
87
|
|
|
@@ -117,12 +102,11 @@ export class RawMarkButton extends React.Component {
|
|
|
117
102
|
};
|
|
118
103
|
|
|
119
104
|
render() {
|
|
120
|
-
const {
|
|
105
|
+
const { children, active, label } = this.props;
|
|
121
106
|
|
|
122
|
-
const names = classNames(classes.button, active && classes.active);
|
|
123
107
|
return (
|
|
124
|
-
<
|
|
125
|
-
|
|
108
|
+
<StyledButton
|
|
109
|
+
active={active}
|
|
126
110
|
onMouseDown={this.onToggle}
|
|
127
111
|
aria-pressed={active}
|
|
128
112
|
onKeyDown={this.onKeyDown}
|
|
@@ -130,9 +114,9 @@ export class RawMarkButton extends React.Component {
|
|
|
130
114
|
tabIndex={0}
|
|
131
115
|
>
|
|
132
116
|
{children}
|
|
133
|
-
</
|
|
117
|
+
</StyledButton>
|
|
134
118
|
);
|
|
135
119
|
}
|
|
136
120
|
}
|
|
137
121
|
|
|
138
|
-
export const MarkButton =
|
|
122
|
+
export const MarkButton = RawMarkButton;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Change } from 'slate';
|
|
3
|
-
import Delete from '@
|
|
4
|
-
import IconButton from '@material
|
|
3
|
+
import Delete from '@mui/icons-material/Delete';
|
|
4
|
+
import IconButton from '@mui/material/IconButton';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
|
-
import classNames from 'classnames';
|
|
7
6
|
import debug from 'debug';
|
|
8
7
|
import SlatePropTypes from 'slate-prop-types';
|
|
9
8
|
import debounce from 'lodash/debounce';
|
|
@@ -11,13 +10,47 @@ import debounce from 'lodash/debounce';
|
|
|
11
10
|
import { DoneButton } from './done-button';
|
|
12
11
|
|
|
13
12
|
import { findSingleNode, findParentNode } from '../utils';
|
|
14
|
-
import {
|
|
13
|
+
import { styled } from '@mui/material/styles';
|
|
15
14
|
import DefaultToolbar from './default-toolbar';
|
|
16
15
|
import { removeDialogs as removeCharacterDialogs } from '../characters';
|
|
17
16
|
import { PIE_TOOLBAR__CLASS } from '../../constants';
|
|
18
17
|
|
|
19
18
|
const log = debug('@pie-lib:editable-html:plugins:toolbar');
|
|
20
19
|
|
|
20
|
+
const StyledToolbar = styled('div', {
|
|
21
|
+
shouldForwardProp: (prop) => !['hasDoneButton', 'position', 'alignment', 'focused', 'autoWidth', 'hidden'].includes(prop),
|
|
22
|
+
})(({ hasDoneButton, position, alignment, focused, autoWidth, hidden }) => ({
|
|
23
|
+
position: 'absolute',
|
|
24
|
+
zIndex: 10,
|
|
25
|
+
cursor: 'pointer',
|
|
26
|
+
justifyContent: 'space-between',
|
|
27
|
+
background: 'var(--editable-html-toolbar-bg, #efefef)',
|
|
28
|
+
minWidth: hasDoneButton ? '280px' : '265px',
|
|
29
|
+
margin: '5px 0 0 0',
|
|
30
|
+
padding: '2px',
|
|
31
|
+
boxShadow:
|
|
32
|
+
'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)',
|
|
33
|
+
boxSizing: 'border-box',
|
|
34
|
+
display: 'flex',
|
|
35
|
+
opacity: focused ? 1 : 0,
|
|
36
|
+
pointerEvents: focused ? 'auto' : 'none',
|
|
37
|
+
top: position === 'top' ? '-45px' : 'auto',
|
|
38
|
+
right: alignment === 'right' ? 0 : 'auto',
|
|
39
|
+
width: autoWidth ? 'auto' : '100%',
|
|
40
|
+
visibility: hidden ? 'hidden' : 'visible',
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
const SharedContainer = styled('div')({
|
|
44
|
+
display: 'flex',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const StyledIconButton = styled(IconButton)({
|
|
48
|
+
width: '28px',
|
|
49
|
+
height: '28px',
|
|
50
|
+
padding: '4px',
|
|
51
|
+
verticalAlign: 'top',
|
|
52
|
+
});
|
|
53
|
+
|
|
21
54
|
const getCustomToolbar = (plugin, node, value, handleDone, getFocusedValue, onDataChange) => {
|
|
22
55
|
if (!plugin) {
|
|
23
56
|
return;
|
|
@@ -57,6 +90,7 @@ export class Toolbar extends React.Component {
|
|
|
57
90
|
getFocusedValue: PropTypes.func.isRequired,
|
|
58
91
|
pluginProps: PropTypes.object,
|
|
59
92
|
toolbarOpts: PropTypes.shape({
|
|
93
|
+
isHtmlMode: PropTypes.bool,
|
|
60
94
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
61
95
|
alignment: PropTypes.oneOf(['left', 'right']),
|
|
62
96
|
alwaysVisible: PropTypes.bool,
|
|
@@ -141,7 +175,6 @@ export class Toolbar extends React.Component {
|
|
|
141
175
|
|
|
142
176
|
render() {
|
|
143
177
|
const {
|
|
144
|
-
classes,
|
|
145
178
|
plugins,
|
|
146
179
|
pluginProps,
|
|
147
180
|
toolbarOpts,
|
|
@@ -223,20 +256,21 @@ export class Toolbar extends React.Component {
|
|
|
223
256
|
const defaultToolbarShowDone = !toolbarOpts || toolbarOpts.showDone !== false;
|
|
224
257
|
|
|
225
258
|
const hasDoneButton = defaultToolbarShowDone || customToolbarShowDone;
|
|
226
|
-
|
|
227
|
-
const names = classNames(classes.toolbar, PIE_TOOLBAR__CLASS, {
|
|
228
|
-
[classes.toolbarWithNoDone]: !hasDoneButton,
|
|
229
|
-
[classes.toolbarTop]: toolbarOpts.position === 'top',
|
|
230
|
-
[classes.toolbarRight]: toolbarOpts.alignment === 'right',
|
|
231
|
-
[classes.focused]: toolbarOpts.alwaysVisible || isFocused,
|
|
232
|
-
[classes.autoWidth]: autoWidth,
|
|
233
|
-
[classes.fullWidth]: !autoWidth,
|
|
234
|
-
[classes.hidden]: toolbarOpts.isHidden === true,
|
|
235
|
-
});
|
|
236
259
|
const customStyles = toolbarOpts.minWidth !== undefined ? { minWidth: toolbarOpts.minWidth } : {};
|
|
237
260
|
|
|
238
261
|
return (
|
|
239
|
-
<
|
|
262
|
+
<StyledToolbar
|
|
263
|
+
className={PIE_TOOLBAR__CLASS}
|
|
264
|
+
hasDoneButton={hasDoneButton}
|
|
265
|
+
position={toolbarOpts.position}
|
|
266
|
+
alignment={toolbarOpts.alignment}
|
|
267
|
+
focused={toolbarOpts.alwaysVisible || isFocused}
|
|
268
|
+
autoWidth={autoWidth}
|
|
269
|
+
hidden={toolbarOpts.isHidden === true}
|
|
270
|
+
style={{ ...extraStyles, ...customStyles }}
|
|
271
|
+
onClick={this.onClick}
|
|
272
|
+
ref={toolbarRef}
|
|
273
|
+
>
|
|
240
274
|
{CustomToolbar ? (
|
|
241
275
|
<CustomToolbar
|
|
242
276
|
node={node}
|
|
@@ -262,77 +296,21 @@ export class Toolbar extends React.Component {
|
|
|
262
296
|
onBlur={onBlur}
|
|
263
297
|
/>
|
|
264
298
|
)}
|
|
265
|
-
|
|
266
|
-
<div className={classes.shared}>
|
|
299
|
+
<SharedContainer>
|
|
267
300
|
{deletable && (
|
|
268
|
-
<
|
|
301
|
+
<StyledIconButton
|
|
269
302
|
aria-label="Delete"
|
|
270
|
-
className={classes.iconRoot}
|
|
271
303
|
onMouseDown={(e) => this.onDeleteMouseDown(e, plugin, node, value, onChange)}
|
|
272
|
-
|
|
273
|
-
root: classes.iconRoot,
|
|
274
|
-
}}
|
|
304
|
+
size="large"
|
|
275
305
|
>
|
|
276
306
|
<Delete />
|
|
277
|
-
</
|
|
307
|
+
</StyledIconButton>
|
|
278
308
|
)}
|
|
279
309
|
{customToolbarShowDone && <DoneButton doneButtonRef={doneButtonRef} onClick={handleDone} />}
|
|
280
|
-
</
|
|
281
|
-
</
|
|
310
|
+
</SharedContainer>
|
|
311
|
+
</StyledToolbar>
|
|
282
312
|
);
|
|
283
313
|
}
|
|
284
314
|
}
|
|
285
315
|
|
|
286
|
-
|
|
287
|
-
toolbar: {
|
|
288
|
-
position: 'absolute',
|
|
289
|
-
zIndex: 10,
|
|
290
|
-
cursor: 'pointer',
|
|
291
|
-
justifyContent: 'space-between',
|
|
292
|
-
background: 'var(--editable-html-toolbar-bg, #efefef)',
|
|
293
|
-
minWidth: '280px',
|
|
294
|
-
margin: '5px 0 0 0',
|
|
295
|
-
padding: '2px',
|
|
296
|
-
boxShadow:
|
|
297
|
-
'0px 1px 5px 0px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)',
|
|
298
|
-
boxSizing: 'border-box',
|
|
299
|
-
display: 'flex',
|
|
300
|
-
opacity: 0,
|
|
301
|
-
pointerEvents: 'none',
|
|
302
|
-
},
|
|
303
|
-
toolbarWithNoDone: {
|
|
304
|
-
minWidth: '265px',
|
|
305
|
-
},
|
|
306
|
-
toolbarTop: {
|
|
307
|
-
top: '-45px',
|
|
308
|
-
},
|
|
309
|
-
toolbarRight: {
|
|
310
|
-
right: 0,
|
|
311
|
-
},
|
|
312
|
-
fullWidth: {
|
|
313
|
-
width: '100%',
|
|
314
|
-
},
|
|
315
|
-
hidden: {
|
|
316
|
-
visibility: 'hidden',
|
|
317
|
-
},
|
|
318
|
-
autoWidth: {
|
|
319
|
-
width: 'auto',
|
|
320
|
-
},
|
|
321
|
-
focused: {
|
|
322
|
-
opacity: 1,
|
|
323
|
-
pointerEvents: 'auto',
|
|
324
|
-
},
|
|
325
|
-
iconRoot: {
|
|
326
|
-
width: '28px',
|
|
327
|
-
height: '28px',
|
|
328
|
-
padding: '4px',
|
|
329
|
-
verticalAlign: 'top',
|
|
330
|
-
},
|
|
331
|
-
label: {
|
|
332
|
-
color: 'var(--editable-html-toolbar-check, #00bb00)',
|
|
333
|
-
},
|
|
334
|
-
shared: {
|
|
335
|
-
display: 'flex',
|
|
336
|
-
},
|
|
337
|
-
};
|
|
338
|
-
export default withStyles(style, { index: 1000 })(Toolbar);
|
|
316
|
+
export default Toolbar;
|
package/src/serialization.jsx
CHANGED
|
@@ -467,7 +467,7 @@ export const reduceMultipleBrs = (markup) => {
|
|
|
467
467
|
return markup.replace(/(<br\s*\/?>){3,}/gi, '<br>');
|
|
468
468
|
} catch (e) {
|
|
469
469
|
// eslint-disable-next-line no-console
|
|
470
|
-
console.log(
|
|
470
|
+
console.log('Couldn\'t remove <br/> tags: ', e);
|
|
471
471
|
}
|
|
472
472
|
|
|
473
473
|
return markup;
|
|
@@ -478,7 +478,7 @@ const reduceRedundantNewLineCharacters = (markup) => {
|
|
|
478
478
|
return markup.replace(/\n/gi, '');
|
|
479
479
|
} catch (e) {
|
|
480
480
|
// eslint-disable-next-line no-console
|
|
481
|
-
console.log(
|
|
481
|
+
console.log('Couldn\'t remove <br/> tags: ', e);
|
|
482
482
|
}
|
|
483
483
|
|
|
484
484
|
return markup;
|
|
@@ -605,7 +605,7 @@ export const htmlToValue = (html) => {
|
|
|
605
605
|
return serializer.deserialize(handleHtml(html));
|
|
606
606
|
} catch (e) {
|
|
607
607
|
// eslint-disable-next-line no-console
|
|
608
|
-
console.log(
|
|
608
|
+
console.log('Couldn\'t parse html: ', e);
|
|
609
609
|
return {};
|
|
610
610
|
}
|
|
611
611
|
};
|