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

WIP: Decorations API #5437

Draft
wants to merge 21 commits into
base: next
Choose a base branch
from
Draft

WIP: Decorations API #5437

wants to merge 21 commits into from

Conversation

bdbch
Copy link
Contributor

@bdbch bdbch commented Aug 3, 2024

Will fill this up later when I have a final idea how to integrate this.

Copy link

changeset-bot bot commented Aug 3, 2024

🦋 Changeset detected

Latest commit: eb0e379

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

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

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

@bdbch bdbch changed the base branch from develop to next August 3, 2024 01:53
Copy link

netlify bot commented Aug 3, 2024

Deploy Preview for tiptap-embed failed. Why did it fail? →

Name Link
🔨 Latest commit eb0e379
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/67052ec31aea870008979b66

@nperez0111
Copy link
Contributor

Some ideas for how we might wanna structure this:

const editor = new Editor()

editor.on('transaction', () => {

  const removeDecoration = editor.addDecorationWidget({ ...options })

  removeDecoration()

  editor.getDecorationSet('myDecoration').forEach(({ from, to }) => {
    editor.removeDecoration(from, to, 'myDecoration')
  })

})

DecorationSet.create({
  onTransaction,
  shouldShow,
  onCreate,
  onRemove,
  onUpdate,
  name: 'myDecoration',
  onEvent: (eventName, meta)=>{
    if (eventName === 'eventName') {
      // I want this decoration active
      editor.addDecorationSet('myDecoration', decorationSet)
      return;
    }
  }
  onTransaction: tr => {
    if (!tr.isOneIWant) {
      editor.clearDecorationSet('myDecoration')
      return
    }

    this.editor.addDecorationWidget()
  },
})

class DecorationManager {

  allDecorationSets: Record<string, DecorationSet> = {}

  addDecorationSet(key: string, decorationSet: DecorationSet) {
    this.allDecorationSets[key] = decorationSet
  }

  removeDecorationSet(key: string) {
    this.allDecorationSets[key].destroy()
    this.allDecorationSets[key] = undefined
  }

  listDecorationSets() {
    return ['myDecoration', 'anotherDecorationSet']
  }

  getDecorationSet(key: string) {

  }

  triggerEvent(eventName: string) {
    // re-run decoration sets
  }

  getProsemirrorPlugin() {
    return new Plugin({
      key: new PluginKey('decorationManager'),
      state: {
        init: () => this,
        apply: (tr, plugin) => {
          const decorationManager = plugin.getState(tr)

          // map through transactions for all decorations that still exist

          decorationManager.allDecorationSets.forEach(decorationSet => {
            decorationSet.onTransaction(tr)
          })
        },
      },
    })
  }
}

editor.triggerDecoration('eventName', meta)
editor.addDecorationSet('myDecoration', decorationSet)
editor.removeDecorationSet('myDecoration')

YaoKaiLun and others added 21 commits September 24, 2024 22:38
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 5.4.1 to 5.4.6.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/v5.4.6/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v5.4.6/packages/vite)

---
updated-dependencies:
- dependency-name: vite
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Bumps [actions/cache](https://github.com/actions/cache) from 4.0.2 to 4.1.0.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](actions/cache@v4.0.2...v4.1.0)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage open
Development

Successfully merging this pull request may close these issues.

6 participants