Git Product home page Git Product logo

ember-wormhole's Introduction

Ember Wormhole Build Status Ember Observer Score

This addon provides a component that allows for rendering a block to a DOM element somewhere else on the page. The component retains typical Ember context in terms of bound data and action handling. Ember Wormhole is compatible with Ember FastBoot as of version 0.4.0, so long as the destination element is part of Ember's own templates.

Live Demo

View a live demo here: http://yapplabs.github.io/ember-wormhole/

The source code for the demo is available here: https://github.com/yapplabs/ember-wormhole/tree/master/tests/dummy/app

But Why?

This library is particularly useful for cases where you have UI that is the logical child of a component but needs to render as a top-level DOM element, such as a confirmation dialog.

And How?

This component tracks its element's child nodes. When inserted into the DOM, it appends its child nodes to a destination element elsewhere. When removed from the DOM, it removes its child nodes, so as not to orphan them on the other side of the wormhole.

Nothing else changes -- data binding and action bubbling still flow according to the Ember component hierarchy. That includes usages of yield, so blocks provided to ember-wormhole simply appear in another part of the DOM.

Show Me Some Code!

We thought you'd never ask...

Given the following DOM:

<body class="ember-application">
  <!-- Destination must be in the same element as your ember app -->
  <!-- otherwise events/bindings will not work -->
  <div id="destination">
  </div>
  <div class="ember-view">
    <!-- rest of your Ember app's DOM... -->
  </div>
</body>

and a template like this:

