import msgs from '../i18n/en.json'; import mustache from 'mustache'; import { menuTemplate, legacyMenuTemplate } from './Menu.stories.data'; import userLinksTemplateLegacy from '!!raw-loader!../includes/templates/LegacyUserLinks.mustache'; import userLinksTemplate from '!!raw-loader!../includes/templates/UserLinks.mustache'; import userLinksLogoutTemplate from '!!raw-loader!../includes/templates/UserLinks__logout.mustache'; import userLinksLoginTemplate from '!!raw-loader!../includes/templates/UserLinks__login.mustache'; import { helperClassName, helperMakeMenuData } from './utils'; /** * Legacy User Links */ const ECHO_ITEMS = `
  • Alerts (0)
  • Notices (3)
  • `; const USERNAME_ITEM = `
  • WikiUser
  • `; const REST_ITEMS = `
  • Talk
  • Sandbox
  • Preferences
  • Beta
  • Watchlist
  • Contributions
  • `; const LOGOUT_ITEM = `
  • Log out
  • `; const ULS_LANGUAGE_SELECTOR = '
  • English
  • '; /** * @type {MenuDefinition} */ const loggedOut = helperMakeMenuData( 'personal', `
  • Not logged in
  • Talk
  • Contributions
  • Create account
  • Log in
  • `, helperClassName( 'vector-user-menu-legacy' ) ); /** * @type {MenuDefinition} */ const loggedInWithEcho = helperMakeMenuData( 'personal', `${USERNAME_ITEM}${ECHO_ITEMS}${REST_ITEMS}${LOGOUT_ITEM}`, helperClassName( 'vector-user-menu-legacy' ) ); /** * @type {MenuDefinition} */ const loggedInWithULS = helperMakeMenuData( 'personal', `${ULS_LANGUAGE_SELECTOR}${USERNAME_ITEM}${ECHO_ITEMS}${REST_ITEMS}${LOGOUT_ITEM}`, helperClassName( 'vector-user-menu-legacy' ) ); /** * @type {Object.} */ const PERSONAL_MENU_TEMPLATE_DATA = { loggedOut, loggedInWithEcho, loggedInWithULS }; /** * Modern User Links */ const LOGGED_IN_ITEMS = `
  • Talk
  • Sandbox
  • Preferences
  • Beta
  • Uploads
  • Contributions
  • `; const LOGGED_OUT_ITEMS = `
  • Talk
  • Contributions
  • `; const LOGGED_IN_OVERFLOW_ITEMS = `
  • Alerts (0)
  • Notices (0)
  • `; const LOGGED_OUT_OVERFLOW_ITEMS = ` `; const loggedInData = { class: 'vector-user-menu vector-menu-dropdown vector-user-menu-logged-in', 'heading-class': 'mw-ui-button mw-ui-quiet mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-userAvatar', 'html-after-portal': mustache.render( userLinksLogoutTemplate, { htmlLogout: `Log out` } ), 'is-anon': false, 'is-dropdown': true, 'has-label': true }; const loggedOutData = { class: 'vector-user-menu vector-menu-dropdown vector-user-menu-logged-out', 'heading-class': 'mw-ui-button mw-ui-quiet mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-ellipsis', 'html-before-portal': mustache.render( userLinksLoginTemplate, { htmlCreateAccount: `Create account`, htmlLogin: `Log in`, msgLearnMore: msgs[ 'vector-anon-user-menu-pages' ], htmlLearnMoreLink: `${msgs[ 'vector-anon-user-menu-pages-learn' ]}:` } ), 'is-anon': false, 'is-dropdown': true, 'has-label': true }; const overflowData = { class: 'vector-menu vector-user-menu-overflow', 'heading-class': '', 'is-dropdown': false }; /** * @type {UserLinksDefinition} */ const USER_LINKS_LOGGED_IN_TEMPLATE_DATA = { 'data-user-menu-overflow': helperMakeMenuData( 'vector-user-menu-overflow', LOGGED_IN_OVERFLOW_ITEMS, overflowData ), 'data-user-menu': helperMakeMenuData( 'personal-more', LOGGED_IN_ITEMS, loggedInData ) }; /** * @type {UserLinksDefinition} */ const USER_LINKS_LOGGED_OUT_TEMPLATE_DATA = { 'data-user-menu-overflow': helperMakeMenuData( 'vector-user-menu-overflow', LOGGED_OUT_OVERFLOW_ITEMS, overflowData ), 'data-user-menu': helperMakeMenuData( 'personal-more', LOGGED_OUT_ITEMS, loggedOutData ) }; const USER_LINK_PARTIALS = { Menu: menuTemplate, LegacyMenu: legacyMenuTemplate }; export { PERSONAL_MENU_TEMPLATE_DATA, USER_LINKS_LOGGED_IN_TEMPLATE_DATA, USER_LINKS_LOGGED_OUT_TEMPLATE_DATA, USER_LINK_PARTIALS, userLinksTemplateLegacy, userLinksTemplate };