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

Node specific placeholders and showOnlyCurrent property #515

Merged
merged 18 commits into from
Jan 6, 2025

Conversation

thijskuilman
Copy link
Contributor

@thijskuilman thijskuilman commented Dec 5, 2024

In this PR, I've added two functionalities from the TipTap Placeholder extension.

Node specific placeholders
You can now set placeholders for specific node types. For example: I had a case where I wanted to set a different placeholder to a heading and a paragraph. You can now do that like this:

TiptapEditor::make('content')
    // Default placeholder. Also a fallback if a nodePlaceholder entry can't be found
    ->placeholder('Write something...')
    // Specific placeholdes per node
    ->nodePlaceholders([
       'paragraph' => 'Start writing your paragraph...',
       'heading' => 'Insert a heading...',
    ])

The code implementation is based on the official example, see the code example here.

Show only current placeholder
I have added the showOnlyCurrent property to TiptapEditor. You can use it like this:

TiptapEditor::make('content')
    ->showOnlyCurrentPlaceholder(false)

In the example above, all nodes will immediately be displayed, instead of only the selected node.

@thijskuilman
Copy link
Contributor Author

Hi @awcodes, I was wondering if you might have some time soon to review this PR? This feature would really help with a current project, and I’d prefer to avoid using a forked version if possible. If there’s anything you’d like me to adjust or improve, I’d be more than happy to make those changes. Thanks!

@awcodes
Copy link
Owner

awcodes commented Dec 13, 2024

Hope to get to this review soon. Sorry. Really busy with work at the moment.

@awcodes
Copy link
Owner

awcodes commented Dec 20, 2024

Are you disabling the floating menu? Seems like there would be a conflict with this and also I think that there would need to be changes to the placeholder css to make this work.

@thijskuilman
Copy link
Contributor Author

Hi @awcodes, thanks for your feedback!

[...] I think that there would need to be changes to the placeholder css to make this work.

I've added the missing placeholder CSS to the fork. It's now updated to use the existing placeholder styling. It now works as expected, see the example:

👁️ View example
 TiptapEditor::make('content')
      ->customDocument('heading block+')
      ->nodePlaceholders([
          'paragraph' => 'Start writing...',
          'heading' => 'A wonderful title',
      ])
image

Are you disabling the floating menu? Seems like there would be a conflict with this [...]

You are right: I disabled floating menu's in my personal project. I now notice the issue as well: if you enter a block that does not have any floating menu items, then it is still shown. This is not caused by this PR, since I can reproduce it on the main branch:

Reproduction

  1. Enter a heading
  2. See a empty Tippy tooltip:
image

I notice the floating menu already contains a x-show to check if it's a paragraph, but it seems like this rule is not respected. I've added some JS code to enforce this rule, see #b0aac1. It now works as expected, see the example:

👁️ View example

If you now focus on an empty heading, then the floating menu will be hidden:

 TiptapEditor::make('content')
      ->customDocument('heading block+')
      ->nodePlaceholders([
          'paragraph' => 'Start writing...',
          'heading' => 'A wonderful title',
      ])
image

The floating menu still works for paragraphs:

image

@awcodes
Copy link
Owner

awcodes commented Jan 2, 2025

This looks good. If you can merge in the updates I've done and resolve the conflicts I'll get it merged in. Thanks.

@thijskuilman
Copy link
Contributor Author

Thanks @awcodes! I just updated the branch.

@awcodes awcodes merged commit 83abff3 into awcodes:3.x Jan 6, 2025
6 checks 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