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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/lib/components/CharacterPicker.js +221 -0
  2. package/lib/components/CharacterPicker.js.map +1 -0
  3. package/lib/components/EditableHtml.js +323 -0
  4. package/lib/components/EditableHtml.js.map +1 -0
  5. package/lib/components/MenuBar.js +694 -0
  6. package/lib/components/MenuBar.js.map +1 -0
  7. package/lib/components/TiptapContainer.js +90 -0
  8. package/lib/components/TiptapContainer.js.map +1 -0
  9. package/lib/components/buttons/done-button.js +53 -0
  10. package/lib/components/characters/characterUtils.js +112 -0
  11. package/lib/components/characters/characterUtils.js.map +1 -0
  12. package/lib/components/characters/custom-popper.js +73 -0
  13. package/lib/components/characters/custom-popper.js.map +1 -0
  14. package/lib/components/common/done-button.js +53 -0
  15. package/lib/components/common/done-button.js.map +1 -0
  16. package/lib/components/common/toolbar-buttons.js +194 -0
  17. package/lib/components/icons/CssIcon.js +37 -0
  18. package/lib/components/icons/CssIcon.js.map +1 -0
  19. package/lib/components/icons/RespArea.js +95 -0
  20. package/lib/components/icons/RespArea.js.map +1 -0
  21. package/lib/components/icons/TableIcons.js +69 -0
  22. package/lib/components/icons/TableIcons.js.map +1 -0
  23. package/lib/components/icons/TextAlign.js +194 -0
  24. package/lib/components/icons/TextAlign.js.map +1 -0
  25. package/lib/components/icons/index.js +194 -0
  26. package/lib/components/image/AltDialog.js +129 -0
  27. package/lib/components/image/ImageToolbar.js +177 -0
  28. package/lib/components/image/ImageToolbar.js.map +1 -0
  29. package/lib/components/image/InsertImageHandler.js +115 -0
  30. package/lib/components/image/InsertImageHandler.js.map +1 -0
  31. package/lib/components/image/alt-dialog.js +2 -0
  32. package/lib/components/media/MediaDialog.js +709 -0
  33. package/lib/components/media/MediaDialog.js.map +1 -0
  34. package/lib/components/media/MediaToolbar.js +101 -0
  35. package/lib/components/media/MediaToolbar.js.map +1 -0
  36. package/lib/components/media/MediaWrapper.js +93 -0
  37. package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js +94 -0
  38. package/lib/components/respArea/DragInTheBlank/DragInTheBlank.js.map +1 -0
  39. package/lib/components/respArea/DragInTheBlank/choice.js +289 -0
  40. package/lib/components/respArea/DragInTheBlank/choice.js.map +1 -0
  41. package/lib/components/respArea/DragInTheBlank.js +94 -0
  42. package/lib/components/respArea/ExplicitConstructedResponse.js +120 -0
  43. package/lib/components/respArea/ExplicitConstructedResponse.js.map +1 -0
  44. package/lib/components/respArea/InlineDropdown.js +126 -0
  45. package/lib/components/respArea/InlineDropdown.js.map +1 -0
  46. package/lib/components/respArea/ToolbarIcon.js +105 -0
  47. package/lib/components/respArea/ToolbarIcon.js.map +1 -0
  48. package/lib/components/respArea/choice.js +2 -0
  49. package/lib/constants.js.map +1 -0
  50. package/lib/extensions/component.js +5 -5
  51. package/lib/extensions/component.js.map +1 -0
  52. package/lib/extensions/css.js.map +1 -0
  53. package/lib/extensions/custom-toolbar-wrapper.js +2 -4
  54. package/lib/extensions/custom-toolbar-wrapper.js.map +1 -0
  55. package/lib/extensions/extended-table.js +30 -0
  56. package/lib/extensions/extended-table.js.map +1 -0
  57. package/lib/extensions/image.js +2 -8
  58. package/lib/extensions/image.js.map +1 -0
  59. package/lib/extensions/index.js +52 -0
  60. package/lib/extensions/index.js.map +1 -0
  61. package/lib/extensions/math.js.map +1 -0
  62. package/lib/extensions/media.js +7 -7
  63. package/lib/extensions/media.js.map +1 -0
  64. package/lib/extensions/responseArea.js +7 -7
  65. package/lib/extensions/responseArea.js.map +1 -0
  66. package/lib/index.js +16 -1481
  67. package/lib/index.js.map +1 -0
  68. package/lib/plugins/index.js +8 -80
  69. package/lib/styles/editorContainerStyles.js +200 -0
  70. package/lib/styles/editorContainerStyles.js.map +1 -0
  71. package/lib/theme.js.map +1 -0
  72. package/lib/utils/size.js +34 -0
  73. package/lib/utils/size.js.map +1 -0
  74. package/package.json +1 -1
  75. package/src/components/CharacterPicker.jsx +185 -0
  76. package/src/components/EditableHtml.jsx +306 -0
  77. package/src/components/MenuBar.jsx +630 -0
  78. package/src/components/TiptapContainer.jsx +96 -0
  79. package/src/components/characters/characterUtils.js +127 -0
  80. package/src/{plugins/image/image-toolbar.jsx → components/image/ImageToolbar.jsx} +2 -2
  81. package/src/{plugins/image/insert-image-handler.js → components/image/InsertImageHandler.js} +0 -1
  82. package/src/{plugins/media/media-dialog.js → components/media/MediaDialog.js} +2 -2
  83. package/src/{plugins/respArea/drag-in-the-blank → components/respArea/DragInTheBlank}/choice.jsx +1 -1
  84. package/src/{plugins/respArea/inline-dropdown/index.jsx → components/respArea/InlineDropdown.jsx} +1 -1
  85. package/src/components/respArea/ToolbarIcon.jsx +68 -0
  86. package/src/extensions/component.jsx +2 -2
  87. package/src/extensions/custom-toolbar-wrapper.jsx +6 -7
  88. package/src/extensions/extended-table.js +27 -0
  89. package/src/extensions/image.js +2 -2
  90. package/src/extensions/index.js +76 -0
  91. package/src/extensions/media.js +12 -7
  92. package/src/extensions/responseArea.js +7 -7
  93. package/src/index.jsx +3 -1440
  94. package/src/styles/editorContainerStyles.js +203 -0
  95. package/src/utils/size.js +32 -0
  96. package/src/__tests__/editor.test.jsx +0 -363
  97. package/src/__tests__/serialization.test.js +0 -291
  98. package/src/block-tags.js +0 -17
  99. package/src/editor.jsx +0 -1197
  100. package/src/extensions/characters.js +0 -46
  101. package/src/old-index.jsx +0 -162
  102. package/src/parse-html.js +0 -8
  103. package/src/plugins/README.md +0 -27
  104. package/src/plugins/characters/index.jsx +0 -284
  105. package/src/plugins/characters/utils.js +0 -447
  106. package/src/plugins/css/index.jsx +0 -340
  107. package/src/plugins/customPlugin/index.jsx +0 -85
  108. package/src/plugins/html/icons/index.jsx +0 -19
  109. package/src/plugins/html/index.jsx +0 -72
  110. package/src/plugins/image/__tests__/__snapshots__/component.test.jsx.snap +0 -51
  111. package/src/plugins/image/__tests__/__snapshots__/image-toolbar-logic.test.jsx.snap +0 -27
  112. package/src/plugins/image/__tests__/__snapshots__/image-toolbar.test.jsx.snap +0 -44
  113. package/src/plugins/image/__tests__/component.test.jsx +0 -41
  114. package/src/plugins/image/__tests__/image-toolbar-logic.test.jsx +0 -42
  115. package/src/plugins/image/__tests__/image-toolbar.test.jsx +0 -11
  116. package/src/plugins/image/__tests__/index.test.js +0 -95
  117. package/src/plugins/image/__tests__/insert-image-handler.test.js +0 -113
  118. package/src/plugins/image/__tests__/mock-change.js +0 -15
  119. package/src/plugins/image/component.jsx +0 -343
  120. package/src/plugins/image/index.jsx +0 -227
  121. package/src/plugins/index.jsx +0 -377
  122. package/src/plugins/list/__tests__/index.test.js +0 -54
  123. package/src/plugins/list/index.jsx +0 -305
  124. package/src/plugins/math/__tests__/__snapshots__/index.test.jsx.snap +0 -48
  125. package/src/plugins/math/__tests__/index.test.jsx +0 -245
  126. package/src/plugins/math/index.jsx +0 -379
  127. package/src/plugins/media/__tests__/index.test.js +0 -75
  128. package/src/plugins/media/index.jsx +0 -325
  129. package/src/plugins/rendering/index.js +0 -31
  130. package/src/plugins/respArea/index.jsx +0 -299
  131. package/src/plugins/respArea/math-templated/index.jsx +0 -104
  132. package/src/plugins/respArea/utils.jsx +0 -90
  133. package/src/plugins/table/CustomTablePlugin.js +0 -113
  134. package/src/plugins/table/__tests__/__snapshots__/table-toolbar.test.jsx.snap +0 -44
  135. package/src/plugins/table/__tests__/index.test.jsx +0 -401
  136. package/src/plugins/table/__tests__/table-toolbar.test.jsx +0 -42
  137. package/src/plugins/table/index.jsx +0 -427
  138. package/src/plugins/table/table-toolbar.jsx +0 -136
  139. package/src/plugins/textAlign/index.jsx +0 -23
  140. package/src/plugins/toolbar/__tests__/__snapshots__/default-toolbar.test.jsx.snap +0 -923
  141. package/src/plugins/toolbar/__tests__/__snapshots__/editor-and-toolbar.test.jsx.snap +0 -20
  142. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar-buttons.test.jsx.snap +0 -36
  143. package/src/plugins/toolbar/__tests__/__snapshots__/toolbar.test.jsx.snap +0 -46
  144. package/src/plugins/toolbar/__tests__/default-toolbar.test.jsx +0 -94
  145. package/src/plugins/toolbar/__tests__/editor-and-toolbar.test.jsx +0 -37
  146. package/src/plugins/toolbar/__tests__/toolbar-buttons.test.jsx +0 -51
  147. package/src/plugins/toolbar/__tests__/toolbar.test.jsx +0 -106
  148. package/src/plugins/toolbar/default-toolbar.jsx +0 -206
  149. package/src/plugins/toolbar/editor-and-toolbar.jsx +0 -257
  150. package/src/plugins/toolbar/index.jsx +0 -23
  151. package/src/plugins/toolbar/toolbar.jsx +0 -338
  152. package/src/plugins/utils.js +0 -31
  153. package/src/serialization.jsx +0 -621
  154. /package/src/{plugins → components}/characters/custom-popper.js +0 -0
  155. /package/src/{plugins/toolbar → components/common}/done-button.jsx +0 -0
  156. /package/src/{plugins/toolbar → components/common}/toolbar-buttons.jsx +0 -0
  157. /package/src/{plugins/css/icons/index.jsx → components/icons/CssIcon.jsx} +0 -0
  158. /package/src/{plugins/respArea/icons/index.jsx → components/icons/RespArea.jsx} +0 -0
  159. /package/src/{plugins/table/icons/index.jsx → components/icons/TableIcons.jsx} +0 -0
  160. /package/src/{plugins/textAlign/icons/index.jsx → components/icons/TextAlign.jsx} +0 -0
  161. /package/src/{plugins/image/alt-dialog.jsx → components/image/AltDialog.jsx} +0 -0
  162. /package/src/{plugins/media/media-toolbar.jsx → components/media/MediaToolbar.jsx} +0 -0
  163. /package/src/{plugins/media/media-wrapper.jsx → components/media/MediaWrapper.jsx} +0 -0
  164. /package/src/{plugins/respArea/drag-in-the-blank/index.jsx → components/respArea/DragInTheBlank/DragInTheBlank.jsx} +0 -0
  165. /package/src/{plugins/respArea/explicit-constructed-response/index.jsx → components/respArea/ExplicitConstructedResponse.jsx} +0 -0
