<script nonce={{ csp_nonce() if csp_nonce else "" }}>
{% set const_name = 'editor_' + target_id|replace('-', '_') %}
{% if use_htmx %}
    var const_name = htmx.find("#{{ target_id }}")
{% else %} 
    var const_name = document.querySelector("#{{ target_id }}")
{% endif %}
{% set editor_class = editor_type.split('-')[0] %}
{{  editor_class|capitalize() + 'Editor' }}
            .create( const_name, {
                licenseKey: "{{ license_key or '' }}",
                {% if upload_endpoint %}
                simpleUpload: {
                    uploadUrl: '{{ url_for(upload_endpoint) }}',
                    withCredentials: true,
                    {% if enable_csrf %}
                    headers: {
                        'X-CSRF-TOKEN': '{{ csrf_token() }}',
                    }
                    {% endif %}
                }
                {% endif %}
            })
            .then( NewEditor => {
                window.editor = NewEditor;
            } )
            .catch( error => {
                console.error( 'Oops, something went wrong!' );
                console.error( error );
            } );
</script>