UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

97 lines (94 loc) 3.44 kB
/*! * KoliBri - The accessible HTML-Standard */ import { f as KolFormTag } from './component-names.js'; import './common.js'; import { J as getExperimentalMode, j as devHint, g as setEventTarget, K as KoliBriDevHelper, L as Log } from './prop.validators.js'; const searchFormElement = (el) => { if (getExperimentalMode()) { devHint(`↓ Search form element start.`); Log.debug(el); } while (el instanceof HTMLElement && el.tagName !== 'FORM' && el.tagName !== KolFormTag.toUpperCase()) { try { if (el.parentElement instanceof HTMLElement) { el = el.parentElement; } else if (el.parentNode instanceof ShadowRoot) { el = el.parentNode.host; } else { el = null; } } catch (_a) { } if (getExperimentalMode()) { Log.debug(el); } } if (getExperimentalMode()) { devHint(`↑ Search form element finished.`); } return el; }; const propagateResetEventToForm = (options = {}) => { var _a, _b; const form = searchFormElement(options.form); if (form instanceof HTMLElement) { const event = new Event('reset', { bubbles: true, cancelable: true, }); if (form.tagName === 'FORM') { setEventTarget(event, form); form.dispatchEvent(event); } else if (form.tagName === KolFormTag.toUpperCase()) { setEventTarget(event, KoliBriDevHelper.querySelector('form', form)); const kolForm = form; if (typeof ((_a = kolForm._on) === null || _a === void 0 ? void 0 : _a.onReset) === 'function') { (_b = kolForm._on) === null || _b === void 0 ? void 0 : _b.onReset(event); } } } }; const propagateSubmitEventToForm = (options = {}) => { const form = searchFormElement(options.form); if (form instanceof HTMLElement) { const event = new SubmitEvent('submit', { bubbles: true, cancelable: true, submitter: form, }); if (form.tagName === 'FORM') { if (getExperimentalMode() && form.noValidate === false) { devHint(`If you have not focusable or hidden form fields in your form, you should enable noValidate for your form.`, { force: true, }); } setTimeout(() => { if (typeof form.requestSubmit === 'function') { form.requestSubmit(); } else { setEventTarget(event, form); form.dispatchEvent(event); } }); } else if (form.tagName === KolFormTag.toUpperCase()) { setEventTarget(event, KoliBriDevHelper.querySelector('form', form)); const kolForm = form; setTimeout(() => { var _a, _b; if (typeof ((_a = kolForm._on) === null || _a === void 0 ? void 0 : _a.onSubmit) === 'function') { (_b = kolForm._on) === null || _b === void 0 ? void 0 : _b.onSubmit(event); } }); } } }; export { propagateResetEventToForm as a, propagateSubmitEventToForm as p }; //# sourceMappingURL=controller2.js.map //# sourceMappingURL=controller2.js.map