Skip to content

feat(web): rich text paste from Clipboard using HTML #2009

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

Merged
merged 2 commits into from
Sep 13, 2024

Conversation

EchoEllet
Copy link
Collaborator

@EchoEllet EchoEllet commented Jul 13, 2024

Description

Support Rich Text Pasting with HTML on the Web.

Importing any file from web directly will cause a compile issue on non-web platforms even if we're using kIsWeb to check the platform, so I used conditional import by importing a file that mocks the implementation for non-web platforms, for web will import the real implementation that is intended for web and use the web package.

This process is error-prone and can cause issues when moving the files and refactoring the imports since the IDE doesn't update the conditional import path and the compiler only causes issues when compiling to the web, which is why the GitHub workflow build the example app for both Web and Linux (a non-web platform).

Also the _pasteMarkdown and _pasteHTML are no longer accessible to quill_controller_web_stub.dart as it's in a separate file, I didn't make them public since they are intended for internal use only, so I moved them into a separate file that's not exported, I have noticed we're making some APIs public because we need them somewhere else internally, making more breaking changes when there is a need.

The deprecated APIs should be in their own separate file since we can move them somewhere else and export the file and still be backward compatible, maybe we need a new directory such as deprecated at some point

Related Issues

Previously, some assertions were failing, some of them were not caused by this feature but related to it.

Suggestions

  • Remove the meta package from flutter_quill since it's already available in Flutter and exposed as a public API, it's required in dart_quill_delta

  • We should probably deprecate the experimental function QuillController.setContents, it's misleading and doesn't work the same as Quill JS. It's not being used internally.

  • disableClipboard is not quite a descriptive name or I might have not understood it correctly, it says:

    this disables the clipboard notification for requesting permissions

  if (!widget.configurations.disableClipboard) {
     // Web - esp Safari Mac/iOS has security measures in place that restrict
     // cliboard status checks w/o direct user interaction. Initializing the
     // ClipboardStatusNotifier with a default value of unknown will cause the
     // clipboard status to be checked w/o user interaction which fails. Default
     // to pasteable for web.
     if (kIsWeb) {
       _clipboardStatus = ClipboardStatusNotifier(
         value: ClipboardStatus.pasteable,
       );
     }
   }

I'm not sure if it disables all Clipboard features including the Clipboard from Flutter or only the Rich text pasting feature. See related PR #1719.

Checklist

  • New feature: Adds new functionality without breaking existing features.
  • 🛠️ Bug fix: Resolves an issue without altering current behavior.
  • 🧹 Code refactor: Code restructuring that does not affect behavior.
  • Breaking change: Alters existing functionality and requires updates.
  • 🧪 Tests: Adds new tests or modifies existing tests.
  • 📝 Documentation: Updates or additions to documentation.
  • 🗑️ Chore: Routine tasks, or maintenance.
  • Build configuration change: Changes to build or deploy processes.

Breaking Change

Does your PR require developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

@EchoEllet EchoEllet changed the title feat: rich text paste web feat(web): rich text paste from Clipboard using HTML Jul 13, 2024
@EchoEllet EchoEllet force-pushed the feat/rich-text-paste-web branch from d43106b to fb72b99 Compare September 13, 2024 14:05
@EchoEllet EchoEllet marked this pull request as ready for review September 13, 2024 14:24
@singerdmx singerdmx merged commit e51add5 into master Sep 13, 2024
2 checks passed
Copy link
Collaborator

@AtlasAutocode AtlasAutocode left a comment

Choose a reason for hiding this comment

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

I don't see any obvious problems.

@EchoEllet
Copy link
Collaborator Author

EchoEllet commented Sep 13, 2024

I was already able to reproduce this issue at the time of this PR (2 months ago), and I wasn't able to again after the last update, I'm not quite sure what I did but I'm able to reproduce it once again:

Text pasted twice

The text is pasted twice, with and without rich text paste feature when there is an HTML in the clipboard content.

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.

[Web] Pasting HTML Doesn't Work Propertly
3 participants