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

feature: add global node type name attributes to editor DOM #5786

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

bdbch
Copy link
Contributor

@bdbch bdbch commented Oct 30, 2024

Changes Overview

This pull request introduces a new feature to add type attributes to nodes and marks in the editor for better identification, which can be useful for testing and styling purposes. The changes span across multiple files to implement and support this feature.

This makes it easier to style specific HTML elements of the editor while not overwriting any styles for node view related elements or other decorations that may unwillingly be styled.

If enabled, a node could be rendered like this in HTML:

<p data-tiptap="paragraph">
  Hello <strong data-tiptap"bold">World</strong>, this is a <em data-tiptap="italic">test</em> to test node-type data attributes.
</p>

Implementation Approach

I added a new option called addTypeAttributes to the editor which is global and enabled by default. This addTypeAttributes option enables a Typenames extension that will dynamically add those type names to the editor DOM.

Those attributes are currently stripped from the editors output.

Testing Done

I tested this all locally on any test of our demos pages.

Verification Steps

Clone and check the branch for your self or check the deployed netlify page.

Additional Notes

I don't think this is a breaking change as it's not really changing the general behavior of the editor and the data-node-type attribute is vague enough to not be used by the general user base.

Checklist

  • I have created a changeset for this PR if necessary.
  • My changes do not break the library.
  • I have added tests where applicable.
  • I have followed the project guidelines.
  • I have fixed any lint issues.

Copy link

changeset-bot bot commented Oct 30, 2024

🦋 Changeset detected

Latest commit: 3fa56e7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 54 packages
Name Type
@tiptap/react Minor
@tiptap/vue-2 Minor
@tiptap/vue-3 Minor
@tiptap/core Minor
@tiptap/extension-blockquote Minor
@tiptap/extension-bold Minor
@tiptap/extension-bubble-menu Minor
@tiptap/extension-bullet-list Minor
@tiptap/extension-character-count Minor
@tiptap/extension-code-block-lowlight Minor
@tiptap/extension-code-block Minor
@tiptap/extension-code Minor
@tiptap/extension-collaboration-cursor Minor
@tiptap/extension-collaboration Minor
@tiptap/extension-color Minor
@tiptap/extension-document Minor
@tiptap/extension-dropcursor Minor
@tiptap/extension-floating-menu Minor
@tiptap/extension-focus Minor
@tiptap/extension-font-family Minor
@tiptap/extension-gapcursor Minor
@tiptap/extension-hard-break Minor
@tiptap/extension-heading Minor
@tiptap/extension-highlight Minor
@tiptap/extension-history Minor
@tiptap/extension-horizontal-rule Minor
@tiptap/extension-image Minor
@tiptap/extension-italic Minor
@tiptap/extension-link Minor
@tiptap/extension-list-item Minor
@tiptap/extension-list-keymap Minor
@tiptap/extension-mention Minor
@tiptap/extension-ordered-list Minor
@tiptap/extension-paragraph Minor
@tiptap/extension-placeholder Minor
@tiptap/extension-strike Minor
@tiptap/extension-subscript Minor
@tiptap/extension-superscript Minor
@tiptap/extension-table-cell Minor
@tiptap/extension-table-header Minor
@tiptap/extension-table-row Minor
@tiptap/extension-table Minor
@tiptap/extension-task-item Minor
@tiptap/extension-task-list Minor
@tiptap/extension-text-align Minor
@tiptap/extension-text-style Minor
@tiptap/extension-text Minor
@tiptap/extension-typography Minor
@tiptap/extension-underline Minor
@tiptap/extension-youtube Minor
@tiptap/html Minor
@tiptap/pm Minor
@tiptap/starter-kit Minor
@tiptap/suggestion Minor

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

Copy link

netlify bot commented Oct 30, 2024

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit 3fa56e7
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/672251d4d3b0a70008af7223
😎 Deploy Preview https://deploy-preview-5786--tiptap-embed.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@bdbch bdbch changed the title Global nodename attribute add global node type name attributes to editor DOM Oct 30, 2024
@bdbch bdbch changed the title add global node type name attributes to editor DOM feature: add global node type name attributes to editor DOM Oct 30, 2024
@bdbch bdbch self-assigned this Oct 30, 2024
Comment on lines 3 to 4
export const Typenames = Extension.create({
name: 'typenames',
Copy link
Contributor

Choose a reason for hiding this comment

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

typenames?

Maybe namedAttributes? Or labeledAttributes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But this adds the nodetype names of nodes and marks? Wouldn't typenames make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

typename just is super generic.

It should be clear that this is applying to the HTMLAttributes of nodes & marks, unsure of a good name for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

typenameAttributes?

Comment on lines 12 to 15
'data-tiptap': {
default: extension.name,
rendered: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this get stored to the Tiptap JSON? Kind of redundant if it does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't think those are added to the Tiptap JSON.

@@ -0,0 +1,19 @@
import { Extension } from '../Extension.js'

export const Typenames = Extension.create({
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe better TypeNames?

packages/core/src/Editor.ts Outdated Show resolved Hide resolved
packages/react/src/ReactNodeViewRenderer.tsx Outdated Show resolved Hide resolved
@bdbch
Copy link
Contributor Author

bdbch commented Oct 30, 2024

Just figured - the addGlobalAttributes function will add all attributes to the Tiptap JSON which is what we don't want. I'll see if I can find a different solution again.

@@ -10,6 +10,8 @@ import React from 'react'
const MenuBar = () => {
const { editor } = useCurrentEditor()

window.editor = editor

Choose a reason for hiding this comment

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

I think you accidentally left this in?

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.

4 participants