{{#ember-wormhole to="destination"}}
  Hello world!
{{/ember-wormhole}}

Then "Hello world!" would be rendered inside the destination div.

If the ember-wormhole is destroyed its far-off children are destroyed too. For example, given:

{{#if isWormholeEnabled}}
  {{#ember-wormhole to="destination"}}
    Hello world!
  {{/ember-wormhole}}
{{/if}}

If isWormholeEnabled starts off true and becomes false, then the "Hello world!" text will be removed from the destination div.

Similarly, if you use ember-wormhole in a route's template, it will render its children in the destination element when the route is entered and remove them when the route is exited.

Can I Render In Place (i.e. Unwormhole)?

Yes! Sometimes you feel like a wormhole. Sometimes you don't. Situations sometimes call for the same content to be rendered through the wormhole or in place.

In this example, renderInPlace will override to and cause the wormhole content to be rendered in place.

{{#ember-wormhole to="destination" renderInPlace=true}}
  Hello world!
{{/ember-wormhole}}

This technique is useful for:

  • Presenting typically-wormholed content within a styleguide
  • Toggling content back and forth through the wormhole
  • Parlor tricks

What if if my element has no id?

You can provide an element directly to the wormhole. For example:

{{#ember-wormhole destinationElement=someElement}}
  Hello world!
{{/ember-wormhole}}

This usage may be appropriate when using wormhole with dynamic targets, such as rendering into all elements matching a selector.

What Version of Ember is This Compatible With?

This library is compatible with and tested against Ember 1.13 and higher.

Important Note about using this library with Ember 2.10

With latest ember-wormhole and [email protected], you need to have a stable root element inside the wormhole block. This is something that the Ember Core team will continue to iterate and work on, but for now the work around is fairly straightforward.

Change:

{{#ember-wormhole to="worm"}}
  {{#if foo}}

  {{/if}}
  <p>Other content, whatever</p>
{{/ember-wormhole}}
To:

{{#ember-wormhole to="worm"}}
  <div>
    {{#if foo}}

    {{/if}}
    <p>Other content, whatever</p>
  </div>
{{/ember-wormhole}}

Ember's native in-element

Since Ember 3.21 there is also a native in-element helper. This helper offer a bit less functionality than this addon, but may be enough for your use case! For more info see the in-element API docs and the excellent article by Faith Or comparing ember-wormhole and in-element

Development Setup

Simple Installation

To add the ember-wormhole add-on to an existing project, enter this command from the root of your EmberJS project:

  • ember install ember-wormhole

Setting Up The Demo

If you'd like to set up a new EmberJS application with the ember-wormhole sample application configured, follow these steps:

  • git clone this repository
  • npm install
  • bower install

Running Tests

  • ember try:testall
  • ember test
  • ember test --server

Running the dummy app

For more information on using ember-cli, visit http://www.ember-cli.com/.

Credits

This addon was extracted from ember-modal-dialog. Contributions from @stefanpenner, @krisselden, @chrislopresto, @lukemelia, @raycohen and others. Yapp Labs is an Ember.js consultancy based in NYC.

ember-wormhole's People

Contributors

adamesque avatar andrewhavens avatar bantic avatar btecu avatar chadhietala avatar chrislopresto avatar cibernox avatar dependabot[bot] avatar dhaulagiri avatar ember-tomster avatar graham-sportsmgmt avatar krisselden avatar lukemelia avatar mixonic avatar nlfurniss avatar olivierlesnicki avatar piotrpalek avatar runspired avatar rwjblue avatar sandstrom avatar sandydoo avatar simonihmig avatar stefanpenner avatar tim-evans avatar turbo87 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-wormhole's Issues

Actions not firing in acceptance test

Hi,

This only happens during a test.

Basically, it seems that when I have an interactive element mounted into something via wormhole, i.e. a popup menu with some menu buttons. clicking never triggers the action.

I am trying to trigger a menu open, and then a click button.

Any ideas?

Thanks

Keeping children in destination element

According to the docs, if a wormhole is used on a route's template it will render it's children in the destination element when the route is rendered and removed when the route is exited.

With that being said, is there any way to keep the children in the destination element even after the route is exited?

My use case is to update the destination element every time a route changes but to keep the route's children in the destination element until the new route's children are ready to be injected via the wormhole

Integration tests fail with ember-wormhole

The default generated component integration tests from ember-cli fail if you use ember-wormhole in that component, since the destination element would be elsewhere in your application.

throw new Error(`ember-wormhole failed to render into '#${this.get('destinationElementId')}' because the element is not in the DOM`);

This can be fixed by shimming the destination into those tests, but I'm wondering if changing to a warning or assert instead of throwing an error may be a better experience?

How to ignore moving to a Div if it doesn't exist?

I'm using a third party plugin that I have no control over how it renders some divs. Some divs can be rendered, some not, depending on your screen width. The problem is that ember wormhole tries to look for that div id and if it doesn't exist, it will just throw an error. Is there a way to just say "don't try to move it if that div doesn't exist" instead?

I was thinking of an {{else}} for the wormhole, but other might want to catch the error instead.

EDIT: I'd rather just ignore the error and do nothing instead of checking if the div exists because it will be a costly operation.

Thanks

Triggers error on Glimmer

Hey,

after I upgraded from 0.1.x to latest release I can successfully open a wormhole.
When I try to navigate to another page tho, I get this error:

TypeError: Cannot read property 'previousSibling' of null
    at removeRange (ember-wormhole.js:62)
    at ember-wormhole.js:29
    at Queue.invokeWithOnError (ember.debug.js:887)
    at Object.Queue.flush (ember.debug.js:943)
    at Object.DeferredActionQueues.flush (ember.debug.js:748)
    at Object.Backburner.end (ember.debug.js:173)
    at Object.Backburner.run (ember.debug.js:219)
    at Object.run (ember.debug.js:17119)
    at ember$data$lib$system$adapter$$Adapter.extend.ajax.Ember.RSVP.Promise.hash.success (rest-adapter.js:788)

Really not sure if this is a Glimmer regression or wormhole using private deprecated API, so opening an issue here for starters.

BR,
Dominik

Renders in place in Fastboot environment

I'm running on 2.10.0 and there seems an issue where all wormholes are rendered in place in Fastboot environment, E.g:

<div id="destination"></div>
{{#ember-wormhole to="destination"}}
  <p>Hello world!</p>
{{/ember-wormhole}}


{{!-- renders to: --}}
<div id="destination"></div>
<div id="ember2023" class="ember-view">
    <p>Hello world!</p>
</div>

Not sure if this is expected behavior when in Fastboot or a bug.

Packaged versions of ember wormhole lose focus on "wormholing"

Hello, we were running into the same issue as fixed in #23. It appears that the last packaged version (0.3.4) was released before that was merged, so it still happens when just doing an "ember install ember-wormhole". Would it be possible to get a newer version released?

Thanks.

Ability to replace content instead of appending

Looking at the current code, it seems that ember-wormhole only supports appending content into the destination. While this makes sense in a lot of cases, we have a use-case where it would be beneficial to replace the content of the destination instead.

In short, we have a portion of our app being SSR'd and after boot up on the client, we're using ember-wormhole to inject some dynamic content and it works wonderfully. But, for SEO and slower phones, we initially render some placeholder content, which we currently have to manually remove. It would be nice if ember-wormhole could handle that for us.

Edit: if this seems like a reasonable ask, I'll implement it.

Destination rerender breaks subsequent data changes

I have something like the following, where the content of setContent is the destination. I recreate this destination every time, without changing the to attribute. Since the destinationElement is cached, the wormhole only works the first time, but once the popup is re-rendered it does not put the new data there.

      openPopup(lane) {
        var popup = this.get('mapPopup');
        var feature = lane.get('boothFeature');
        var map = this.get('map');

        if (popup.getPosition()) {
          this.set('lane', undefined);
          popup.close();
        }

        if (feature) {
          let latlng = feature.getGeometry().get();
          let id = lane.get('id');
          let wormhole = this.get('wormhole');

          popup.setContent(`<div id='infowindow'></div>`);
          popup.setPosition(latlng);
          popup.open(map);
          this.set('lane', lane);

          // see routable-site template for wormhole/infowindow layout
          if (wormhole) {
            wormhole.rerender();
          }
        }
      },
{{#if lane}}
  {{#ember-wormhole to='infowindow' viewName='wormhole'}}
    Lane #: <b>{{lane.number}}</b><br>
    Mode: <b>{{lane.mode}}</b><br>
    Avg. Wait Time: <b>na</b>
  {{/ember-wormhole}}
{{/if}}

this._dom is undefined for Glimmer2 + Fastboot

When running addon tests in a Fastboot environment, I get the following exception since canary includes Glimmer2:

TypeError: Cannot read property 'document' of undefined

I tracked this down, this comes from this line of code: https://github.com/yapplabs/ember-wormhole/blob/master/addon/components/ember-wormhole.js#L41.

Further debugging showed that renderer._env.getDOM() indeed returns undefined over here: https://github.com/yapplabs/ember-wormhole/blob/master/addon/utils/dom.js#L50

Again, this is for the combo Glimmer2 + Fastboot. I had no problems with 2.8 in Fastboot, or beta/canary in the browser!

Inner component action sent to wormhole component instead of outer component (canary)

Using Ember canary, when an "outer" component has an "inner" component that's inside a wormhole, and the "inner" component sends an action, the action is fired on the wormhole itself, causing the error:

Uncaught Error: <emberapp@component:ember-wormhole::ember609> had no action handler for: actionName

It used to be fired correctly on the "outer" component, but is broken since emberjs/ember.js#12289.

I've also raised an issue on the ember.js repository: emberjs/ember.js#12317, but thought the issue may be able to fixed on the ember-wormhole side, or you might have some insight into how to fix the regression.

Note that this is only an error if the "inner" component and wormhole are defined in an "outer" component template; the action works fine if the component/wormhole are in a controller template.

This fiddle reproduces the issue: http://ember-twiddle.com/1c59a1dcdb18eec69a8e. Changing the ember dependency from canary to release in twiddle.json fixes the issue.

[Idea] component for the wormhole output

Basically the wormhole would know when the receiver is rendered, and only then would it transfer the yielded content.

Something like the following:

<!-- application/template.hbs -->
{{#if menuOpen}}
  {{#ember-wormhole-receiver 'sidebar-menu'}}
    Default application wide menus here
  {{/ember-wormhole-receiver}}
{{/if}}
<!-- some/route/template.hbs -->
{{#ember-wormhole 'sidebar-menu'}}
  Route menu items here with their own actions and context
{{/ember-wormhole}}

This would allow for easier implementations (not when trying to integrate with third-party libs) when working in an ember app. Think a sidebar that has a header (defined in application/template.hbs) with a dropdown menu. The sidebar content could be in any route, so we have a receiver in the header and any route can now manipulate that menu easily without having to wire up a service with a boolean.

Underneath, the two components would communicate via a service based on the identifier shared by the two.

jQuery selecting contents of a wormhole from inside component

I'm using an ember-wormhole inside a component, and am trying to access an element that's inside the wormhole with this.$() in the component.

component/template.hbs

{{#ember-wormhole to="destination"}}
  <a class="targetme">Target anchor</a>
{{/ember-wormhole}}

component/component.js

export default Ember.Component.extend({
  _select: function() {
    // doesn't work
    this.$('.targetme').focus();
    // does work
    Ember.$('#destination .targetme').focus();
  }.on('didInsertElement')
});

As mentioned in the sample above, using this.$ doesn't work, as this.$ is scoped to the component view, ember-wormhole moves the contents out of that view, meaning the component view is essentially empty (the contents I'm wanting to access are inside the wormhole).

To circumvent this, I currently have to just do a global selection with Ember.$ in my component, and target the wormhole the contents are moved to (as seen above).

Is there a better way to do this currently, that doesn't involve a global selection with Ember.$?

Explicitly define compatibility with Ember 1.13+

Tried getting this addon to work with Ember 1.12 to no avail. As soon as I upgraded the Ember version to 1.13, things worked as expected. Perhaps would be a good idea to note in the README.

Uncaught TypeError: Cannot read property 'previousSibling' of null

Hey I was trying to port my app to ember 1.13.1 and started getting this error when transitioning to other routes. I will try to make a jsbin later on, just posting this in case it is something known.
The error occurs here:

    removeRange: function removeRange(firstNode, lastNode) {
      var node = lastNode;
      do {
        var next = node.previousSibling; // <-- error from issue title

Keystrokes are dropped on wormholed inputs

I have a repository where it is reproducible:

https://github.com/prashn64/focus-repro-wormhole

This README outlines steps to reproduce (Bug 3), but it's essentially when you have a text input inside a wormhole that you only activate/deactivate when the text content changes. It seems that ripping the input out of the DOM and then re-placing it in the wormhole is causing a few keystrokes to fall through the cracks.

It's hard to see a case where it's too bad, but as the complexity of your component using the wormhole increases, the worse it gets.

Focus is dropped on iOS chrome.

The recent commit that deals with retaining works nicely with most browsers, but fails on chrome for iOS.

I have a repository where it is reproducible:

https://github.com/prashn64/focus-repro-wormhole

This README outlines steps to reproduce, but it's essentially when you have a text input inside a wormhole that you only activate/deactivate when the text content changes.

Programatically changing template?

My use case will require us to change the content in a section depending on an input action elsewhere on the page. Let's say that my navbar has two buttons on it, A and B. When the user clicks A we need to load template X into the wormhole and when they click B we need to load template Y into the wormhole.

Is this possible?

I see how the demo/dummy app is linking a wormhole to a variable called "sidebar" and switching the value in that sidebar to determine where the content is rendered. Would this mean that I'd create a bunch of wormholes each with the content I want to render and then use variables linked to their "to=" properties?

Error: The head node of a wormhole must be attached to the DOM

I just experienced a problem with ember-wormhole 4.0 used by ember-power-select.

A quick google search got me to this issue on the ghost blog, which describes exactly my problem and was solved by reverting to 0.3.6:
TryGhost/Ghost#7073

As the version upgrade 0.3.6 to 4.0 is about dom changes for fastboot, it looked possible that a bug was introduced there. So I also downgraded to 0.3.6 and that solved it without further changes.

Best regards,
Robert

Ember 2.5.1
Ember Data 2.7.0
jQuery 2.2.4

Attempting to inject an unknown injection: `service:-document`

Since having upgraded to ember-wormhole 0.5.1 in our Ember 2.7 based app I see this exception. Seems to be related to #75.

I saw this in one of our apps after updating ember-light-table, that brings in ember-wormhole 0.5.1. Added an ember-try config for Ember 2.7 here: adopted-ember-addons/ember-light-table#267, which is failing for 2.7 (see the Travis logs), probably also 2.6 (not tested).

Also tried to update ember-wormhole in my own addon ember-bootstrap (ember-bootstrap/ember-bootstrap#160) and see the same exception (see the Travis logs), for 2.7 and 2.6.

The stack trace is unfortunately cut off too early in the Travis logs, but when running tests in Chrome I saw the stack trace touching this line actually: https://github.com/yapplabs/ember-wormhole/blob/master/addon/utils/dom.js#L54. So it was not failing here https://github.com/yapplabs/ember-wormhole/blob/master/addon/utils/dom.js#L50, documentService was undefined as expected.

Tried to reproduce this within ember-wormhole itself by adding an ember-try scenario for 2.7, however that did not fail! Strange enough...

How future proof is this library?

First of all, thanks for this lib!

Even while it does not use private API, I wonder how future proof this is. It works great for me with Ember Glimmer 1.13. But what will happen when more advanced techniques are introduced to Glimmer? Shadow dom will get broken if we move Dom objects around, right? Maybe you can shed some light on the future stability of this plugin, it will help me deciding to highly use it in my UI.

Thanks

Error with Ember 2.10

Using latest 0.5. Looks like #74 is still broken?

DEBUG: Ember : 2.10.0
ember.debug.js:5732DEBUG: Ember Data : 2.10.0
ember.debug.js:5732DEBUG: jQuery : 3.1.1
ember.debug.js:5732DEBUG: Ember Simple Auth : 1.1.0

ember-wormhole.js:39 Uncaught TypeError: Cannot read property 'createTextNode' of undefined
at Class.init (http://localhost:4200/assets/vendor.js:151140:50)
at Class.superWrapper [as init] (http://localhost:4200/assets/vendor.js:51395:22)
at new Class (http://localhost:4200/assets/vendor.js:47086:17)
at Function.create (http://localhost:4200/assets/vendor.js:47374:14)
at CurlyComponentManager.create (http://localhost:4200/assets/vendor.js:23812:29)
at OpenComponentOpcode.evaluate (http://localhost:4200/assets/vendor.js:58627:37)
at VM.execute (http://localhost:4200/assets/vendor.js:65202:28)
at Object.render (http://localhost:4200/assets/vendor.js:64776:23)
at RootState.render (http://localhost:4200/assets/vendor.js:23099:46)
at runInTransaction (http://localhost:4200/assets/vendor.js:34058:28)

Call an user-provided action on didInsertElement/willDestroyElement

I have a component with a template like this:

{{#if isOpen}}
  {{#ember-wormhole to=to renderInPlace=renderInPlace}}
    <div class="{{my-class}}">{{yield}}</div>
  {{/ember-wormhole}}
{{/if}}

When the component gets opened/closed, I need to add some events to the root of the page.
I was thinking that it would be very handy to be able to instruct ember-wormhole to notify me when it gets added/removed to the dom.

My idea was {{#ember-wormhole to=to renderInPlace=renderInPlace onInsert=(action "foo") onDestroy=(action "bar")}}.

The changes to the component on the code would just be

didInsertElement() {
  // ... usual code
  this.sendAction('onInsert');
},

willDestroyElement() {
  // ... usual code
  this.sendAction('onDestroy');
}

Would you consider such addition?

[Feature] Destination component which fires up an action when wormhole is mounted

I have a use case, when I need to have some way of notifying context when wormhole is mounted into destination, eg

{{destination elementId="destination_id" action="wormholeMounted"}}
{{#ember-wormhole to="destination_id"}}
Content
{{/ember-wormhole}}

So when wormhole's content is inserted into {{destination, action wormholeMounted is fired. I already implemented this using MutationObserver in my app. Do you think it might be useful having this feature as a part of this addon? If yes, I will issue a PR. Thanks.

Wormhole causes issue with power select

Ember Power Select uses Wormhole behind the curtains, and I've found that using them on the same page causes an issue with the dropdowns. When you open a dropdown, it will not collapse again. The issue does not occur when the wormhole component is deleted from that template. Any fixes?

Append to a not empty element?

Looks like I can't set as wormhole endpoint an element with already some nodes inside. Why that? Is there any workaround?

Thanks.

memory leaks

Hello,

We have quite a lot of memory leak in our Ember acceptance tests and are trying to identify where it comes from.

We use ember-wormhole at different places in our app. Doing a javascript heap snapshot shows multiple detached nodes coming from ember-wormhole. Hard to know the exact place where the mem is not released, but by grepping what I see in the snapshot it seems like there are still references to the destroyed ember-wormhole components coming from the CachedReference of the dom (see keywords _lastValue and _wormholeTailNode below).

May that be because when destroying the app at the end of our acceptance tests we don't release all mem contained in the destination id ??

Any help very welcome,

Thanks,

L
screenshot 2017-02-19 15 20 25 2

Emberjs 2.10.0-beta.2 issues

Hi, we're testing the new ember beta and we're seeing a repetition issue with wormhole, the same code works fine on Ember 2.9. Image attached shows the repetition as well as the related console, errors.

Our use of wormhole is quite basic, we have wormhole target divs set up in a right-hand-side bar on application.hbs. The wormholes are populated from a component.

bug

Renders the content twice while liquid-fire transition is in progress

I noticed that the wormhole content is rendered twice into the target during liquid fire transitions using liquid-outlet.

I think for transitioning from route1 to route2 liquid-fire has both pages prepared. That results in rendering the wormhole content of both pages into my header buttons area.

Programmatic wormhole?

Can I programmatically populate a div with a wormhole on a DOM event? The element to populate is not created by Ember (there's no template to add a "show me" flag to.

I am creating an Ember app that is a table with, basically, a row for each Person. Each row must have an icon that the user can click to expand the row to show more data about the person (a "table row accordion"). The table is the JQuery Tabulator grid. The Ember component that holds the table initializes the Tabulator component in didInsertElement.

didInsertElement() {
let tabulator = this.$("#the-tabulator-div").tabulator({
... lot's of table config
columns: annotateLastColumn(this.get('columns')),
rowFormatter: this.rowFormatter
...
});
...grab some data and come back...
}

Later, after data is fetched, Tabulator displays the data for each row, of course creating DOM nodes at that point (and outside of Ember). This all works in a basic ugly way. The hooks for the accordion are in annotateLastColumn(), which adds an icon to the right of the last column for the user to click, and in rowFormatter(jqRow, data) - which Tabulator calls as it makes each row. The rowFormatter's parameters are the jQuery reference for the row and the row's data. The function adds a hidden div to the row with the Person detail - via straight HTML strings appended to the row. The user clicks the icon and it shows/hides. It is this div that Tabulator creates that I want to make a worm-hole when the user clicks.

Though it displays, the code is ugly - a template is preferable to JS strings. It's also outside of Ember. The accordion is intended to be interactive (the user can edit the Person data) and moveable - the user can pop it out of the table.

It seems ember-wormhole requires a template with a flag that shows/hides the wormhole. Since the divs are created by Tabulator, there is no template for ember-wormhole to leverage. When the user clicks the icon in the row, can I problematically tell Ember wormhole to "show it here"?

Wormhole from one component to another

Is it possible to wormhole from one component to another? I'm getting the "missing DOM element" error in the console and the wormholed content is rendering in place

[Glimmer2] DOMException with {{#if}} helper

When testing for compatibility of ember-bootstrap with Glimmer2, I get the following exception with the modal component that uses ember-wormhole:

DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

I narrowed it down to ember-wormhole using a conditional statement, as shown in the following minimalistic example. As soon as show is set to true, I get the mentioned exception:

{{#ember-wormhole to="worm"}}
    <p>This is wormholed content.</p>

  {{#if show}}
    <p>This is conditional content.</p>
  {{/if}}
{{/ember-wormhole}}

Here is a demo repo to replicate this bug: https://github.com/simonihmig/ember-wormhole-glimmer2-demo

I am not sure who is to blame here, if it is ember-wormhole or Glimmer2, so first filing this here for the time being...

How do I hook in to the render/move life event?

I'm trying to use foundation modals, and I have this component:

a class=buttonClasses data-reveal-id=modalId
  = buttonText

= ember-wormhole to="foundation-modals"
  div.reveal-modal.medium data-reveal=reveal aria-labeledby=titleId aria-hidden=hidden role=role id=modalId data-options="root_element: 'body'"
    h2.text-center = title
    p
      = yield
      a.close-reveal-modal aria-label="Close" &#215;

and the wormhole moves the under-lying template fine, but I think it loses it's jQuery bindings.

Is there a way to hook in to the wormhole, and call:

$(document).foundation('reflow');?

Support tagless wormholes

I was trying to create a tagless wormhole for not adding anything to the DOM where the wormhole is placed, like this: {{#ember-wormhole tagName="" to="..."}. This failed badly, both the wormholed content as well as I think the sibling nodes of the wormhole got screwed up badly.

I can try to bring up a more precise description of what the effect exactly is if needed, but it seems this just does not work at all. Without having looked too deeply into the implementation of ember-wormhole, I wonder is this known, or is there a good reason why this does not / cannot work?

I kind of feel like the wormhole should by tagless by default, or at least support this, because when you do not want to have your wormholed content to sit in the DOM where it logically belongs to (which is why you use the wormhole in the first place, right?), then you also do not want an empty, "orphaned" div to hang around. With some "loose" CSS selectors this empty div could actually get some styling applied and thus become visible.

If this use case has been overlooked so far, I might try to bring up a PR when I find the time...

Apart from that, this addon has been so useful in so many cases! πŸ‘

Self-documenting Code Snippets

Simplify the code snippet config using the same patterns now used in ember-modal-dialog, where snippets are pulled from the source files themselves. This allows us to ditch the examples directory entirely, ensuring everything will be consistent.

ember-modal-dialog Examples

Can't find DOM in engine

I'm getting an error when using ember-wormhole inside an ember-engine:

Uncaught Error: ember-wormhole could not get DOM

Looks like the getDOM util doesn't find 'service:-document' and the container lookup of 'renderer:-dom' results in an 'InteractiveRenderer' object that doesn't have a '_dom' property so it throws an error.

I'm not sure if this issue can be solved on the ember-wormhole side or if we need ember-engines to provide a reference to the DOM, but figured I'd leave this here for now.

"wormholing" elements destroys focus, selection

If an element to be sent through an ember-wormhole currently has (or is the parent of an element that has) focus, the process of reparenting the element during appendRange destroys focus and shifts document.activeElement back to the <body>.

I'm running into this when using ember-cli-focus-input inside an ember-modal-dialog β€”Β the {{focus-input}} component's didInsertElement handler fires first, focuses & selects the input element, but if the dialog is also opening at the same time, the wormhole's didInsertElement fires last, reparenting the DOM nodes and wiping out the focus.

It might be reasonable to check document.activeElement at the beginning of appendToDestination and hang on the element if it's part of the wormhole's content so focus could be restored on the other side of appendRange.

I'm not sure how much extra work you'd need to do to preserve selection ranges as well; I mostly care about the selection inside the text input, which might be easier to handle than generic selection.

fastboot compatibility

Is there any plan for or interest in adding fastboot compatibility to ember-wormhole?

I've made a proof-of-concept here that uses a few private APIs to work around Fastboot's restrictions and make it work in Fastboot. If there's interest in adding this functionality to ember-wormhole there are probably a few safer/more-public APIs that can be used instead.

Another idea suggested by @mixonic:

  • alt idea is that helpers can return nodes, so add helper calls before and after the yield statement, have them push the node they return onto an array shared with the parent component)
  • parent component uses afterRender when that array is updated w/ the nodes, and uses them to walk instead of trying to find the first/last child nodes

HTML Events don't seem to work

Within a component you can create functions like keyPress which will run when the keypress event is invoked. but this doesn't seem to work on a wormhole component

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.