ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
29.97k stars 3.25k forks source link

Plugins example/are broken #1246

Closed dmitrizzle closed 7 years ago

dmitrizzle commented 7 years ago

It's a bug.

What's the current behavior?

Plugins example throws error: fuk

build.prod.js:4978 Uncaught TypeError: Cannot read property 'type' of undefined
    at Object.e [as onBeforeInput] (http://slatejs.org/build.prod.js:4978:184)
    at r.value (http://slatejs.org/build.prod.js:5185:1968)
    at t.onEvent (http://slatejs.org/build.prod.js:5022:6166)
    at Object.r.(anonymous function) [as onBeforeInput] (http://slatejs.org/build.prod.js:5022:3280)
    at t.value (http://slatejs.org/build.prod.js:5019:5909)
    at n.(anonymous function) (http://slatejs.org/build.prod.js:5019:5139)
    at Object.cb (http://slatejs.org/build.prod.js:4829:3128)
    at Object.invokeGuardedCallback (http://slatejs.org/build.prod.js:4830:17461)
    at Object.invokeGuardedCallbackAndCatchFirstError (http://slatejs.org/build.prod.js:4830:17576)
    at gb (http://slatejs.org/build.prod.js:4829:3390)
e @ build.prod.js:4978
value @ build.prod.js:5185
onEvent @ build.prod.js:5022
r.(anonymous function) @ build.prod.js:5022
value @ build.prod.js:5019
n.(anonymous function) @ build.prod.js:5019
cb @ build.prod.js:4829
invokeGuardedCallback @ build.prod.js:4830
invokeGuardedCallbackAndCatchFirstError @ build.prod.js:4830
gb @ build.prod.js:4829
executeDispatchesInOrder @ build.prod.js:4830
Fb @ build.prod.js:4829
Hb @ build.prod.js:4829
Db @ build.prod.js:4829
processEventQueue @ build.prod.js:4830
handleTopLevel @ build.prod.js:4830
xb @ build.prod.js:4829
batchedUpdates @ build.prod.js:4830
qb @ build.prod.js:4829
ob @ build.prod.js:4829
batchedUpdates @ build.prod.js:4830
dispatchEvent @ build.prod.js:4830
build.prod.js:5053 Uncaught TypeError: Cannot read property 'text' of undefined
    at Object.f [as onInput] (http://slatejs.org/build.prod.js:5053:4127)
    at r.value (http://slatejs.org/build.prod.js:5185:1968)
    at t.onEvent (http://slatejs.org/build.prod.js:5022:6166)
    at Object.r.(anonymous function) [as onInput] (http://slatejs.org/build.prod.js:5022:3280)
    at t.value (http://slatejs.org/build.prod.js:5019:5909)
    at n.(anonymous function) (http://slatejs.org/build.prod.js:5019:5139)
    at Object.cb (http://slatejs.org/build.prod.js:4829:3128)
    at Object.invokeGuardedCallback (http://slatejs.org/build.prod.js:4830:17461)
    at Object.invokeGuardedCallbackAndCatchFirstError (http://slatejs.org/build.prod.js:4830:17576)
    at gb (http://slatejs.org/build.prod.js:4829:3390)
f @ build.prod.js:5053
value @ build.prod.js:5185
onEvent @ build.prod.js:5022
r.(anonymous function) @ build.prod.js:5022
value @ build.prod.js:5019
n.(anonymous function) @ build.prod.js:5019
cb @ build.prod.js:4829
invokeGuardedCallback @ build.prod.js:4830
invokeGuardedCallbackAndCatchFirstError @ build.prod.js:4830
gb @ build.prod.js:4829
executeDispatchesInOrder @ build.prod.js:4830
Fb @ build.prod.js:4829
Hb @ build.prod.js:4829
Db @ build.prod.js:4829
processEventQueue @ build.prod.js:4830
handleTopLevel @ build.prod.js:4830
xb @ build.prod.js:4829
batchedUpdates @ build.prod.js:4830
qb @ build.prod.js:4829
ob @ build.prod.js:4829
batchedUpdates @ build.prod.js:4830
dispatchEvent @ build.prod.js:4830

I believe this is also related to the issues I'm having in my own plugin as well.This code:

onKeyDown(event, data, change) {
  const { state } = change
  console.log(state.focusBlock)
  //...
}

Returns undefined. The above is used to check if an image block is in focus, like so: if (state.focusBlock.type !== "image") return


Also:

change.toggleMark(type) Now throws TypeError: change.toggleMark is not a function - this function is a straight copy of Slate Plugins walkthrough - which I suspect is broken for the same reason the example above is.

This shouldn't happen.

dmitrizzle commented 7 years ago

isubasti pointed out (on Slack) that function signature has changed, so data parameter needs to be removed. I've done that on my plugins, however slate-auto-replace and slate-paste-linkify still yet to do this.

ianstormtaylor commented 7 years ago

Hey @dmitrizzle, very true. I released the new version of slate-react@0.6.0 but didn't have time to update my plugins until now. Just released new versions of each!