@pie-lib/editable-html 10.0.0-beta.5 → 10.0.0-beta.6
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 +255 -152
- package/lib/components.js +15 -39
- package/lib/components.js.map +1 -1
- package/lib/editor.js +200 -356
- package/lib/editor.js.map +1 -1
- package/lib/index.js +25 -49
- package/lib/index.js.map +1 -1
- package/lib/new-serialization.js +6 -67
- package/lib/new-serialization.js.map +1 -1
- package/lib/parse-html.js +7 -6
- package/lib/parse-html.js.map +1 -1
- package/lib/plugins/characters/custom-popper.js +3 -13
- package/lib/plugins/characters/custom-popper.js.map +1 -1
- package/lib/plugins/characters/index.js +20 -59
- package/lib/plugins/characters/index.js.map +1 -1
- package/lib/plugins/characters/utils.js +1 -1
- package/lib/plugins/characters/utils.js.map +1 -1
- package/lib/plugins/hotKeys/index.js +9 -16
- package/lib/plugins/hotKeys/index.js.map +1 -1
- package/lib/plugins/image/alt-dialog.js +6 -27
- package/lib/plugins/image/alt-dialog.js.map +1 -1
- package/lib/plugins/image/component.js +42 -99
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js +14 -50
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js +16 -59
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/image/insert-image-handler.js +13 -25
- package/lib/plugins/image/insert-image-handler.js.map +1 -1
- package/lib/plugins/index.js +6 -36
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/list/index.js +11 -46
- package/lib/plugins/list/index.js.map +1 -1
- package/lib/plugins/math/index.js +89 -93
- package/lib/plugins/math/index.js.map +1 -1
- package/lib/plugins/media/index.js +32 -109
- package/lib/plugins/media/index.js.map +1 -1
- package/lib/plugins/media/media-dialog.js +107 -195
- package/lib/plugins/media/media-dialog.js.map +1 -1
- package/lib/plugins/media/media-toolbar.js +7 -27
- package/lib/plugins/media/media-toolbar.js.map +1 -1
- package/lib/plugins/media/media-wrapper.js +9 -14
- package/lib/plugins/media/media-wrapper.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/choice.js +13 -53
- package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/index.js +6 -20
- package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
- package/lib/plugins/respArea/explicit-constructed-response/index.js +5 -10
- package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
- package/lib/plugins/respArea/icons/index.js +16 -31
- package/lib/plugins/respArea/icons/index.js.map +1 -1
- package/lib/plugins/respArea/index.js +7 -54
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/respArea/inline-dropdown/index.js +3 -10
- package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
- package/lib/plugins/respArea/utils.js +6 -21
- package/lib/plugins/respArea/utils.js.map +1 -1
- package/lib/plugins/table/icons/index.js +1 -8
- package/lib/plugins/table/icons/index.js.map +1 -1
- package/lib/plugins/table/index.js +54 -187
- package/lib/plugins/table/index.js.map +1 -1
- package/lib/plugins/table/table-toolbar.js +12 -44
- package/lib/plugins/table/table-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/default-toolbar.js +17 -46
- package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/done-button.js +2 -10
- package/lib/plugins/toolbar/done-button.js.map +1 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js +134 -144
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/index.js +2 -6
- package/lib/plugins/toolbar/index.js.map +1 -1
- package/lib/plugins/toolbar/toolbar-buttons.js +9 -40
- package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
- package/lib/plugins/toolbar/toolbar.js +29 -83
- package/lib/plugins/toolbar/toolbar.js.map +1 -1
- package/lib/plugins/utils.js +8 -30
- package/lib/plugins/utils.js.map +1 -1
- package/lib/serialization.js +11 -69
- package/lib/serialization.js.map +1 -1
- package/lib/test-serializer.js +3 -46
- package/lib/test-serializer.js.map +1 -1
- package/lib/theme.js +1 -1
- package/lib/theme.js.map +1 -1
- package/package.json +7 -7
- package/playground/image/data.js +20 -20
- package/playground/image/index.html +20 -22
- package/playground/image/index.jsx +10 -12
- package/playground/index.html +23 -25
- package/playground/mathquill/index.html +20 -23
- package/playground/mathquill/index.jsx +22 -18
- package/playground/prod-test/index.html +20 -24
- package/playground/prod-test/index.jsx +3 -5
- package/playground/schema-override/data.js +10 -10
- package/playground/schema-override/image-plugin.jsx +4 -3
- package/playground/schema-override/index.html +19 -21
- package/playground/schema-override/index.jsx +14 -13
- package/playground/serialization/data.js +10 -10
- package/playground/serialization/image-plugin.jsx +4 -3
- package/playground/serialization/index.html +20 -22
- package/playground/table-examples.html +8 -5
- package/playground/webpack.config.js +10 -10
- package/src/editor.jsx +108 -104
- package/src/index.jsx +20 -13
- package/src/parse-html.js +1 -1
- package/src/plugins/characters/custom-popper.js +7 -7
- package/src/plugins/characters/index.jsx +34 -23
- package/src/plugins/characters/utils.js +81 -81
- package/src/plugins/image/alt-dialog.jsx +5 -4
- package/src/plugins/image/component.jsx +47 -44
- package/src/plugins/image/image-toolbar.jsx +19 -27
- package/src/plugins/image/index.jsx +24 -18
- package/src/plugins/image/insert-image-handler.js +9 -0
- package/src/plugins/index.jsx +7 -9
- package/src/plugins/list/index.jsx +7 -7
- package/src/plugins/math/index.jsx +71 -28
- package/src/plugins/media/index.jsx +7 -7
- package/src/plugins/media/media-dialog.js +63 -89
- package/src/plugins/media/media-toolbar.jsx +8 -8
- package/src/plugins/media/media-wrapper.jsx +8 -5
- package/src/plugins/respArea/drag-in-the-blank/choice.jsx +19 -21
- package/src/plugins/respArea/drag-in-the-blank/index.jsx +4 -4
- package/src/plugins/respArea/explicit-constructed-response/index.jsx +5 -4
- package/src/plugins/respArea/icons/index.jsx +14 -11
- package/src/plugins/respArea/index.jsx +9 -15
- package/src/plugins/respArea/inline-dropdown/index.jsx +6 -6
- package/src/plugins/respArea/utils.jsx +7 -3
- package/src/plugins/table/icons/index.jsx +11 -17
- package/src/plugins/table/index.jsx +14 -10
- package/src/plugins/table/table-toolbar.jsx +6 -6
- package/src/plugins/toolbar/default-toolbar.jsx +9 -9
- package/src/plugins/toolbar/done-button.jsx +4 -4
- package/src/plugins/toolbar/editor-and-toolbar.jsx +36 -33
- package/src/plugins/toolbar/index.jsx +3 -2
- package/src/plugins/toolbar/toolbar-buttons.jsx +11 -11
- package/src/plugins/toolbar/toolbar.jsx +6 -1
- package/src/plugins/utils.js +2 -2
- package/src/serialization.jsx +34 -32
- package/lib/old-serialization.js +0 -330
- package/lib/slate-editor.js +0 -302
- package/package-lock.json +0 -3762
|
@@ -24,7 +24,7 @@ export class TableToolbar extends React.Component {
|
|
|
24
24
|
onToggleBorder: PropTypes.func.isRequired,
|
|
25
25
|
hasBorder: PropTypes.bool,
|
|
26
26
|
onDone: PropTypes.func.isRequired,
|
|
27
|
-
classes: PropTypes.object.isRequired
|
|
27
|
+
classes: PropTypes.object.isRequired,
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
static defaultProps = {
|
|
@@ -32,7 +32,7 @@ export class TableToolbar extends React.Component {
|
|
|
32
32
|
onChange: () => {}
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
onDone = e => {
|
|
35
|
+
onDone = (e) => {
|
|
36
36
|
const { onDone } = this.props;
|
|
37
37
|
e.preventDefault();
|
|
38
38
|
onDone();
|
|
@@ -50,7 +50,7 @@ export class TableToolbar extends React.Component {
|
|
|
50
50
|
onRemoveTable,
|
|
51
51
|
onToggleBorder,
|
|
52
52
|
hasBorder,
|
|
53
|
-
classes
|
|
53
|
+
classes,
|
|
54
54
|
} = this.props;
|
|
55
55
|
log('[render] hasBorder:', hasBorder);
|
|
56
56
|
|
|
@@ -94,10 +94,10 @@ const styles = () => ({
|
|
|
94
94
|
tableToolbar: {
|
|
95
95
|
width: '100%',
|
|
96
96
|
display: 'flex',
|
|
97
|
-
justifyContent: 'space-between'
|
|
97
|
+
justifyContent: 'space-between',
|
|
98
98
|
},
|
|
99
99
|
toolbarButtons: {
|
|
100
|
-
display: 'flex'
|
|
101
|
-
}
|
|
100
|
+
display: 'flex',
|
|
101
|
+
},
|
|
102
102
|
});
|
|
103
103
|
export default withStyles(styles)(TableToolbar);
|
|
@@ -30,7 +30,7 @@ const isBlockActive = (editor, format) => {
|
|
|
30
30
|
return !!match;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
export const ToolbarButton = props => {
|
|
33
|
+
export const ToolbarButton = (props) => {
|
|
34
34
|
const { editor } = props;
|
|
35
35
|
const onToggle = () => {
|
|
36
36
|
props.onToggle(editor, props);
|
|
@@ -79,7 +79,7 @@ ToolbarButton.propTypes = {
|
|
|
79
79
|
buttonStyles: PropTypes.object,
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
const isActiveToolbarPlugin = props => plugin => {
|
|
82
|
+
const isActiveToolbarPlugin = (props) => plugin => {
|
|
83
83
|
const isDisabled = (props[plugin.name] || {}).disabled;
|
|
84
84
|
|
|
85
85
|
return plugin && plugin.toolbar && !isDisabled;
|
|
@@ -95,9 +95,9 @@ export const DefaultToolbar = ({
|
|
|
95
95
|
onDone,
|
|
96
96
|
classes,
|
|
97
97
|
showDone,
|
|
98
|
-
deletable
|
|
98
|
+
deletable,
|
|
99
99
|
}) => {
|
|
100
|
-
const filtered = plugins.filter(isActiveToolbarPlugin(pluginProps)).map(p => p.toolbar);
|
|
100
|
+
const filtered = plugins.filter(isActiveToolbarPlugin(pluginProps)).map((p) => p.toolbar);
|
|
101
101
|
|
|
102
102
|
return (
|
|
103
103
|
<div className={classes.defaultToolbar}>
|
|
@@ -136,24 +136,24 @@ DefaultToolbar.propTypes = {
|
|
|
136
136
|
onDone: PropTypes.func.isRequired,
|
|
137
137
|
showDone: PropTypes.bool,
|
|
138
138
|
addArea: PropTypes.bool,
|
|
139
|
-
deletable: PropTypes.bool
|
|
139
|
+
deletable: PropTypes.bool,
|
|
140
140
|
};
|
|
141
141
|
|
|
142
142
|
DefaultToolbar.defaultProps = {
|
|
143
|
-
pluginProps: {}
|
|
143
|
+
pluginProps: {},
|
|
144
144
|
};
|
|
145
145
|
|
|
146
146
|
const toolbarStyles = () => ({
|
|
147
147
|
defaultToolbar: {
|
|
148
148
|
display: 'flex',
|
|
149
149
|
width: '100%',
|
|
150
|
-
justifyContent: 'space-between'
|
|
150
|
+
justifyContent: 'space-between',
|
|
151
151
|
},
|
|
152
152
|
buttonsContainer: {
|
|
153
153
|
alignItems: 'center',
|
|
154
154
|
display: 'flex',
|
|
155
|
-
width: '100%'
|
|
156
|
-
}
|
|
155
|
+
width: '100%',
|
|
156
|
+
},
|
|
157
157
|
});
|
|
158
158
|
|
|
159
159
|
export default withStyles(toolbarStyles)(DefaultToolbar);
|
|
@@ -12,7 +12,7 @@ export const RawDoneButton = ({ classes, onClick }) => (
|
|
|
12
12
|
onClick={onClick}
|
|
13
13
|
classes={{
|
|
14
14
|
label: classes.label,
|
|
15
|
-
root: classes.iconRoot
|
|
15
|
+
root: classes.iconRoot,
|
|
16
16
|
}}
|
|
17
17
|
>
|
|
18
18
|
<Check />
|
|
@@ -21,7 +21,7 @@ export const RawDoneButton = ({ classes, onClick }) => (
|
|
|
21
21
|
|
|
22
22
|
RawDoneButton.propTypes = {
|
|
23
23
|
classes: PropTypes.object.isRequired,
|
|
24
|
-
onClick: PropTypes.func
|
|
24
|
+
onClick: PropTypes.func,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
const styles = {
|
|
@@ -30,7 +30,7 @@ const styles = {
|
|
|
30
30
|
width: '28px',
|
|
31
31
|
height: '28px',
|
|
32
32
|
color: 'var(--editable-html-toolbar-check, #00bb00)',
|
|
33
|
-
padding: '4px'
|
|
34
|
-
}
|
|
33
|
+
padding: '4px',
|
|
34
|
+
},
|
|
35
35
|
};
|
|
36
36
|
export const DoneButton = withStyles(styles)(RawDoneButton);
|
|
@@ -10,7 +10,7 @@ import { color } from '@pie-lib/render-ui';
|
|
|
10
10
|
|
|
11
11
|
const log = debug('@pie-lib:editable-html:plugins:toolbar:editor-and-toolbar');
|
|
12
12
|
|
|
13
|
-
const style = {
|
|
13
|
+
const style = (theme) => ({
|
|
14
14
|
root: {
|
|
15
15
|
position: 'relative',
|
|
16
16
|
padding: '0px',
|
|
@@ -22,15 +22,15 @@ const style = {
|
|
|
22
22
|
overflow: 'visible',
|
|
23
23
|
maxHeight: '500px',
|
|
24
24
|
// needed in order to be able to put the focus before a void element when it is the first one in the editor
|
|
25
|
-
padding: '5px'
|
|
25
|
+
padding: '5px',
|
|
26
26
|
},
|
|
27
27
|
'& [data-slate-void="true"]': {
|
|
28
28
|
// needed in order to be able to put the focus before a void element when it is the first one in the editor
|
|
29
|
-
padding: '1px'
|
|
29
|
+
padding: '1px',
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
children: {
|
|
33
|
-
padding: '10px 16px'
|
|
33
|
+
padding: '10px 16px',
|
|
34
34
|
},
|
|
35
35
|
editorHolder: {
|
|
36
36
|
position: 'relative',
|
|
@@ -47,6 +47,7 @@ const style = {
|
|
|
47
47
|
position: 'absolute',
|
|
48
48
|
transition: 'background-color 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
|
|
49
49
|
pointerEvents: 'none',
|
|
50
|
+
backgroundColor: 'rgba(0, 0, 0, 0.42)',
|
|
50
51
|
},
|
|
51
52
|
'&::after': {
|
|
52
53
|
left: '0',
|
|
@@ -56,39 +57,41 @@ const style = {
|
|
|
56
57
|
content: '""',
|
|
57
58
|
position: 'absolute',
|
|
58
59
|
transform: 'scaleX(0)',
|
|
59
|
-
transition:
|
|
60
|
-
|
|
61
|
-
backgroundColor: 'rgba(0, 0, 0, 0.42)'
|
|
60
|
+
transition: 'transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms, background-color 200ms linear',
|
|
61
|
+
backgroundColor: 'rgba(0, 0, 0, 0.42)',
|
|
62
62
|
},
|
|
63
63
|
'&:focus': {
|
|
64
64
|
'&::after': {
|
|
65
65
|
transform: 'scaleX(1)',
|
|
66
66
|
backgroundColor: primary,
|
|
67
|
-
height: '2px'
|
|
68
|
-
}
|
|
67
|
+
height: '2px',
|
|
68
|
+
},
|
|
69
69
|
},
|
|
70
70
|
'&:hover': {
|
|
71
71
|
'&::after': {
|
|
72
72
|
transform: 'scaleX(1)',
|
|
73
|
-
backgroundColor:
|
|
74
|
-
height: '2px'
|
|
75
|
-
}
|
|
73
|
+
backgroundColor: theme.palette.common.black,
|
|
74
|
+
height: '2px',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
'& :focus-visible': {
|
|
78
|
+
outline: 'none !important',
|
|
76
79
|
}
|
|
77
80
|
},
|
|
78
81
|
disabledUnderline: {
|
|
79
82
|
'&::before': {
|
|
80
|
-
display: 'none'
|
|
83
|
+
display: 'none',
|
|
81
84
|
},
|
|
82
85
|
'&::after': {
|
|
83
|
-
display: 'none'
|
|
84
|
-
}
|
|
86
|
+
display: 'none',
|
|
87
|
+
},
|
|
85
88
|
},
|
|
86
89
|
disabledScrollbar: {
|
|
87
90
|
'&::-webkit-scrollbar': {
|
|
88
|
-
display: 'none'
|
|
91
|
+
display: 'none',
|
|
89
92
|
},
|
|
90
93
|
scrollbarWidth: 'none',
|
|
91
|
-
'-ms-overflow-style': 'none'
|
|
94
|
+
'-ms-overflow-style': 'none',
|
|
92
95
|
},
|
|
93
96
|
readOnly: {
|
|
94
97
|
'&::before': {
|
|
@@ -96,7 +99,7 @@ const style = {
|
|
|
96
99
|
backgroundSize: '5px 1px',
|
|
97
100
|
backgroundImage: 'linear-gradient(to right, rgba(0, 0, 0, 0.42) 33%, transparent 0%)',
|
|
98
101
|
backgroundRepeat: 'repeat-x',
|
|
99
|
-
backgroundPosition: 'left top'
|
|
102
|
+
backgroundPosition: 'left top',
|
|
100
103
|
},
|
|
101
104
|
'&::after': {
|
|
102
105
|
left: '0',
|
|
@@ -107,38 +110,38 @@ const style = {
|
|
|
107
110
|
position: 'absolute',
|
|
108
111
|
transform: 'scaleX(0)',
|
|
109
112
|
transition: 'transform 200ms cubic-bezier(0.0, 0.0, 0.2, 1) 0ms, background-color 0ms linear',
|
|
110
|
-
backgroundColor: 'rgba(0, 0, 0, 0)'
|
|
113
|
+
backgroundColor: 'rgba(0, 0, 0, 0)',
|
|
111
114
|
},
|
|
112
115
|
'&:hover': {
|
|
113
116
|
'&::after': {
|
|
114
117
|
transform: 'scaleX(0)',
|
|
115
|
-
backgroundColor:
|
|
116
|
-
height: '2px'
|
|
117
|
-
}
|
|
118
|
-
}
|
|
118
|
+
backgroundColor: theme.palette.common.black,
|
|
119
|
+
height: '2px',
|
|
120
|
+
},
|
|
121
|
+
},
|
|
119
122
|
},
|
|
120
123
|
editorInFocus: {
|
|
121
124
|
'&::after': {
|
|
122
125
|
transform: 'scaleX(1)',
|
|
123
126
|
backgroundColor: primary,
|
|
124
|
-
height: '2px'
|
|
127
|
+
height: '2px',
|
|
125
128
|
},
|
|
126
129
|
'&:hover': {
|
|
127
130
|
'&::after': {
|
|
128
|
-
backgroundColor: primary
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
+
backgroundColor: primary,
|
|
132
|
+
},
|
|
133
|
+
},
|
|
131
134
|
},
|
|
132
135
|
error: {
|
|
133
|
-
border:
|
|
136
|
+
border: `2px solid ${theme.palette.error.main} !important`,
|
|
134
137
|
},
|
|
135
138
|
noBorder: {
|
|
136
|
-
border: 'none'
|
|
139
|
+
border: 'none',
|
|
137
140
|
},
|
|
138
141
|
noPadding: {
|
|
139
|
-
padding: 0
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
+
padding: 0,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
142
145
|
|
|
143
146
|
export const EditorAndToolbar = props => {
|
|
144
147
|
const {
|
|
@@ -249,7 +252,7 @@ EditorAndToolbar.propTypes = {
|
|
|
249
252
|
alwaysVisible: PropTypes.bool,
|
|
250
253
|
error: PropTypes.string,
|
|
251
254
|
noBorder: PropTypes.bool,
|
|
252
|
-
position: PropTypes.oneOf(['bottom', 'top'])
|
|
255
|
+
position: PropTypes.oneOf(['bottom', 'top']),
|
|
253
256
|
})
|
|
254
257
|
};
|
|
255
258
|
|
|
@@ -9,14 +9,15 @@ import EditorAndToolbar from './editor-and-toolbar';
|
|
|
9
9
|
export default function ToolbarPlugin(opts) {
|
|
10
10
|
return {
|
|
11
11
|
/* eslint-disable-next-line */
|
|
12
|
-
renderEditor: props => (
|
|
12
|
+
renderEditor: (props) => (
|
|
13
13
|
<EditorAndToolbar
|
|
14
14
|
{...props}
|
|
15
15
|
mainEditorRef={opts.mainEditorRef}
|
|
16
16
|
disableScrollbar={opts.disableScrollbar}
|
|
17
17
|
disableUnderline={opts.disableUnderline}
|
|
18
|
+
autoWidth={opts.autoWidth}
|
|
18
19
|
onDone={opts.onDone}
|
|
19
20
|
/>
|
|
20
|
-
)
|
|
21
|
+
),
|
|
21
22
|
};
|
|
22
23
|
}
|
|
@@ -10,19 +10,19 @@ const styles = () => ({
|
|
|
10
10
|
display: 'inline-flex',
|
|
11
11
|
padding: '2px',
|
|
12
12
|
'& :hover': {
|
|
13
|
-
color: 'black'
|
|
14
|
-
}
|
|
13
|
+
color: 'black',
|
|
14
|
+
},
|
|
15
15
|
},
|
|
16
16
|
active: {
|
|
17
|
-
color: 'black'
|
|
17
|
+
color: 'black',
|
|
18
18
|
},
|
|
19
19
|
disabled: {
|
|
20
20
|
opacity: 0.7,
|
|
21
21
|
cursor: 'not-allowed',
|
|
22
22
|
'& :hover': {
|
|
23
|
-
color: 'grey'
|
|
24
|
-
}
|
|
25
|
-
}
|
|
23
|
+
color: 'grey',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
const log = debug('pie-elements:editable-html:raw-button');
|
|
@@ -34,14 +34,14 @@ export class RawButton extends React.Component {
|
|
|
34
34
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
35
35
|
active: PropTypes.bool,
|
|
36
36
|
disabled: PropTypes.bool,
|
|
37
|
-
extraStyles: PropTypes.object
|
|
37
|
+
extraStyles: PropTypes.object,
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
constructor(props) {
|
|
41
41
|
super(props);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
onClick = e => {
|
|
44
|
+
onClick = (e) => {
|
|
45
45
|
log('[onClick]');
|
|
46
46
|
e.preventDefault();
|
|
47
47
|
const { onClick } = this.props;
|
|
@@ -52,7 +52,7 @@ export class RawButton extends React.Component {
|
|
|
52
52
|
const { active, classes, children, disabled, extraStyles } = this.props;
|
|
53
53
|
const names = classNames(classes.button, {
|
|
54
54
|
[classes.active]: active,
|
|
55
|
-
[classes.disabled]: disabled
|
|
55
|
+
[classes.disabled]: disabled,
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
return (
|
|
@@ -71,14 +71,14 @@ export class RawMarkButton extends React.Component {
|
|
|
71
71
|
mark: PropTypes.string,
|
|
72
72
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
73
73
|
classes: PropTypes.object.isRequired,
|
|
74
|
-
active: PropTypes.bool
|
|
74
|
+
active: PropTypes.bool,
|
|
75
75
|
};
|
|
76
76
|
|
|
77
77
|
constructor(props) {
|
|
78
78
|
super(props);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
onToggle = e => {
|
|
81
|
+
onToggle = (e) => {
|
|
82
82
|
e.preventDefault();
|
|
83
83
|
this.props.onToggle(this.props.mark);
|
|
84
84
|
};
|
|
@@ -169,6 +169,11 @@ export const Toolbar = props => {
|
|
|
169
169
|
return null;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
+
// this means we have selected text
|
|
173
|
+
if (selection.anchor.offset !== selection.focus.offset) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
172
177
|
const [node, path] = Editor.node(editor, selection, depth ? { depth } : undefined);
|
|
173
178
|
|
|
174
179
|
if (!node) {
|
|
@@ -263,7 +268,7 @@ export const Toolbar = props => {
|
|
|
263
268
|
[classes.toolbarRight]: toolbarOpts.alignment === 'right',
|
|
264
269
|
[classes.focused]: toolbarOpts.alwaysVisible || isFocused,
|
|
265
270
|
[classes.autoWidth]: autoWidth,
|
|
266
|
-
[classes.fullWidth]: !autoWidth
|
|
271
|
+
[classes.fullWidth]: !autoWidth,
|
|
267
272
|
});
|
|
268
273
|
|
|
269
274
|
return (
|
package/src/plugins/utils.js
CHANGED
|
@@ -26,9 +26,9 @@ export const findParentNode = (value, node) => {
|
|
|
26
26
|
return value.document.getParent(node.key);
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
export const hasMark = (value, type) => value && value.marks.some(mark => mark.type == type);
|
|
29
|
+
export const hasMark = (value, type) => value && value.marks.some((mark) => mark.type == type);
|
|
30
30
|
|
|
31
|
-
export const hasBlock = (value, type) => value && value.blocks.some(node => node.type == type);
|
|
31
|
+
export const hasBlock = (value, type) => value && value.blocks.some((node) => node.type == type);
|
|
32
32
|
|
|
33
33
|
export const isBlockActive = (editor, format, blockType = 'type') => {
|
|
34
34
|
const { selection } = editor;
|
package/src/serialization.jsx
CHANGED
|
@@ -30,7 +30,7 @@ export const BLOCK_TAGS = {
|
|
|
30
30
|
h3: 'heading-three',
|
|
31
31
|
h4: 'heading-four',
|
|
32
32
|
h5: 'heading-five',
|
|
33
|
-
h6: 'heading-six'
|
|
33
|
+
h6: 'heading-six',
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
/**
|
|
@@ -45,10 +45,10 @@ const MARK_TAGS = {
|
|
|
45
45
|
u: 'underline',
|
|
46
46
|
s: 'strikethrough',
|
|
47
47
|
code: 'code',
|
|
48
|
-
strong: 'bold'
|
|
48
|
+
strong: 'bold',
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
export const parseStyleString = s => {
|
|
51
|
+
export const parseStyleString = (s) => {
|
|
52
52
|
const regex = /([\w-]*)\s*:\s*([^;]*)/g;
|
|
53
53
|
let match;
|
|
54
54
|
const result = {};
|
|
@@ -58,18 +58,18 @@ export const parseStyleString = s => {
|
|
|
58
58
|
return result;
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
export const getBase64 = file => {
|
|
61
|
+
export const getBase64 = (file) => {
|
|
62
62
|
return new Promise((resolve, reject) => {
|
|
63
63
|
const reader = new FileReader();
|
|
64
64
|
reader.readAsDataURL(file);
|
|
65
65
|
reader.onload = () => resolve(reader.result);
|
|
66
|
-
reader.onerror = error => reject(error);
|
|
66
|
+
reader.onerror = (error) => reject(error);
|
|
67
67
|
});
|
|
68
68
|
};
|
|
69
69
|
|
|
70
|
-
export const reactAttributes = o => toStyleObject(o, { camelize: true, addUnits: false });
|
|
70
|
+
export const reactAttributes = (o) => toStyleObject(o, { camelize: true, addUnits: false });
|
|
71
71
|
|
|
72
|
-
const attributesToMap = el => (acc, attribute) => {
|
|
72
|
+
const attributesToMap = (el) => (acc, attribute) => {
|
|
73
73
|
const value = el.getAttribute(attribute);
|
|
74
74
|
if (value) {
|
|
75
75
|
if (attribute === 'style') {
|
|
@@ -113,7 +113,7 @@ const blocks = {
|
|
|
113
113
|
* Here for rendering styles for all block elements
|
|
114
114
|
*/
|
|
115
115
|
data: { attributes: attributes.reduce(attributesToMap(el), {}) },
|
|
116
|
-
nodes: next(el.childNodes)
|
|
116
|
+
nodes: next(el.childNodes),
|
|
117
117
|
};
|
|
118
118
|
},
|
|
119
119
|
serialize: (object, children) => {
|
|
@@ -131,7 +131,7 @@ const blocks = {
|
|
|
131
131
|
return <Tag {...jsonData.attributes}>{children}</Tag>;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
}
|
|
134
|
+
},
|
|
135
135
|
};
|
|
136
136
|
|
|
137
137
|
const marks = {
|
|
@@ -142,7 +142,7 @@ const marks = {
|
|
|
142
142
|
return {
|
|
143
143
|
object: 'mark',
|
|
144
144
|
type: mark,
|
|
145
|
-
nodes: next(el.childNodes)
|
|
145
|
+
nodes: next(el.childNodes),
|
|
146
146
|
};
|
|
147
147
|
},
|
|
148
148
|
serialize(object, children) {
|
|
@@ -154,10 +154,11 @@ const marks = {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
}
|
|
157
|
+
},
|
|
158
158
|
};
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
// eslint-disable-next-line no-unused-vars
|
|
161
|
+
const findPreviousText = (el) => {
|
|
161
162
|
if (el.nodeName === '#text') {
|
|
162
163
|
return el;
|
|
163
164
|
}
|
|
@@ -182,9 +183,9 @@ export const TEXT_RULE = {
|
|
|
182
183
|
leaves: [
|
|
183
184
|
{
|
|
184
185
|
object: 'leaf',
|
|
185
|
-
text: '\n'
|
|
186
|
-
}
|
|
187
|
-
]
|
|
186
|
+
text: '\n',
|
|
187
|
+
},
|
|
188
|
+
],
|
|
188
189
|
};
|
|
189
190
|
}
|
|
190
191
|
|
|
@@ -197,9 +198,9 @@ export const TEXT_RULE = {
|
|
|
197
198
|
leaves: [
|
|
198
199
|
{
|
|
199
200
|
object: 'leaf',
|
|
200
|
-
text: el.nodeValue
|
|
201
|
-
}
|
|
202
|
-
]
|
|
201
|
+
text: el.nodeValue,
|
|
202
|
+
},
|
|
203
|
+
],
|
|
203
204
|
};
|
|
204
205
|
}
|
|
205
206
|
},
|
|
@@ -212,7 +213,7 @@ export const TEXT_RULE = {
|
|
|
212
213
|
return array;
|
|
213
214
|
}, []);
|
|
214
215
|
}
|
|
215
|
-
}
|
|
216
|
+
},
|
|
216
217
|
};
|
|
217
218
|
|
|
218
219
|
const RULES = [
|
|
@@ -224,7 +225,7 @@ const RULES = [
|
|
|
224
225
|
responseAreaSerialization,
|
|
225
226
|
TEXT_RULE,
|
|
226
227
|
blocks,
|
|
227
|
-
marks
|
|
228
|
+
marks,
|
|
228
229
|
];
|
|
229
230
|
|
|
230
231
|
function allWhitespace(node) {
|
|
@@ -235,7 +236,7 @@ function allWhitespace(node) {
|
|
|
235
236
|
function defaultParseHtml(html) {
|
|
236
237
|
if (typeof DOMParser === 'undefined') {
|
|
237
238
|
throw new Error(
|
|
238
|
-
'The native `DOMParser` global which the `Html` serializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead.'
|
|
239
|
+
'The native `DOMParser` global which the `Html` serializer uses by default is not present in this environment. You must supply the `options.parseHtml` function instead.',
|
|
239
240
|
);
|
|
240
241
|
}
|
|
241
242
|
|
|
@@ -259,14 +260,14 @@ function defaultParseHtml(html) {
|
|
|
259
260
|
const parseHtml =
|
|
260
261
|
typeof window === 'undefined'
|
|
261
262
|
? () => ({
|
|
262
|
-
childNodes: []
|
|
263
|
+
childNodes: [],
|
|
263
264
|
})
|
|
264
265
|
: defaultParseHtml;
|
|
265
266
|
|
|
266
267
|
const serializer = new Html({
|
|
267
268
|
defaultBlock: 'div',
|
|
268
269
|
rules: RULES,
|
|
269
|
-
parseHtml
|
|
270
|
+
parseHtml,
|
|
270
271
|
});
|
|
271
272
|
|
|
272
273
|
const _extends =
|
|
@@ -320,7 +321,7 @@ serializer.deserialize = function deserialize(html) {
|
|
|
320
321
|
}
|
|
321
322
|
|
|
322
323
|
const block = _extends({ object: 'block', data: {}, isVoid: false }, defaultBlock, {
|
|
323
|
-
nodes: [node]
|
|
324
|
+
nodes: [node],
|
|
324
325
|
});
|
|
325
326
|
|
|
326
327
|
memo.push(block);
|
|
@@ -330,8 +331,8 @@ serializer.deserialize = function deserialize(html) {
|
|
|
330
331
|
if (nodes.length === 0) {
|
|
331
332
|
nodes = [
|
|
332
333
|
_extends({ object: 'block', data: {}, isVoid: false }, defaultBlock, {
|
|
333
|
-
nodes: [{ object: 'text', leaves: [{ object: 'leaf', text: '', marks: [] }] }]
|
|
334
|
-
})
|
|
334
|
+
nodes: [{ object: 'text', leaves: [{ object: 'leaf', text: '', marks: [] }] }],
|
|
335
|
+
}),
|
|
335
336
|
];
|
|
336
337
|
}
|
|
337
338
|
|
|
@@ -340,11 +341,11 @@ serializer.deserialize = function deserialize(html) {
|
|
|
340
341
|
document: {
|
|
341
342
|
object: 'document',
|
|
342
343
|
data: {},
|
|
343
|
-
nodes: nodes
|
|
344
|
+
nodes: nodes,
|
|
344
345
|
},
|
|
345
346
|
schema: {
|
|
346
|
-
rules: []
|
|
347
|
-
}
|
|
347
|
+
rules: [],
|
|
348
|
+
},
|
|
348
349
|
};
|
|
349
350
|
|
|
350
351
|
let i;
|
|
@@ -352,7 +353,7 @@ serializer.deserialize = function deserialize(html) {
|
|
|
352
353
|
for (i = 0; i < 3000; i++) {
|
|
353
354
|
json.schema.rules.push({
|
|
354
355
|
match: { object: 'document' },
|
|
355
|
-
nodes: [{ match: { object: 'block' } }]
|
|
356
|
+
nodes: [{ match: { object: 'block' } }],
|
|
356
357
|
});
|
|
357
358
|
}
|
|
358
359
|
|
|
@@ -365,16 +366,17 @@ serializer.deserialize = function deserialize(html) {
|
|
|
365
366
|
return null;
|
|
366
367
|
};
|
|
367
368
|
|
|
368
|
-
export const htmlToValue = html => {
|
|
369
|
+
export const htmlToValue = (html) => {
|
|
369
370
|
try {
|
|
370
371
|
return serializer.deserialize(html);
|
|
371
372
|
} catch (e) {
|
|
373
|
+
// eslint-disable-next-line no-console
|
|
372
374
|
console.log("Couldn't parse html: ", e);
|
|
373
375
|
return {};
|
|
374
376
|
}
|
|
375
377
|
};
|
|
376
378
|
|
|
377
|
-
export const valueToHtml = value => serializer.serialize(value);
|
|
379
|
+
export const valueToHtml = (value) => serializer.serialize(value);
|
|
378
380
|
|
|
379
381
|
/**
|
|
380
382
|
*
|