import { createElement } from "../lib/skeleton/index.js"; import { safe } from "../lib/dom.js"; import { gid } from "../lib/random.js"; import "./icon.js"; export function formTmpl(options = {}) { const { autocomplete = true, renderNode = null, renderLeaf = null } = options; return { renderNode: (opts) => { if (renderNode) { const $el = renderNode({ ...opts, format }); if ($el) return $el; } const { label } = opts; return createElement(`
`); }, renderLeaf: (opts) => { if (renderLeaf) { const $el = renderLeaf({ ...opts, format }); if ($el) return $el; } const { label } = opts; return createElement(` `); }, renderInput: $renderInput({ autocomplete }), formatLabel: format }; }; function $renderInput(options = {}) { const { autocomplete } = options; return function(props) { const { id = null, type, value = null, placeholder = "", required = false, readonly = false, path = [], datalist = null, options = null } = props; let attr = `name="${path.join(".")}" `; if (id) attr += `id="${id}" `; if (placeholder) attr += `placeholder="${safe(placeholder, "\"")}" `; if (!autocomplete) attr += "autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"off\" "; if (required) attr += "required "; if (readonly) attr += "readonly "; switch (type) { case "text": // TODO const dataListId = gid("list_"); const $input = createElement(` `); if (!datalist) return $input; const $wrapper = window.document.createElement("span"); const $datalist = window.document.createElement("datalist"); $wrapper.appendChild($input); $datalist.setAttribute("id", dataListId); return $wrapper; case "enable": return createElement(`