Skip to content
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: make undo and redo as ProseMirror commands #12

Merged
merged 10 commits into from
Aug 20, 2024

Conversation

ocavue
Copy link
Collaborator

@ocavue ocavue commented Aug 20, 2024

This PR changes the function signature of undo and redo. The second parameter dispatch is now optional. By doing that, undo and redo match ProseMirror command definition.

A command function takes an editor state, optionally a dispatch function that it can use to dispatch a transaction and optionally an EditorView instance. It should return a boolean that indicates whether it could perform any action. When no dispatch callback is passed, the command should do a 'dry run', determining whether it is applicable, but not actually doing anything.
docs link


Some other changes included in this PR but not directly related to the feature above:

  1. Add a PNPM workspace, so that the storybook can pick the current developing version of loro-prosemirror

  2. Add type prefix when importing a TS type. This fixes the following Rollup error when building

    [!] RollupError: "LoroSyncPluginProps" is not exported by "src/sync-plugin.ts", imported by "src/index.ts".
    
  3. Update tsconfig.json so that TypeScript can check the type prefix. Add a pnpm run lint script and run it in the CI workflow.

Comment on lines -191 to -192
dispatch(emptyTr);
return false;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no point calling dispatch when the function failed to execute the action (i.e. return false).

@ocavue ocavue marked this pull request as ready for review August 20, 2024 02:21
@zxch3n
Copy link
Member

zxch3n commented Aug 20, 2024

Thanks a lot! LGTM

@zxch3n zxch3n merged commit b0a1bc1 into loro-dev:main Aug 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants