class CCPInputWidgetEditorController extends HTMLElement{ #input = null #index = null #type = null #delete_icon = ` ` constructor(){ super(); } connectedCallback(){ } get index(){ return this.#index } /*computeDefaultInputType(){ if(this.#input.schema.format === "secret"){ return "password" }else if(this.#input.schema.format === "date"){ return "date" }else if(this.#input.schema.format === "time"){ return "time" }else if(this.#input.schema.format === "dateTime"){ return "datetime-local" } return "text" }*/ isSelectedFormat(fmt){ return this.#input.schema.format === fmt } renderDefaultByType(){ return `` /*if(this.#input.schema.format === "code"){ return ` ` } else { return ` ` }*/ } renderDeleteButton(){ return `` } render(input, i, reopen){ this.#index = i this.#input = input this.#type = input.schema.enum ? "enum" : "string" const minOccurs = input.minOccurs = Number(input.minOccurs) ? Number(input.minOccurs) : 0 const maxOccurs = input.maxOccurs = Number(input.maxOccurs) ? Number(input.maxOccurs) : 0 this.innerHTML = `
${ input.id !== 'ccpimage' ? this.renderDeleteButton() : ''}
Comma separated list of options
${this.renderDefaultByType()}
👁
` this.addEventListener("click", ev=>{ const ename = ev.target.getAttribute("name") if(ename === "password_toggle"){ const w = this.querySelector("div[name=input-default] input[name=default]") w.type = (w.type === "password" ? "" : "password") ev.preventDefault() } }) const defaultinp = this.querySelector("div[name='input-default']") defaultinp.addEventListener("input", ev=>{ const inp = this.querySelector("d4s-ccp-input") this.#input.schema.default = inp.value }) defaultinp.addEventListener("change", ev=>{ const inp = this.querySelector("d4s-ccp-input") this.#input.schema.default = inp.value }) defaultinp.addEventListener("click", ev=>{ const src = ev.target.getAttribute("name") if (src === "plus" || src === "minus") { const inp = this.querySelector("d4s-ccp-input") this.#input.schema.default = inp.value } }) this.addEventListener("input", ev=>{ const val = ev.target.value const ename = ev.target.getAttribute("name") const display = this.querySelector("div[name='default-container']") if(ename === "id"){ this.#input.id = val } else if(ename === "title"){ this.#input.title = val display.innerHTML = this.renderDefaultByType() } else if(ename === "description"){ this.#input.description = val display.innerHTML = this.renderDefaultByType() } else if(ename === "minOccurs"){ this.#input.minOccurs = Number(val) ? Number(val) : 0 display.innerHTML = this.renderDefaultByType() } else if(ename === "maxOccurs"){ this.#input.maxOccurs = Number(val) ? Number(val) : 0 display.innerHTML = this.renderDefaultByType() } else if(ename === "format"){ this.#input.schema.format = val display.innerHTML = this.renderDefaultByType() } else if(ename === "contentMediaType"){ this.#input.schema.contentMediaType = val display.innerHTML = this.renderDefaultByType() } else if(ename === "options"){ this.#input.schema.enum = val.split(",") display.innerHTML = this.renderDefaultByType() } else if(ename === "readonly"){ this.#input.schema.readOnly = ev.target.checked display.innerHTML = this.renderDefaultByType() } else if(ename === "type"){ this.#type = ev.target.value if(this.#type === "enum"){ this.querySelector("div[name=string-input]").classList.add("d-none") this.querySelector("div[name=enum-input]").classList.remove("d-none") this.#input.schema.enum = this.querySelector("input[name=options]").value.split(",") }else if(this.#type === "string"){ this.querySelector("div[name=enum-input]").classList.add("d-none") this.querySelector("div[name=string-input]").classList.remove("d-none") delete this.#input.schema['enum'] } display.innerHTML = this.renderDefaultByType() } }) } } window.customElements.define('d4s-ccp-input-editor', CCPInputWidgetEditorController);