import "./xml-editor";
import { JinnXMLEditor } from "./xml-editor";
import { JinnCodemirror } from "./jinn-codemirror";
interface LeidenEditorUpdateEvent extends Event {
detail: { content: string }
}
const style = `
:host {
display: block;
width: 100%;
}
jinn-codemirror,
jinn-xml-editor {
font-size: var(--edep-editor-font-size, 1rem);
display:block;
width:100%;
}
#leiden-editor {
margin-bottom: 0;
}
[slot=toolbar] {
display: flex;
flex-wrap: wrap;
align-items: center;
column-gap: var(--edep-editor-toolbar-gap, 4px);
width: 100%;
box-sizing: border-box;
padding: var(--edep-editor-toolbar-padding, 0.25rem 0.5rem);
background: var(--edep-editor-toolbar-background, inherit);
border-bottom: 1px solid var(--edep-editor-border-color, #CFCDC5);
}
.hidden {
display: none;
}
#close-leiden {
margin-left: .75rem;
font-weight: bold;
}`;
const ignoreKeys = ['Shift', 'Alt', 'Meta', 'Control', 'ArrowLeft', 'ArrowRight', 'ArrowDown',
'ArrowUp', 'PageDown', 'PageUp', 'Home', 'End'];
const EDITOR_MODES = {
leiden_plus: 'Leiden+',
edcs: 'EDCS/EDH',
default: 'Petrae'
};
function createModeSelect(mode: string) {
const options:string[] = [];
Object.entries(EDITOR_MODES).forEach(([key, value]) => {
options.push(``);
});
return ``;
}
/**
* Combines an XML editor with an option to import and convert markup following variants
* of the Leiden convention.
*
* @slot leiden-header - optional header to be displayed above the toolbar of the leiden editor
* @slot xml-header - optional header to be displayed above the toolbar of the xml editor
* @slot leiden-toolbar - toolbar for the leiden editor
* @slot xml-toolbar - toolbar for the xml editor
* @slot open-leiden - control (button by default) which opens/closes the leiden editor
*/
export class JinnEpidocEditor extends HTMLElement {
xmlEditor: JinnXMLEditor | null | undefined;
/**
* Syntax mode to use for the leiden editor, one of leiden_plus, edcs or petrae
*/
public mode: string = 'leiden_plus';
/**
* if set, user may choose from the supported syntaxes
*
* @attr {boolean} mode-select
*/
public modeSelect: boolean;
public valid?: boolean;
/**
* If set, expects that a value passed in is a DOM element, which will serve as a wrapper for the content.
* The wrapper element itself will not be shown in the editor.
*/
public unwrap?: boolean;
/**
* an optional schema description (JSON syntax) to load for the XML editor
*/
public schema: string | null;
/**
* determines the root element for autocomplete
*
* @attr {string} schema-root
*/
public schemaRoot: string | null;
public placeholder: string = '';
/**
* Should the leiden editor be shown initially?
*/
public showLeiden: boolean = false;
/**
* The value edited in the editor as either an Element or string -
* depending on the mode set.
*/
set value(value: Element | string | null | undefined) {
this.xmlEditor.value = value;
}
get value(): Element | null | undefined {
return this.xmlEditor.value;
}
constructor() {
super()
this.xmlEditor = null;
this.valid = true;
this.unwrap = false;
this.schema = null;
this.schemaRoot = null;
this.modeSelect = false;
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
this.unwrap = this.hasAttribute('unwrap');
this.schema = this.getAttribute('schema');
this.schemaRoot = this.getAttribute('schema-root');
this.modeSelect = this.hasAttribute('mode-select');
this.mode = this.getAttribute('mode') || 'leiden_plus';
this.placeholder = this.getAttribute('placeholder') || '';
this.showLeiden = this.hasAttribute('show-leiden');
this.shadowRoot.innerHTML = `