-
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
Refactor editor methods and fix JSDoc #5307
Conversation
🦋 Changeset detectedLatest commit: e6e8724 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
365b6ae
to
aae5aa9
Compare
# Conflicts: # packages/slate/src/create-editor.ts # packages/slate/src/interfaces/editor.ts
# Conflicts: # packages/slate-react/src/components/string.tsx # packages/slate/src/interfaces/editor.ts
# Conflicts: # packages/slate-react/src/components/editable.tsx
# Conflicts: # packages/slate/src/interfaces/editor.ts # packages/slate/src/transforms/selection.ts # packages/slate/src/transforms/text.ts
Does this have implications for the import { someFunction } from 'slate[-react]';
export const withX = (editor) => ({
...editor,
someFunction: (x, y, z) => {
console.log('someFunction', x, y, z);
return someFunction(x, y, z);
},
}); |
@12joan This composition pattern is now possible, indeed! However, in that example, the last plugin would override the other plugins overrides (on the same method), so we'd need to slightly change Plate core logic to support the piping pattern. |
This change bloated the minified core by 19% and destroyed one of the things I really liked about slate; a focus on static method implementations meant any features I didn't use were tree-shaken away. I'm disappointed to see Slate moved in this direction while I was away. I don't think it meshes with the goals Ian set out for it. Surely you could've done this all-in-one just with the |
Yikes, ok. Plan wasn’t to bloat/break tree shaking, but to try to make things more consistent. Will look into this asap. |
Description
This pull request introduces a new pattern without any breaking changes. All
Editor
andTransforms
methods now calleditor
methods. For example,Transforms.setNodes
is now callingeditor.setNodes
, andeditor.setNodes
is now callingsetNodes
, an exported function implementing the default editor behavior. You can overrideeditor.setNodes
on your end so that you can either useEditor.setNodes
oreditor.setNodes
, and both will use your overridden behavior, and Slate will too.The
editor
object now has many more methods, and some changes have been made to improve code style consistency. None of the implementation of the methods has changed, except for the addition of a new argument toeditor.insertText
.This PR also includes:
Example
Please refer to the example code snippet below for the usage of the new pattern:
Context
This pull request allows for more flexibility in implementing custom behavior for
Editor
andTransforms
methods without breaking any existing functionality. It achieves this by introducing a new pattern whereEditor
andTransforms
methods calleditor
methods, andeditor
methods call an exported function implementing the default editor behavior.This pattern allows for overriding
editor
methods with custom behavior, and using eitherEditor
oreditor
methods, which will both use the overridden behavior, and Slate will too.ReactEditor
is not yet following that pattern. I'd wait for this pattern approval first.With the introduction of many new methods to
editor
, it may be beneficial to consider implementing a plugin-based architecture to prevent overloading the editor object. This would involve relocating all queries toeditor.queries
and all transforms toeditor.transforms
. However, this is a significant breaking change that is not included in this PR.