import msgs from '../i18n/en.json'; import mustache from 'mustache'; import { menuTemplate } from './Menu.stories.data'; import userLinksTemplateLegacy from '!!raw-loader!../includes/templates/legacy/UserLinks.mustache'; import userLinksTemplate from '!!raw-loader!../includes/templates/UserLinks.mustache'; import userLinksMoreTemplate from '!!raw-loader!../includes/templates/UserLinks__more.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
  • Watchlist
  • Contributions
  • `; const LOGGED_OUT_ITEMS = `
  • Talk
  • Contributions
  • `; const additionalUserMoreData = { class: 'vector-menu vector-user-menu-more', 'heading-class': 'vector-menu-heading', 'is-dropdown': false }; const userMoreHtmlItems = ( isAnon = true ) => mustache.render( userLinksMoreTemplate, { 'is-anon': isAnon, 'is-create-account-allowed': isAnon, 'html-create-account': `Create account`, 'data-user-page': helperMakeMenuData( 'user-page', ` ` ), 'data-notifications': helperMakeMenuData( 'notifications', ECHO_ITEMS ) } ); const loggedInData = { class: 'vector-user-menu vector-menu-dropdown vector-user-menu-logged-in', 'is-dropdown': true, 'heading-class': 'mw-ui-button mw-ui-quiet mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-userAvatar', 'is-anon': false, 'html-after-portal': mustache.render( userLinksLogoutTemplate, { htmlLogout: `Log out` } ) }; const loggedOutData = { class: 'vector-user-menu vector-menu-dropdown vector-user-menu-logged-out', 'is-dropdown': true, 'heading-class': 'mw-ui-button mw-ui-quiet mw-ui-icon mw-ui-icon-element mw-ui-icon-wikimedia-ellipsis', 'is-anon': true, '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' ]}:` } ) }; /** * @type {UserLinksDefinition} */ const USER_LINKS_LOGGED_IN_TEMPLATE_DATA = { 'data-user-more': helperMakeMenuData( 'personal-more', userMoreHtmlItems( false ), additionalUserMoreData ), 'data-user-menu': helperMakeMenuData( 'new-personal', LOGGED_IN_ITEMS, loggedInData ) }; /** * @type {UserLinksDefinition} */ const USER_LINKS_LOGGED_OUT_TEMPLATE_DATA = { 'data-user-more': helperMakeMenuData( 'personal-more', userMoreHtmlItems( true ), additionalUserMoreData ), 'data-user-menu': helperMakeMenuData( 'new-personal', LOGGED_OUT_ITEMS, loggedOutData ) }; const USER_LINK_PARTIALS = { Menu: menuTemplate }; export { PERSONAL_MENU_TEMPLATE_DATA, USER_LINKS_LOGGED_IN_TEMPLATE_DATA, USER_LINKS_LOGGED_OUT_TEMPLATE_DATA, USER_LINK_PARTIALS, userLinksTemplateLegacy, userLinksTemplate };