Skip to content
This repository was archived by the owner on May 19, 2020. It is now read-only.

Commit e9ba2d7

Browse files
authored
Merge pull request #203 from accordproject/dl-update-isEditable
refactor(*): pass editor to isEditable so it can be used by plugins
2 parents 76ceb67 + e36826c commit e9ba2d7

File tree

5 files changed

+20
-42
lines changed

5 files changed

+20
-42
lines changed

package-lock.json

+12-31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@
112112
"slate-plain-serializer": "^0.7.10",
113113
"style-loader": "^0.23.1"
114114
}
115-
}
115+
}

src/FormattingToolbar/index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ export default class FormatToolbar extends React.Component {
175175
*/
176176
onClickMark(event, type) {
177177
const { editor, pluginManager, lockText } = this.props;
178-
const { value } = editor;
179178

180-
if (!lockText || pluginManager.isEditable(value, type)) {
179+
if (!lockText || pluginManager.isEditable(editor, type)) {
181180
event.preventDefault();
182181
editor.toggleMark(type);
183182
}
@@ -189,8 +188,7 @@ export default class FormatToolbar extends React.Component {
189188
*/
190189
onClickLinkButton() {
191190
const { editor, pluginManager, lockText } = this.props;
192-
const { value } = editor;
193-
if (!lockText || pluginManager.isEditable(value)) {
191+
if (!lockText || pluginManager.isEditable(editor)) {
194192
const hasLinksBool = action.hasLinks(editor);
195193
const isOnlyLinkBool = action.isOnlyLink(editor);
196194
if (hasLinksBool && !isOnlyLinkBool) return;
@@ -212,7 +210,7 @@ export default class FormatToolbar extends React.Component {
212210
const { editor, pluginManager, lockText } = this.props;
213211
const { value } = editor;
214212

215-
if (!lockText || pluginManager.isEditable(value, type)) {
213+
if (!lockText || pluginManager.isEditable(editor, type)) {
216214
event.preventDefault();
217215
if (action.isClickBlockQuote(type)) {
218216
action.isSelectionList(value)

src/PluginManager.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ export default class PluginManager {
5757
* If any plugin returns isEditable (true) then
5858
* the content is editable
5959
*
60-
* @param {Value} value the Slate value
60+
* @param {Editor} editor the Slate editor
6161
* @param {string} code the type of edit requested
6262
*/
63-
isEditable(value, code) {
63+
isEditable(editor, code) {
6464
// if no plugins have an `isEditable` method, return true
6565
if (!this.plugins.filter(plugin => plugin.isEditable).length) return true;
6666

6767
for (let n = 0; n < this.plugins.length; n += 1) {
6868
const plugin = this.plugins[n];
69-
if (plugin.isEditable && plugin.isEditable(value, code)) {
69+
if (plugin.isEditable && plugin.isEditable(editor, code)) {
7070
return true;
7171
}
7272
}

src/SlateAsInputEditor/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,8 @@ const SlateAsInputEditor = React.forwardRef((props, ref) => {
232232
*/
233233
const isEditable = useCallback((editor, code) => {
234234
if (editor.props.lockText) {
235-
const { value } = editor;
236235
const pluginManager = new PluginManager(plugins);
237-
return pluginManager.isEditable(value, code);
236+
return pluginManager.isEditable(editor, code);
238237
}
239238

240239
return true;

0 commit comments

Comments
 (0)