You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
2 years ago
|
/**
|
||
|
* @fileoverview Utility functions for propWrapperFunctions setting
|
||
|
*/
|
||
|
|
||
|
'use strict';
|
||
|
|
||
|
/** TODO: type {(string | { name: string, linkAttribute: string })[]} */
|
||
|
/** @type {any} */
|
||
|
const DEFAULT_LINK_COMPONENTS = ['a'];
|
||
|
const DEFAULT_LINK_ATTRIBUTE = 'href';
|
||
|
|
||
|
/** TODO: type {(string | { name: string, formAttribute: string })[]} */
|
||
|
/** @type {any} */
|
||
|
const DEFAULT_FORM_COMPONENTS = ['form'];
|
||
|
const DEFAULT_FORM_ATTRIBUTE = 'action';
|
||
|
|
||
|
function getFormComponents(context) {
|
||
|
const settings = context.settings || {};
|
||
|
const formComponents = /** @type {typeof DEFAULT_FORM_COMPONENTS} */ (
|
||
|
DEFAULT_FORM_COMPONENTS.concat(settings.formComponents || [])
|
||
|
);
|
||
|
return new Map(formComponents.map((value) => {
|
||
|
if (typeof value === 'string') {
|
||
|
return [value, DEFAULT_FORM_ATTRIBUTE];
|
||
|
}
|
||
|
return [value.name, value.formAttribute];
|
||
|
}));
|
||
|
}
|
||
|
|
||
|
function getLinkComponents(context) {
|
||
|
const settings = context.settings || {};
|
||
|
const linkComponents = /** @type {typeof DEFAULT_LINK_COMPONENTS} */ (
|
||
|
DEFAULT_LINK_COMPONENTS.concat(settings.linkComponents || [])
|
||
|
);
|
||
|
return new Map(linkComponents.map((value) => {
|
||
|
if (typeof value === 'string') {
|
||
|
return [value, DEFAULT_LINK_ATTRIBUTE];
|
||
|
}
|
||
|
return [value.name, value.linkAttribute];
|
||
|
}));
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
getFormComponents,
|
||
|
getLinkComponents,
|
||
|
};
|