UNPKG

@public-ui/components

Version:

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

99 lines (95 loc) 3.57 kB
/*! * KoliBri - The accessible HTML-Standard */ 'use strict'; var componentNames = require('./component-names-5KS_pYRF.js'); var common = require('./common-DPb6NWR4.js'); const searchFormElement = (el) => { if (common.getExperimentalMode()) { common.devHint(`↓ Search form element start.`); common.Log.debug(el); } while (el instanceof HTMLElement && el.tagName !== 'FORM' && el.tagName !== componentNames.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 (common.getExperimentalMode()) { common.Log.debug(el); } } if (common.getExperimentalMode()) { common.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') { common.setEventTarget(event, form); form.dispatchEvent(event); } else if (form.tagName === componentNames.KolFormTag.toUpperCase()) { common.setEventTarget(event, common.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 (common.getExperimentalMode() && form.noValidate === false) { common.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 { common.setEventTarget(event, form); form.dispatchEvent(event); } }); } else if (form.tagName === componentNames.KolFormTag.toUpperCase()) { common.setEventTarget(event, common.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); } }); } } }; exports.propagateResetEventToForm = propagateResetEventToForm; exports.propagateSubmitEventToForm = propagateSubmitEventToForm; //# sourceMappingURL=controller-BMDxsRHs.js.map //# sourceMappingURL=controller-BMDxsRHs.js.map