diff --git a/build-system/test-configs/dep-check-config.js b/build-system/test-configs/dep-check-config.js index a748b626eace..919b1cad84c5 100644 --- a/build-system/test-configs/dep-check-config.js +++ b/build-system/test-configs/dep-check-config.js @@ -265,12 +265,11 @@ exports.rules = [ 'extensions/amp-story-education/0.1/amp-story-education.js->extensions/amp-story/1.0/amp-story-localization-service.js', // Story share menu - 'extensions/amp-story-share-menu/0.1/amp-story-share-menu.js->extensions/amp-story/1.0/utils.js', + 'extensions/amp-story-share-menu/0.1/amp-story-share-menu.js->extensions/amp-social-share/0.1/amp-social-share.js', 'extensions/amp-story-share-menu/0.1/amp-story-share-menu.js->extensions/amp-story/1.0/amp-story-store-service.js', - 'extensions/amp-story-share-menu/0.1/amp-story-share-menu.js->extensions/amp-story/1.0/amp-story-localization-service.js', + 'extensions/amp-story-share-menu/0.1/amp-story-share-menu.js->extensions/amp-story/1.0/utils.js', 'extensions/amp-story-share-menu/0.1/amp-story-share-menu.js->extensions/amp-story/1.0/request-utils.js', 'extensions/amp-story-share-menu/0.1/amp-story-share-menu.js->extensions/amp-story/1.0/toast.js', - 'extensions/amp-story/1.0/amp-story-share.js->extensions/amp-story-share-menu/0.1/amp-story-share-menu.js', // Story Shopping 'extensions/amp-story-shopping/0.1/amp-story-shopping-config.js->extensions/amp-story/1.0/amp-story-store-service.js', diff --git a/examples/visual-tests/amp-story/share-menu.html b/examples/visual-tests/amp-story/share-menu.html index 7eb588edad2f..c194ce37326b 100644 --- a/examples/visual-tests/amp-story/share-menu.html +++ b/examples/visual-tests/amp-story/share-menu.html @@ -5,12 +5,10 @@ - amp-story share menu visual diff - + - + @@ -61,8 +61,8 @@ - - + +

Hello world!

diff --git a/examples/visual-tests/amp-story/share-menu.rtl.html b/examples/visual-tests/amp-story/share-menu.rtl.html index 5a97520b4114..a07842062f65 100644 --- a/examples/visual-tests/amp-story/share-menu.rtl.html +++ b/examples/visual-tests/amp-story/share-menu.rtl.html @@ -5,12 +5,10 @@ - amp-story share menu visual diff - + @@ -61,14 +61,13 @@ - - + +

مرحبا بالعالم

- - diff --git a/extensions/amp-story-share-menu/0.1/amp-story-share-menu.js b/extensions/amp-story-share-menu/0.1/amp-story-share-menu.js index 8c9f37daed8b..c7386f473ef9 100644 --- a/extensions/amp-story-share-menu/0.1/amp-story-share-menu.js +++ b/extensions/amp-story-share-menu/0.1/amp-story-share-menu.js @@ -1,10 +1,10 @@ import {userAssert} from '#core/assert'; import {Keys_Enum} from '#core/constants/key-codes'; import * as Preact from '#core/dom/jsx'; +import {Layout_Enum} from '#core/dom/layout'; import {closestAncestorElementBySelector} from '#core/dom/query'; import {isObject} from '#core/types'; import {map} from '#core/types/object'; -import {getWin} from '#core/window'; import { copyTextToClipboard, isCopyingToClipboardSupported, @@ -20,15 +20,15 @@ import {Toast} from 'extensions/amp-story/1.0/toast'; import {CSS} from '../../../build/amp-story-share-menu-0.1.css'; import {getAmpdoc} from '../../../src/service-helpers'; -import {localize} from '../../amp-story/1.0/amp-story-localization-service'; import { Action, StateProperty, UIType, - getStoreService, } from '../../amp-story/1.0/amp-story-store-service'; import {createShadowRootWithStyle} from '../../amp-story/1.0/utils'; +import '../../amp-social-share/0.1/amp-social-share'; + /** @const {string} Class to toggle the share menu. */ export const VISIBLE_CLASS = 'i-amphtml-story-share-menu-visible'; @@ -52,13 +52,13 @@ const SHARE_PROVIDER_LOCALIZED_STRING_ID = map({ * Key for share providers in config. * @const {string} */ -export const SHARE_PROVIDERS_KEY = 'shareProviders'; +const SHARE_PROVIDERS_KEY = 'shareProviders'; /** * Deprecated key for share providers in config. * @const {string} */ -export const DEPRECATED_SHARE_PROVIDERS_KEY = 'share-providers'; +const DEPRECATED_SHARE_PROVIDERS_KEY = 'share-providers'; /** * @param {!Node} child @@ -70,52 +70,53 @@ const renderShareItemElement = (child) => ( /** * Share menu UI. */ -export class AmpStoryShareMenu { +export class AmpStoryShareMenu extends AMP.BaseElement { /** - * @param {!Element} hostEl + * @param {!Element} element */ - constructor(hostEl) { - /** @private @const {!Window} */ - this.win_ = getWin(hostEl); + constructor(element) { + super(element); /** @private {?Element} */ - this.element_ = null; - - /** @private @const {!./amp-story-store-service.AmpStoryStoreService} */ - this.storeService_ = getStoreService(this.win_); + this.rootEl_ = null; /** @private @const {!Element} */ this.storyEl_ = userAssert( - closestAncestorElementBySelector(hostEl, 'amp-story') + closestAncestorElementBySelector(element, 'amp-story') ); /** @const @private {!../../../src/service/vsync-impl.Vsync} */ - this.vsync_ = Services.vsyncFor(this.win_); + this.vsync_ = Services.vsyncFor(this.win); - /** @private {!Element} */ - this.hostEl_ = hostEl; + /** @private {?../../../src/service/localization.LocalizationService} */ + this.localizationService_ = null; + + /** @private {?../../../extensions/amp-story/1.0/amp-story-store-service.AmpStoryStoreService} */ + this.storeService_ = null; } /** * Builds and appends the component in the story. Could build either the * amp-social-share button to display the native system sharing, or a fallback * UI. + * @return {!Promise} */ - build() { - if (this.element_) { + buildCallback() { + if (this.rootEl_) { return; } - const providersList = this.buildProvidersList_(); - this.element_ = this.buildDialog_(providersList); - // TODO(mszylkowski): import '../../amp-social-share/0.1/amp-social-share' when this file is lazy loaded. - Services.extensionsFor(this.win_).installExtensionForDoc( - getAmpdoc(this.storyEl_), - 'amp-social-share' - ); - - this.vsync_.mutate(() => { - createShadowRootWithStyle(this.hostEl_, this.element_, CSS); + return Promise.all([ + Services.storyStoreServiceForOrNull(this.win).then( + (service) => (this.storeService_ = service) + ), + Services.localizationServiceForOrNull(this.element).then( + (service) => (this.localizationService_ = service) + ), + ]).then(() => { + const providersList = this.buildProvidersList_(); + this.rootEl_ = this.buildDialog_(providersList); + createShadowRootWithStyle(this.element, this.rootEl_, CSS); this.initializeListeners_(); }); } @@ -140,7 +141,7 @@ export class AmpStoryShareMenu { true /** callToInitialize */ ); - this.win_.addEventListener('keyup', (event) => { + this.win.addEventListener('keyup', (event) => { if (event.key == Keys_Enum.ESCAPE) { event.preventDefault(); this.close_(); @@ -155,8 +156,8 @@ export class AmpStoryShareMenu { */ onShareMenuStateUpdate_(isOpen) { this.vsync_.mutate(() => { - this.element_.classList.toggle(VISIBLE_CLASS, isOpen); - this.element_.setAttribute('aria-hidden', !isOpen); + this.rootEl_.classList.toggle(VISIBLE_CLASS, isOpen); + this.rootEl_.setAttribute('aria-hidden', !isOpen); }); } @@ -168,8 +169,8 @@ export class AmpStoryShareMenu { onUIStateUpdate_(uiState) { this.vsync_.mutate(() => { uiState !== UIType.MOBILE - ? this.element_.setAttribute('desktop', '') - : this.element_.removeAttribute('desktop'); + ? this.rootEl_.setAttribute('desktop', '') + : this.rootEl_.removeAttribute('desktop'); }); } @@ -202,8 +203,7 @@ export class AmpStoryShareMenu {