linkComponents.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * @fileoverview Utility functions for propWrapperFunctions setting
  3. */
  4. 'use strict';
  5. /** TODO: type {(string | { name: string, linkAttribute: string })[]} */
  6. /** @type {any} */
  7. const DEFAULT_LINK_COMPONENTS = ['a'];
  8. const DEFAULT_LINK_ATTRIBUTE = 'href';
  9. /** TODO: type {(string | { name: string, formAttribute: string })[]} */
  10. /** @type {any} */
  11. const DEFAULT_FORM_COMPONENTS = ['form'];
  12. const DEFAULT_FORM_ATTRIBUTE = 'action';
  13. function getFormComponents(context) {
  14. const settings = context.settings || {};
  15. const formComponents = /** @type {typeof DEFAULT_FORM_COMPONENTS} */ (
  16. DEFAULT_FORM_COMPONENTS.concat(settings.formComponents || [])
  17. );
  18. return new Map(formComponents.map((value) => {
  19. if (typeof value === 'string') {
  20. return [value, DEFAULT_FORM_ATTRIBUTE];
  21. }
  22. return [value.name, value.formAttribute];
  23. }));
  24. }
  25. function getLinkComponents(context) {
  26. const settings = context.settings || {};
  27. const linkComponents = /** @type {typeof DEFAULT_LINK_COMPONENTS} */ (
  28. DEFAULT_LINK_COMPONENTS.concat(settings.linkComponents || [])
  29. );
  30. return new Map(linkComponents.map((value) => {
  31. if (typeof value === 'string') {
  32. return [value, DEFAULT_LINK_ATTRIBUTE];
  33. }
  34. return [value.name, value.linkAttribute];
  35. }));
  36. }
  37. module.exports = {
  38. getFormComponents,
  39. getLinkComponents,
  40. };