npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aurelia-portal-attribute

v1.4.0

Published

A plugin to customize rendering process in Aurelia application.

Downloads

818

Readme

aurelia-portal-attribute

Join the chat at https://gitter.im/aurelia/discuss CircleCI

[Introduction]

This article covers the portal attribute plugin for Aurelia. This plugin is created for managing rendering flow of part of custom element in an Aurelia application. The plugin supports the use of dynamic elements matching as render target, via either element references or CSS selectors. Online Demo

[Installing The Plugin]

  1. In your JSPM-based project install the plugin via jspm with following command
jspm install aurelia-portal-attribute

If you use Webpack, install the plugin with the following command

npm install aurelia-portal-attribute --save

If you use the Aurelia CLI, install the plugin with the following command

au install aurelia-portal-attribute

alternatively you can manually add these dependencies to your vendor bundle:

  ...
  "dependencies": [
    {
      "name": "aurelia-portal-attribute",
      "path": "../node_modules/aurelia-portal-attribute/dist/amd",
      "main": "aurelia-portal-attribute"
    }
  ]
  1. Make sure you use manual bootstrapping. In order to do so open your index.html and locate the element with the attribute aurelia-app. Change it to look like this:
  <body aurelia-app="main">...</body>
  1. In main.js in your src:
  export function configure(aurelia) {
    aurelia.use
     .standardConfiguration()
     .plugin(PLATFORM.moduleName('aurelia-portal-attribute'))

    aurelia.start().then(a => a.setRoot());
  }

[Using The Plugin]

There are a few scenarios you can take advantage of the attribute.

  1. There is part of the element that needs to be rendered into document body. This is a common case, as the component may be nested under a overflow: hidden ancestor and it won't be able to display properly. Consider the following dom structure of a custom <combobox /> element:
  <template class="combobox">
    <div class="input-ct">
      <input ref="input" value.bind="filterText" />
    <div>
    <ul class="list-group items-list">
      <li repeat.for="item of items | filter: filterText" class="list-group-item">${item.name}</li>
    </ul>
  </template>

This structure often works fine when we have ul.list-group.item-list CSS: position: absolute; top: 100%; But it will not work when the custom element is nested inside an element with overflow: hidden, or inside an element with scroll, like following example:

  <!-- app.html -->
  <div style="height: 200px; overflow: auto;">
    <!-- oopps, my list got clipped -->
    <combobox></combobox>
  </div>

A simple solution is to use CSS: position: fixed on the list and calculat its position, or the portal attribute like the following example:

  <template class="combobox">
    <div class="input-ct">
      <input ref="input" value.bind="filterText" />
    <div>
    <ul portal class="list-group items-list">
      <li repeat.for="item of items | filter: filterText" class="list-group-item">${item.name}</li>
    </ul>
  </template>

portal attribute may seem to be an overkill, but beside styling, it also helps you separate DOM path of different parts in your custom element, whist still binds them to the same underlying view model, which should helps better DOM manangement, including event model in some cases. Following is an example of final rendered DOM tree for <combobox/> above:

  <body>
    <app>
      <combobox>
        <!-- combobox internal elements -->
      </combobox>
    </app>
    <!-- combobox item list in the body -->
    <ul class="list-group items-list">
      <li class="list-group-item">item 1</li>
      <li class="list-group-item">item 2</li>
      <li class="list-group-item">item 3</li>
      ...
      <!-- more items -->
    </ul>
  </body>

APIs

| Name | Types | Default | Description | | - | - | - | - | | target | string/Element | undefined | Target of the portal, by default will be resolved to document body, if target cannot be found. If a string is supplied, it will be used to determine the real target with a call document.querySelector() | | position | beforebegin or afterbegin or beforeend or afterend | beforeend | Describing the position relative to the target of a portal to move the content to |

Examples

Portalling an element to document body

<div class="my-menu" portal>
or
<div class="my-menu" portal="body">

Portalling multiple elements to the end of document body

<template portal>
  <p>paragraph 1</p>
  <p>paragraph 2</p>
</template>

Building The Code

To build the code, follow these steps.

  1. Ensure that NodeJS is installed. This provides the platform on which the build tooling runs.
  2. From the project folder, execute the following command:
npm install
  1. To build the code, you can now run:
npm run build
  1. You will find the compiled code in the dist folder, available in three module formats: AMD, CommonJS and ES6.

Running The Tests

npm test

Acknowledgement

Thanks goes to Dwayne Charrington for his Aurelia-TypeScript starter package https://github.com/Vheissu/aurelia-typescript-plugin