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

Retain existing config when calling configure on Marks and Extensions #3822

Merged
merged 1 commit into from
Apr 21, 2023
Merged

Retain existing config when calling configure on Marks and Extensions #3822

merged 1 commit into from
Apr 21, 2023

Conversation

nholden
Copy link
Contributor

@nholden nholden commented Mar 4, 2023

Currently, when you call .configure() on a Mark or Extension, the Mark or Extension that's returned doesn't retain the config from the original.

This is a problem for StarterKit. When Code is added to an editor added as a standalone extension, an inline code block is exitable. When added as part of StarterKit, an inline code block is not exitable because StarterKit calls Code.configure(), blowing away the default config.

This PR ensures that when you call .configure() on a Mark or Extension, the Mark or Extension that's returned retains the config from the original.

closes #3813

@netlify
Copy link

netlify bot commented Mar 4, 2023

Deploy Preview for tiptap-embed ready!

Name Link
🔨 Latest commit c0ec0c2
🔍 Latest deploy log https://app.netlify.com/sites/tiptap-embed/deploys/6403829193be470008344a71
😎 Deploy Preview https://deploy-preview-3822--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 settings.

@bdbch bdbch changed the base branch from main to develop March 8, 2023 15:28
Copy link
Member

@bdbch bdbch left a comment

Choose a reason for hiding this comment

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

Good find. Thanks, LGTM! @svenadlung ?

@bdbch bdbch added this to the 2.1.0 Release milestone Mar 28, 2023
@bdbch bdbch added Status: Review Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. labels Mar 29, 2023
@fleon
Copy link
Contributor

fleon commented Apr 18, 2023

@bdbch Can we get this merged? Looks pretty straightforward. 😄

@svenadlung
Copy link
Contributor

@bdbch Looks good to me. Feel free to merge.

@huangmb
Copy link

huangmb commented Apr 18, 2023

I think the main problem is ExtensionManagerextension.type === 'mark' && extension.config.exitable not call callOrReturn(getExtensionField(extension,'exitable'))
5fed0f2#diff-34ea668dac19f1717ece64fd0716f0709a69da5401e5615aa8de1cd801c9f30c

@huangmb
Copy link

huangmb commented Apr 19, 2023

my temporary solution is

addProseMirrorPlugins() {
        const extensions = this.options.extensions || [];
        return extensions.filter(extension => extension.type === 'mark')
            .map(extension => {
                const editor = this.editor
                const context = {
                    name: extension.name,
                    options: extension.options,
                    storage: extension.storage,
                    editor,
                }
                if (extension.config.exitable) {
                    // ExtensionManager已经正常处理了,跳过
                    return null
                }
                const exitable = callOrReturn(getExtensionField(extension, 'exitable', context))
                if (exitable) {
                    return keymap({
                        ArrowRight: () => Mark.handleExit({editor, mark: extension})
                    })
                }
                return null
            })
            .filter(plugin=>plugin)
    }

if tiptap core fix this bug, i will remove this extension

@bdbch bdbch merged commit 0dcc684 into ueberdosis:develop Apr 21, 2023
@nholden nholden deleted the nholden/retain-config branch April 21, 2023 16:15
@bdbch
Copy link
Member

bdbch commented Apr 26, 2023

Sorry but I had to revert this PR as it was breaking a lot of the core functionality. It's included in v2.1.0-rc.2 if you want to test it yourself.

Basically this.config will be { name: 'mark', defaultOptions: {} } by default which means type names won't be correct anymore and the defaultOptions warning will be appear by default.

Could you check into this again @nholden ?

@nholden
Copy link
Contributor Author

nholden commented Apr 30, 2023

Good catch, @bdbch! I took another stab at this in #3998.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code not exitable in StarterKit
5 participants