diff --git a/addon/components/-ember-popper-legacy.js b/addon/components/-ember-popper-legacy.js index 0c80b14..349ffd1 100644 --- a/addon/components/-ember-popper-legacy.js +++ b/addon/components/-ember-popper-legacy.js @@ -16,15 +16,15 @@ export default class EmberPopper extends EmberPopperBase { this._initialParentNode = this.element.parentNode; if (!GTE_EMBER_1_13) { - addObserver(this, 'renderInPlace', this, this._updatePopper); addObserver(this, 'eventsEnabled', this, this._updatePopper); addObserver(this, 'modifiers', this, this._updatePopper); - addObserver(this, 'registerAPI', this, this._updatePopper); addObserver(this, 'onCreate', this, this._updatePopper); addObserver(this, 'onUpdate', this, this._updatePopper); addObserver(this, 'placement', this, this._updatePopper); addObserver(this, 'popperContainer', this, this._updatePopper); addObserver(this, 'popperTarget', this, this._updatePopper); + addObserver(this, 'registerAPI', this, this._updatePopper); + addObserver(this, 'renderInPlace', this, this._updatePopper); super.didRender(...arguments); } @@ -34,15 +34,15 @@ export default class EmberPopper extends EmberPopperBase { super.willDestroyElement(...arguments); if (!GTE_EMBER_1_13) { - removeObserver(this, 'renderInPlace', this, this._updatePopper); removeObserver(this, 'eventsEnabled', this, this._updatePopper); removeObserver(this, 'modifiers', this, this._updatePopper); - removeObserver(this, 'registerAPI', this, this._updatePopper); removeObserver(this, 'onCreate', this, this._updatePopper); removeObserver(this, 'onUpdate', this, this._updatePopper); removeObserver(this, 'placement', this, this._updatePopper); removeObserver(this, 'popperContainer', this, this._updatePopper); removeObserver(this, 'popperTarget', this, this._updatePopper); + removeObserver(this, 'registerAPI', this, this._updatePopper); + removeObserver(this, 'renderInPlace', this, this._updatePopper); } const element = this._getPopperElement(); @@ -56,8 +56,8 @@ export default class EmberPopper extends EmberPopperBase { _updatePopper() { const element = this._getPopperElement(); - const renderInPlace = this.get('_renderInPlace'); const popperContainer = this.get('_popperContainer'); + const renderInPlace = this.get('_renderInPlace'); // If renderInPlace is false, move the element to the popperContainer to avoid z-index issues. // See renderInPlace for more details. @@ -75,10 +75,10 @@ export default class EmberPopper extends EmberPopperBase { @computed() get _popperHash() { return { - update: this.update.bind(this), - scheduleUpdate: this.scheduleUpdate.bind(this), + disableEventListeners: this.disableEventListeners.bind(this), enableEventListeners: this.enableEventListeners.bind(this), - disableEventListeners: this.disableEventListeners.bind(this) + scheduleUpdate: this.scheduleUpdate.bind(this), + update: this.update.bind(this) }; } } diff --git a/addon/components/ember-popper-base.js b/addon/components/ember-popper-base.js index c248cd8..0a8c612 100644 --- a/addon/components/ember-popper-base.js +++ b/addon/components/ember-popper-base.js @@ -36,14 +36,6 @@ export default class EmberPopperBase extends Component { @type(optional('object')) modifiers = null - /** - * An optional function to be called when a new target is located. - * The target is passed in as an argument to the function. - */ - @argument - @type(optional(Action)) - registerAPI = null - /** * onCreate callback merged (if present) into the Popper instance's options hash. * https://popper.js.org/popper-documentation.html#Popper.Defaults.onCreate @@ -83,6 +75,14 @@ export default class EmberPopperBase extends Component { @type(optional(Selector)) popperTarget = null + /** + * An optional function to be called when a new target is located. + * The target is passed in as an argument to the function. + */ + @argument + @type(optional(Action)) + registerAPI = null + /** * If `true`, the popper element will not be moved to popperContainer. WARNING: This can cause * z-index issues where your popper will be overlapped by DOM elements that aren't nested as @@ -95,10 +95,14 @@ export default class EmberPopperBase extends Component { // ================== PRIVATE PROPERTIES ================== /** - * Set in didInsertElement() once the Popper is initialized. - * Passed to consumers via a named yield. + * Tracks current/previous state of `_renderInPlace`. */ - _popper = null + _didRenderInPlace = false + + /** + * Tracks current/previous value of `eventsEnabled` option + */ + _eventsEnabled = null /** * Parent of the element on didInsertElement, before it may have been moved @@ -106,19 +110,19 @@ export default class EmberPopperBase extends Component { _initialParentNode = null /** - * Tracks current/previous state of `_renderInPlace`. + * Tracks current/previous value of `modifiers` option */ - _didRenderInPlace = false + _modifiers = null /** - * Tracks current/previous value of popper target + * Tracks current/previous value of `onCreate` callback */ - _popperTarget = null + _onCreate = null /** - * Tracks current/previous value of `eventsEnabled` option + * Tracks current/previous value of `onUpdate` callback */ - _eventsEnabled = null + _onUpdate = null /** * Tracks current/previous value of `placement` option @@ -126,30 +130,26 @@ export default class EmberPopperBase extends Component { _placement = null /** - * Tracks current/previous value of `modifiers` option - */ - _modifiers = null - - /** - * ID for the requestAnimationFrame used for updates, used to cancel - * the RAF on component destruction + * Set in didInsertElement() once the Popper is initialized. + * Passed to consumers via a named yield. */ - _updateRAF = null + _popper = null /** - * Tracks current/previous value of `onCreate` callback + * Tracks current/previous value of popper target */ - _onCreate = null + _popperTarget = null /** - * Tracks current/previous value of `onUpdate` callback + * Public API of the popper sent to external components in `registerAPI` */ - _onUpdate = null + _publicAPI = null /** - * Public API of the popper sent to external components in `registerAPI` + * ID for the requestAnimationFrame used for updates, used to cancel + * the RAF on component destruction */ - _publicAPI = null + _updateRAF = null // ================== LIFECYCLE HOOKS ================== @@ -202,13 +202,13 @@ export default class EmberPopperBase extends Component { return; } - const popperTarget = this._getPopperTarget(); - const renderInPlace = this.get('_renderInPlace'); const eventsEnabled = this.get('eventsEnabled'); const modifiers = this.get('modifiers'); - const placement = this.get('placement'); const onCreate = this.get('onCreate'); const onUpdate = this.get('onUpdate'); + const placement = this.get('placement'); + const popperTarget = this._getPopperTarget(); + const renderInPlace = this.get('_renderInPlace'); // Compare against previous values to see if anything has changed const didChange = renderInPlace !== this._didRenderInPlace @@ -228,12 +228,12 @@ export default class EmberPopperBase extends Component { // Store current values to check against on updates this._didRenderInPlace = renderInPlace; - this._popperTarget = popperTarget; this._eventsEnabled = eventsEnabled; this._modifiers = modifiers; - this._placement = placement; this._onCreate = onCreate; this._onUpdate = onUpdate; + this._placement = placement; + this._popperTarget = popperTarget; const options = { eventsEnabled, @@ -297,10 +297,10 @@ export default class EmberPopperBase extends Component { // bootstrap the public API with fields that are guaranteed to be static, // such as imperative actions this._publicAPI = { - update: this.update.bind(this), - scheduleUpdate: this.scheduleUpdate.bind(this), + disableEventListeners: this.disableEventListeners.bind(this), enableEventListeners: this.enableEventListeners.bind(this), - disableEventListeners: this.disableEventListeners.bind(this) + scheduleUpdate: this.scheduleUpdate.bind(this), + update: this.update.bind(this) }; } diff --git a/addon/components/ember-popper.js b/addon/components/ember-popper.js index c2afa50..c629314 100644 --- a/addon/components/ember-popper.js +++ b/addon/components/ember-popper.js @@ -1,5 +1,5 @@ -import { guidFor } from '@ember/object/internals'; import EmberPopperBase from './ember-popper-base'; +import { guidFor } from '@ember/object/internals'; export default class EmberPopper extends EmberPopperBase { diff --git a/addon/templates/components/-ember-popper-legacy.hbs b/addon/templates/components/-ember-popper-legacy.hbs index 31c3559..3fd9715 100644 --- a/addon/templates/components/-ember-popper-legacy.hbs +++ b/addon/templates/components/-ember-popper-legacy.hbs @@ -1,6 +1,6 @@ {{yield (hash - update=(action 'update') - scheduleUpdate=(action 'scheduleUpdate') - enableEventListeners=(action 'enableEventListeners') disableEventListeners=(action 'disableEventListeners') + enableEventListeners=(action 'enableEventListeners') + scheduleUpdate=(action 'scheduleUpdate') + update=(action 'update') )}} diff --git a/addon/templates/components/ember-popper.hbs b/addon/templates/components/ember-popper.hbs index 1da12f5..3762fa3 100644 --- a/addon/templates/components/ember-popper.hbs +++ b/addon/templates/components/ember-popper.hbs @@ -3,10 +3,10 @@ {{#if renderInPlace}}
{{yield (hash - update=(action 'update') - scheduleUpdate=(action 'scheduleUpdate') - enableEventListeners=(action 'enableEventListeners') disableEventListeners=(action 'disableEventListeners') + enableEventListeners=(action 'enableEventListeners') + scheduleUpdate=(action 'scheduleUpdate') + update=(action 'update') )}}
{{else}} @@ -20,10 +20,10 @@ {{!-- Add a wrapper around the yielded block so we have something for the Popper to target --}}
{{yield (hash - update=(action 'update') - scheduleUpdate=(action 'scheduleUpdate') - enableEventListeners=(action 'enableEventListeners') disableEventListeners=(action 'disableEventListeners') + enableEventListeners=(action 'enableEventListeners') + scheduleUpdate=(action 'scheduleUpdate') + update=(action 'update') )}}
{{/-in-element}}