English 中文(简体)
ckeditor 5 plugins not working with svelte
原标题:
  1. I m trying to get ckeditor with html support to work within svelte.
<script>
    import { onMount } from  svelte ;
    import ClassicEditor from  @ckeditor/ckeditor5-build-classic ;
    import { FullPage } from  @ckeditor/ckeditor5-html-support ;
    export let text = ""; 
    onMount( () => {
        ClassicEditor.create( document.querySelector(  #editor  ), {plugins : [FullPage]})
        .then( editor => {
            console.log( editor );
            editor.setData( text );
            editor.model.document.on(  change:data , () => {
                text = editor.getData();
            } );
        } )
        .catch( error => {
            console.error( error );
        } );
    });
</script>

<textarea id= editor ></textarea>

✔️ Expected result

I would expect the above code to result in a ckeditor instance with html support.

❌ Actual result

my js build using rollup gives me the below error

(!) Circular dependencies
node_modules/@ckeditor/ckeditor5-engine/src/view/position.js -> node_modules/@ckeditor/ckeditor5-engine/src/view/treewalker.js -> node_modules/@ckeditor/ckeditor5-engine/src/view/position.js
node_modules/@ckeditor/ckeditor5-engine/src/view/documentselection.js -> node_modules/@ckeditor/ckeditor5-engine/src/view/selection.js -> node_modules/@ckeditor/ckeditor5-engine/src/view/documentselection.js
node_modules/@ckeditor/ckeditor5-engine/src/model/position.js -> node_modules/@ckeditor/ckeditor5-engine/src/model/treewalker.js -> node_modules/@ckeditor/ckeditor5-engine/src/model/position.js
...and 4 more
created static/js/bundle.js in 13.7s

❓ Possible solution

If I remove the line as well as FullPage from the plugins array then I have no issues.

import { FullPage } from  @ckeditor/ckeditor5-html-support ;

The editor will be instantiated. this could be an issue with my rollup.config.js --

import svelte from  rollup-plugin-svelte ;
import resolve from  @rollup/plugin-node-resolve ;
import commonjs from  @rollup/plugin-commonjs ;
import livereload from  rollup-plugin-livereload ;
import { terser } from  rollup-plugin-terser ;
import css from "rollup-plugin-css-only";
import autoPreprocess from  svelte-preprocess ;
import copy from  rollup-plugin-copy ;
import scss from  rollup-plugin-scss ;
import polyfillNode from  rollup-plugin-polyfill-node ;
import svg from  rollup-plugin-svg ;

const production = !process.env.ROLLUP_WATCH;
export default {
    input:  svelte-components/src/main.js , // (1)
    output: {
        sourcemap: true,
        format:  iife ,
        name:  app ,
        file:  static/js/bundle.js 
    },
    plugins: [
        svg(),
        css({ output: "extra_bundle.css" }),
        scss({
            fileName: "bootstrap.css",
            failOnError: true,
            runtime: require("sass"),
          }),
        svelte({
            // enable run-time checks when not in production
            dev: !production,
            // we ll extract any component CSS out into
            // a separate file - better for performance
            css: css => {
                css.write( bundle.css ); // (3)
            }
        }),
        // If you have external dependencies installed from
        // npm, you ll most likely need these plugins. In
        // some cases you ll need additional configuration -
        // consult the documentation for details:
        // https://github.com/rollup/plugins/tree/master/packages/commonjs
        resolve({
            browser: true,
            dedupe: [ svelte ]
        }),
        commonjs(),
        // In dev mode, call `npm run start` once
        // the bundle has been generated
        !production && serve(),

        // Watch the `public` directory and refresh the
        // browser on changes when not in production
        !production && livereload( svelte-components ), // (4)

        // If we re building for production (npm run build
        // instead of npm run dev), minify
        production && terser(),
        copy({
            targets: [
                { src:  node_modules/bootstrap/dist/js/bootstrap.min.js , dest:  static/js  },              
            ],
            verbose: true,
        }),
        polyfillNode(), // Add this plugin
        terser()
    ],
    watch: { 
        clearScreen: false
    }
};

function serve() {
    let started = false;

    return {
        writeBundle() {
            if (!started) {
                started = true;

                require( child_process ).spawn( npm , [ run ,  start ,  -- ,  --dev ], {
                    stdio: [ ignore ,  inherit ,  inherit ],
                    shell: true
                });
            }
        }
    };
}

If you d like to see this fixed sooner, add a ? reaction to this post.

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签