-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat/#5521/derive on selection change and on value change #5523
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'slate': minor | ||
'slate-react': minor | ||
--- | ||
|
||
Add `onValueChange` to watch value changes and `onSelectorChange` to watch selector changes |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,15 @@ export const withReact = <T extends BaseEditor>( | |
clipboardFormatKey = 'x-slate-fragment' | ||
): T & ReactEditor => { | ||
const e = editor as T & ReactEditor | ||
const { apply, onChange, deleteBackward, addMark, removeMark } = e | ||
const { | ||
apply, | ||
onChange, | ||
onValueChange, | ||
onSelectionChange, | ||
deleteBackward, | ||
addMark, | ||
removeMark, | ||
} = e | ||
|
||
// The WeakMap which maps a key to a specific HTMLElement must be scoped to the editor instance to | ||
// avoid collisions between editors in the DOM that share the same value. | ||
|
@@ -366,6 +374,14 @@ export const withReact = <T extends BaseEditor>( | |
onContextChange() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to pass a parameter to this function as stated in #5521 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not getting what you mean. What should I pass as parameter here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need 2 new props to |
||
} | ||
|
||
switch (options?.operation?.type) { | ||
case 'set_selection': | ||
onSelectionChange(options) | ||
break | ||
default: | ||
onValueChange(options) | ||
} | ||
|
||
onChange(options) | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is where I need to add the new handlers, @zbeyens?
and execute them inside onContextChange?
or do you want me to add a new parameter on onContextChange, where we'll send the
onValueChange
/onSelectorChange
(from this line)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever that makes it work :) Will be confirmed by unit tests.