slab/delta

How do I use the delta in an old web page via script tag?

Closed this issue · 2 comments

Hello, I'm using the QuillJS library through unpkg. I have a script tag and am simply referencing the quill.js file. In my editor's text-change event I need to compose a new Delta object, but I am getting an undefined error.

I don't know how this works. I am working on an old vanilla js site with no transpilers or anything like that. I found the Delta library on unpkg too but it's made up of multiple files (it's not self-containing like Quill.js). I tried using another script tag and pointing it to the Delta.js file and I'm getting an error about a ts file. The documentation talks about Deltas and demonstrates creating them, as if they'll just work but it doesn't for me.

Do libraries have to do something special to make their code available through a single js file? And what can you do to get around it if you don't use newer js (module imports/exports/require) . Here's a simplified example of what I am trying to do:

myQuillObj.on('text-change', function(delta, old, source) {
    if (delta[0].ops.insert == 'z')  {
        var d = new Delta().delete(1)  // <= Delta is undefined
    }

    myQuillObj.updateContents(d, 'api)
}

I also tried doing a copy of the delta passed to me but the resulting object doesn't contain what it needs to. I'd have to use another library like lodash to do a deep copy, which requires newer js too.

You should be able to get access to the Delta constructor with
const Delta = Quill.import('delta');
Hope it helps :)

@FanatiQS thank you very much! I feel so stupid, I read the documentation on deltas earlier this morning right up until the very last sentence where it mentioned this. Thank you for your quick response, you helped saved my day.