UNPKG

@public-ui/components

Version:

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

86 lines (82 loc) 3.33 kB
/*! * KoliBri - The accessible HTML-Standard */ 'use strict'; var common = require('./common-DPb6NWR4.js'); const mapCustomIcon = (state, alignment, icon) => { if (common.isObject(icon)) { state[alignment] = icon; } else if (common.isString(icon, 1)) { state[alignment] = { icon: icon, }; } }; const mapIconProp2State = (icon) => { let state = {}; if (common.isString(icon, 1)) { state = { left: { icon: icon, }, }; } else if (typeof icon === 'object' && icon !== null) { mapCustomIcon(state, 'top', icon.top); mapCustomIcon(state, 'right', icon.right); mapCustomIcon(state, 'bottom', icon.bottom); mapCustomIcon(state, 'left', icon.left); } return state; }; const beforePatchIcon = (component) => { var _a, _b, _c; if ((_a = component.nextState) === null || _a === void 0 ? void 0 : _a.has('_icons')) { const icons = (_b = component.nextState) === null || _b === void 0 ? void 0 : _b.get('_icons'); (_c = component.nextState) === null || _c === void 0 ? void 0 : _c.set('_icons', mapIconProp2State(icons)); } }; const isIcon = (value) => typeof value === 'object' && value !== null && (typeof value.style === 'undefined' || common.isStyle(value.style)) && (typeof value.label === 'undefined' || common.isString(value.label)) && common.isString(value.icon, 1); const validateIcons = (component, value, options = {}) => { common.objectObjectHandler(value, () => { var _a; try { value = common.parseJson(value); } catch (_b) { } common.watchValidator(component, '_icons', (value) => { const valueIsEmptyObject = typeof value === 'object' && value !== null && Object.keys(value).length === 0; return (value === null || valueIsEmptyObject || common.isString(value, 1) || (typeof value === 'object' && value !== null && (common.isString(value.left, 0) || isIcon(value.left) || common.isString(value.right, 0) || isIcon(value.right) || common.isString(value.top, 0) || isIcon(value.top) || common.isString(value.bottom, 0) || isIcon(value.bottom)))); }, new Set(['KoliBriIcon']), value, Object.assign(Object.assign({}, options), { defaultValue: {}, hooks: { afterPatch: (_a = options.hooks) === null || _a === void 0 ? void 0 : _a.afterPatch, beforePatch: (nextValue, nextState, component, key) => { var _a, _b; if (typeof ((_a = options.hooks) === null || _a === void 0 ? void 0 : _a.beforePatch) === 'function') { (_b = options.hooks) === null || _b === void 0 ? void 0 : _b.beforePatch(nextValue, nextState, component, key); } beforePatchIcon(component); }, } })); }); }; exports.validateIcons = validateIcons; //# sourceMappingURL=icons-C4O3H4TU.js.map //# sourceMappingURL=icons-C4O3H4TU.js.map