@@ -1,257 +0,0 @@
1
- import React from 'react';
2
- import Toolbar from './toolbar';
3
- import classNames from 'classnames';
4
- import debug from 'debug';
5
- import { primary } from '../../theme';
6
- import { withStyles } from '@material-ui/core/styles';
7
- import PropTypes from 'prop-types';
8
- import SlatePropTypes from 'slate-prop-types';
9
- import { color } from '@pie-lib/render-ui';
10
-
11
- const log = debug('@pie-lib:editable-html:plugins:toolbar:editor-and-toolbar');
12
-
13
- export class EditorAndToolbar extends React.Component {
14
- static propTypes = {
15
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
16
- value: SlatePropTypes.value.isRequired,
17
- plugins: PropTypes.array.isRequired,
18
- onChange: PropTypes.func.isRequired,
19
- getFocusedValue: PropTypes.func.isRequired,
20
- onDone: PropTypes.func.isRequired,
21
- onDataChange: PropTypes.func,
22
- toolbarRef: PropTypes.func,
23
- focusedNode: SlatePropTypes.node,
24
- readOnly: PropTypes.bool,
25
- disableScrollbar: PropTypes.bool,
26
- disableUnderline: PropTypes.bool,
27
- autoWidth: PropTypes.bool,
28
- classes: PropTypes.object.isRequired,
29
- pluginProps: PropTypes.object,
30
- toolbarOpts: PropTypes.shape({
31
- position: PropTypes.oneOf(['bottom', 'top']),
32
- alwaysVisible: PropTypes.bool,
33
- error: PropTypes.string,
34
- noBorder: PropTypes.any,
35
- noPadding: PropTypes.any,
36
- }),
37
- focusToolbar: PropTypes.bool.isRequired,
38
- onToolbarFocus: PropTypes.func.isRequired,
39
- onToolbarBlur: PropTypes.func.isRequired,
40
- doneButtonRef: PropTypes.func,
41
- };
42
-
43
- render() {
44
- const {
45
- classes,
46
- children,
47
- value,
48
- plugins,
49
- onChange,
50
- getFocusedValue,
51
- onDone,
52
- focusedNode,
53
- autoWidth,
54
- readOnly,
55
- disableScrollbar,
56
- disableUnderline,
57
- pluginProps,
58
- toolbarOpts,
59
- onDataChange,
60
- toolbarRef,
61
- doneButtonRef,
62
- focusToolbar,
63
- onToolbarFocus,
64
- onToolbarBlur,
65
- } = this.props;
66
-
67
- let inFocus = value.isFocused || (focusedNode !== null && focusedNode !== undefined) || focusToolbar;
68
-
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
- let clonedChildren = children;
77
-
78
- if (typeof children !== 'string') {
79
- clonedChildren = React.cloneElement(children, {
80
- ref: (el) => (this.editorRef = el),
81
- });
82
- }
83
-
84
- log('[render] inFocus: ', inFocus, 'value.isFocused:', value.isFocused, 'focused node: ', focusedNode);
85
-
86
- return (
87
- <div
88
- className={classNames(
89
- {
90
- [classes.noBorder]: toolbarOpts && toolbarOpts.noBorder,
91
- [classes.error]: toolbarOpts && toolbarOpts.error,
92
- },
93
- classes.root,
94
- )}
95
- >
96
- <div className={holderNames}>
97
- <div
98
- className={classNames(
99
- {
100
- [classes.noPadding]: toolbarOpts && toolbarOpts.noPadding,
101
- },
102
- classes.children,
103
- )}
104
- >
105
- {clonedChildren}
106
- </div>
107
- </div>
108
-
109
- <Toolbar
110
- autoWidth={autoWidth}
111
- plugins={plugins}
112
- focusedNode={focusedNode}
113
- value={value}
114
- isFocused={inFocus}
115
- onBlur={onToolbarBlur}
116
- onFocus={onToolbarFocus}
117
- onChange={onChange}
118
- getFocusedValue={getFocusedValue}
119
- onDone={onDone}
120
- onDataChange={onDataChange}
121
- toolbarRef={toolbarRef}
122
- doneButtonRef={doneButtonRef}
123
- pluginProps={pluginProps}
124
- toolbarOpts={toolbarOpts}
125
- />
126
- </div>
127
- );
128
- }
129
- }
130
-
131
- const style = (theme) => ({
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);
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
-
3
- import EditorAndToolbar from './editor-and-toolbar';
4
-
5
- /**
6
- * Adds a toolbar which is shown when the editor is focused.
7
- * @param {*} opts
8
- */
9
- export default function ToolbarPlugin(opts) {
10
- return {
11
- /* eslint-disable-next-line */
12
- renderEditor: (props) => (
13
- <EditorAndToolbar
14
- {...props}
15
- mainEditorRef={opts.mainEditorRef}
16
- disableScrollbar={opts.disableScrollbar}
17
- disableUnderline={opts.disableUnderline}
18
- autoWidth={opts.autoWidth}
19
- onDone={opts.onDone}
20
- />
21
- ),
22
- };
23
- }
@@ -1,338 +0,0 @@
1
- import React from 'react';
2
- import { Change } from 'slate';
3
- import Delete from '@material-ui/icons/Delete';
4
- import IconButton from '@material-ui/core/IconButton';
5
- import PropTypes from 'prop-types';
6
- import classNames from 'classnames';
7
- import debug from 'debug';
8
- import SlatePropTypes from 'slate-prop-types';
9
- import debounce from 'lodash/debounce';
10
-
11
- import { DoneButton } from './done-button';
12
-
13
- import { findSingleNode, findParentNode } from '../utils';
14
- import { withStyles } from '@material-ui/core/styles';
15
- import DefaultToolbar from './default-toolbar';
16
- import { removeDialogs as removeCharacterDialogs } from '../characters';
17
- import { PIE_TOOLBAR__CLASS } from '../../constants';
18
-
19
- const log = debug('@pie-lib:editable-html:plugins:toolbar');
20
-
21
- const getCustomToolbar = (plugin, node, value, handleDone, getFocusedValue, onDataChange) => {
22
- if (!plugin) {
23
- return;
24
- }
25
-
26
- if (!plugin.toolbar) {
27
- return;
28
- }
29
-
30
- if (plugin.toolbar.CustomToolbarComp) {
31
- /**
32
- * Using a pre-defined Component should be preferred
33
- * as the rendering of it (and it's children) can be optimized by React.
34
- * If you keep re-defining the comp with an inline function
35
- * then react will have to re-render.
36
- */
37
- return plugin.toolbar.CustomToolbarComp;
38
- } else if (typeof plugin.toolbar.customToolbar === 'function') {
39
- log('deprecated - use CustomToolbarComp');
40
- return plugin.toolbar.customToolbar(node, value, handleDone, getFocusedValue, onDataChange);
41
- }
42
- };
43
-
44
- export class Toolbar extends React.Component {
45
- static propTypes = {
46
- zIndex: PropTypes.number,
47
- value: SlatePropTypes.value.isRequired,
48
- plugins: PropTypes.array,
49
- plugin: PropTypes.object,
50
- onImageClick: PropTypes.func,
51
- onDone: PropTypes.func.isRequired,
52
- toolbarRef: PropTypes.func.isRequired,
53
- classes: PropTypes.object.isRequired,
54
- isFocused: PropTypes.bool,
55
- autoWidth: PropTypes.bool,
56
- onChange: PropTypes.func.isRequired,
57
- getFocusedValue: PropTypes.func.isRequired,
58
- pluginProps: PropTypes.object,
59
- toolbarOpts: PropTypes.shape({
60
- position: PropTypes.oneOf(['bottom', 'top']),
61
- alignment: PropTypes.oneOf(['left', 'right']),
62
- alwaysVisible: PropTypes.bool,
63
- ref: PropTypes.func,
64
- showDone: PropTypes.bool,
65
- minWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
66
- isHidden: PropTypes.bool,
67
- }),
68
- onDataChange: PropTypes.func,
69
- doneButtonRef: PropTypes.func,
70
- onBlur: PropTypes.func,
71
- onFocus: PropTypes.func,
72
- };
73
-
74
- constructor(props) {
75
- super(props);
76
- this.state = {
77
- change: null,
78
- };
79
- }
80
-
81
- componentWillUnmount() {
82
- removeCharacterDialogs();
83
- }
84
-
85
- hasMark = (type) => {
86
- const { value } = this.props;
87
- return value.marks.some((mark) => mark.type == type);
88
- };
89
-
90
- hasBlock = (type) => {
91
- const { value } = this.props;
92
- return value.blocks.some((node) => node.type == type);
93
- };
94
-
95
- onToggle = (plugin) => {
96
- const { value, onChange } = this.props;
97
-
98
- if (!plugin.onToggle) return;
99
-
100
- const change = plugin.onToggle(value.change());
101
- onChange(change);
102
- };
103
-
104
- onClick = (e) => {
105
- log('[onClick]');
106
- e.preventDefault();
107
- };
108
-
109
- onButtonClick = (fn) => {
110
- return (e) => {
111
- e.preventDefault();
112
- fn();
113
- };
114
- };
115
-
116
- onToolbarDone = (change, finishEditing) => {
117
- log('[onToolbarDone] change: ', change, 'finishEditing: ', finishEditing);
118
- const { onChange, onDone } = this.props;
119
-
120
- // use handler only if this is an actual Slate Change
121
- if (change instanceof Change) {
122
- onChange(change, () => {
123
- if (finishEditing) {
124
- onDone();
125
- }
126
- });
127
- } else {
128
- if (finishEditing) {
129
- log('[onToolbarChange] call onDone');
130
- onDone();
131
- }
132
- }
133
- };
134
-
135
- onDeleteClick = debounce((e, plugin, node, value, onChange) => plugin.deleteNode(e, node, value, onChange), 500);
136
-
137
- onDeleteMouseDown = (e, plugin, node, value, onChange) => {
138
- e.persist();
139
- this.onDeleteClick(e, plugin, node, value, onChange);
140
- };
141
-
142
- render() {
143
- const {
144
- classes,
145
- plugins,
146
- pluginProps,
147
- toolbarOpts,
148
- value,
149
- autoWidth,
150
- onChange,
151
- getFocusedValue,
152
- isFocused,
153
- onDone,
154
- toolbarRef,
155
- doneButtonRef,
156
- onBlur,
157
- onFocus,
158
- } = this.props;
159
-
160
- const node = findSingleNode(value);
161
- const parentNode = findParentNode(value, node);
162
-
163
- log(' --------------> [render] node: ', node);
164
- log('[render] node: ', node);
165
-
166
- const plugin = plugins.find((p) => {
167
- if (!node) {
168
- return;
169
- }
170
-
171
- if (p.toolbar) {
172
- return p.toolbar.supports && p.toolbar.supports(node, value);
173
- }
174
- });
175
- const parentPlugin = plugins.find((p) => {
176
- if (!parentNode) {
177
- return;
178
- }
179
-
180
- if (p.toolbar) {
181
- return p.toolbar.supports && p.toolbar.supports(parentNode, value);
182
- }
183
- });
184
-
185
- log('[render] plugin: ', plugin);
186
-
187
- const handleDone = (change, done) => {
188
- let handler = onDone;
189
-
190
- if (plugin && plugin.toolbar && plugin.toolbar.customToolbar) {
191
- handler = this.onToolbarDone;
192
- }
193
-
194
- handler(change, done);
195
-
196
- if (parentPlugin && parentPlugin.handleDone) {
197
- parentPlugin.handleDone(value, node, plugin, onChange);
198
- }
199
- };
200
-
201
- const handleDataChange = (key, data) => {
202
- this.props.onDataChange(key, data);
203
- };
204
-
205
- const CustomToolbar = getCustomToolbar(plugin, node, value, handleDone, getFocusedValue, this.props.onDataChange);
206
-
207
- const filteredPlugins = plugin && plugin.filterPlugins ? plugin.filterPlugins(node, plugins) : plugins;
208
-
209
- log('[render] CustomToolbar: ', CustomToolbar);
210
- const parentExtraStyles =
211
- parentPlugin && parentPlugin.pluginStyles ? parentPlugin.pluginStyles(node, parentNode, plugin) : {};
212
- const pluginExtraStyles = plugin && plugin.pluginStyles ? plugin.pluginStyles(node, parentNode, plugin) : {};
213
- const extraStyles = {
214
- ...pluginExtraStyles,
215
- ...parentExtraStyles,
216
- };
217
-
218
- const deletable = node && plugin && plugin.deleteNode;
219
- const customToolbarShowDone =
220
- node && plugin && plugin.toolbar && plugin.toolbar.showDone && !toolbarOpts.alwaysVisible;
221
-
222
- // If there is a toolbarOpts we check if the showDone is not equal to false
223
- const defaultToolbarShowDone = !toolbarOpts || toolbarOpts.showDone !== false;
224
-
225
- 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
- const customStyles = toolbarOpts.minWidth !== undefined ? { minWidth: toolbarOpts.minWidth } : {};
237
-
238
- return (
239
- <div className={names} style={{ ...extraStyles, ...customStyles }} onClick={this.onClick} ref={toolbarRef}>
240
- {CustomToolbar ? (
241
- <CustomToolbar
242
- node={node}
243
- value={value}
244
- getFocusedValue={getFocusedValue}
245
- onToolbarDone={this.onToolbarDone}
246
- onDataChange={handleDataChange}
247
- pluginProps={pluginProps}
248
- />
249
- ) : (
250
- <DefaultToolbar
251
- plugins={filteredPlugins}
252
- pluginProps={pluginProps}
253
- value={value}
254
- onChange={onChange}
255
- getFocusedValue={getFocusedValue}
256
- showDone={defaultToolbarShowDone}
257
- onDone={handleDone}
258
- deletable={deletable}
259
- isHtmlMode={toolbarOpts.isHtmlMode}
260
- onFocus={onFocus}
261
- doneButtonRef={doneButtonRef}
262
- onBlur={onBlur}
263
- />
264
- )}
265
-
266
- <div className={classes.shared}>
267
- {deletable && (
268
- <IconButton
269
- aria-label="Delete"
270
- className={classes.iconRoot}
271
- onMouseDown={(e) => this.onDeleteMouseDown(e, plugin, node, value, onChange)}
272
- classes={{
273
- root: classes.iconRoot,
274
- }}
275
- >
276
- <Delete />
277
- </IconButton>
278
- )}
279
- {customToolbarShowDone && <DoneButton doneButtonRef={doneButtonRef} onClick={handleDone} />}
280
- </div>
281
- </div>
282
- );
283
- }
284
- }
285
-
286
- const style = {
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);
@@ -1,31 +0,0 @@
1
- export const findSingleNode = (value) => {
2
- if (!value || !value.isCollapsed || !value.startKey) {
3
- return;
4
- }
5
-
6
- const inline = value.document.getClosestInline(value.startKey);
7
-
8
- if (inline) {
9
- return inline;
10
- }
11
-
12
- const block = value.document.getClosestBlock(value.startKey);
13
-
14
- if (block) {
15
- return block;
16
- }
17
- };
18
-
19
- export const findParentNode = (value, node) => {
20
- if (!value || !node) {
21
- return;
22
- }
23
-
24
- return value.document.getParent(node.key);
25
- };
26
-
27
- export const hasMark = (value, type) => value && value.marks.some((mark) => mark.type == type);
28
-
29
- export const hasBlock = (value, type) => value && value.blocks.some((node) => node.type == type);
30
-
31
- export const hasNode = ({ document }, type) => document && document.nodes.some((node) => node.type == type);