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

[Bug]Selecting the editor causes the iframe to disappear #1254

Open
2 tasks done
YueXingyu5482 opened this issue Feb 24, 2024 · 0 comments
Open
2 tasks done

[Bug]Selecting the editor causes the iframe to disappear #1254

YueXingyu5482 opened this issue Feb 24, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@YueXingyu5482
Copy link

Initial checklist

  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything (or linked relevant results below)

Affected packages and versions

"@milkdown/core": "^7.3.5",     "@milkdown/preset-commonmark": "^7.3.5",     "@milkdown/preset-gfm": "^7.3.5",     "@milkdown/theme-nord": "^7.3.5",     "@milkdown/utils": "^7.3.5",     "@milkdown/vue": "^7.3.5",     "remark-directive": "^3.0.0",     "vue": "^3.4.15"

Link to runnable example

No response

Steps to reproduce

If the default value in the editor is only iframe, the iframe disappears when the editor is selected
`import { InputRule } from '@milkdown/prose/inputrules'
import { $node, $inputRule, $remark } from "@milkdown/utils"
import directive from 'remark-directive';

const remarkPluginId = "iframe"
const remarkDirective = $remark(remarkPluginId, () => directive)
const iframeNode = $node('iframe', () => ({
group: 'block',
atom: true,
isolating: true,
marks: '',
selectable: true,
draggable: true,
defining: true,
attrs: {
src: { default: null },
},
parseDOM: [{
tag: 'iframe',
getAttrs: (dom) => ({
src: dom.getAttribute('src'),
}),
}],
toDOM: (node) => [
'iframe',
{ ...node.attrs, 'contenteditable': false },
0,
],
parseMarkdown: {
match: (node) => {
return node.type === 'leafDirective' && node.name === 'iframe'
},
runner: (state, node, type) => {
state.addNode(type, { src: node.attributes.src });
},
},
toMarkdown: {
match: (node) => node.type.name === 'iframe',
runner: (state, node) => {
state.addNode('leafDirective', undefined, undefined, {
name: 'iframe',
attributes: { src: node.attrs.src },
});
},
}
}))
const iframeInputRule = $inputRule((ctx) => new InputRule(/::iframe{src="(?[^"]+)?"?}/, (state, match, start, end) => {
const [okay, src = ''] = match;
const { tr } = state;

if (okay) {
    tr.replaceWith(start - 1, end, iframeNode.type(ctx).create({ src }));
}

return tr;

}))
export default [iframeInputRule, iframeNode, remarkDirective]`

Expected behavior

The editor is selected, and the contents of the editor are not affected

Actual behavior

The editor is selected, but the iframe is deleted

Runtime

Chrome

OS

macOS

Build and bundle tools

Vite

@YueXingyu5482 YueXingyu5482 added the bug Something isn't working label Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants