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

@blockquote-web-components/blockquote-mixin-slot-content

v1.5.0

Published

Webcomponent blockquote-mixin-slot-content following open-wc recommendations

Downloads

60

Readme

Lit

BlockquoteMixinSlotContent is a mixin for managing the flattened set of nodes assigned to a slot when the node(s) contained in some slot change.

Demo

Open in StackBlitz

Usage

BlockquoteMixinSlotContent implements the event handling pattern called event delegation.

It's necessary to set up the "catch-all" handler on this.shadowRoot node.

this.shadowRoot.addEventListener('slotchanges', this._onSlotChanges.bind(this));

Example:

class SlotElement extends BlockquoteMixinSlotContent(LitElement) {
  // ...
  connectedCallback() {
    super.connectedCallback && super.connectedCallback();
    this.shadowRoot.addEventListener('slotchanges', this._onSlotChanges.bind(this));
  }

  _onSlotChanges(ev) {
    const { detail } = ev;
    console.log(detail);
  }
  // ...
}

Caveats with whitespace:

It's important to understand some of the nuances between text nodes that contain text and text nodes that contain only whitespace.

<slot-element>
  nodeText1
  <p>Element 1</p>
  <p>Element 2</p>
</slot-element>

assignedNodes returns 5 Nodes

assignedNodes: Array(5)
0: text // textContent: "\n        nodeText1\n        "
1: p    // textContent: "Element 1"
2: text // textContent: "\n        "
3: p    // textContent: "Element 2"
4: text // textContent: "\n        "
length: 5

Also, another problem with whitespace is that when the content is just whitespace, assignedNodes are no longer able to return flattened nodes.

without whitespace

<slot-element>
  #shadow-root
  <slot>
    <img src="icon.svg" />
  </slot>
</slot-element>

<slot-element>Hello</slot-element>
document.querySelector('slot-element').textContent = '';

// assignedNodes [`img`]

with whitespace

<slot-element>
  #shadow-root
  <slot>
    <img src="icon.svg" />
  </slot>
</slot-element>

<slot-element>Hello</slot-element>
document.querySelector('slot-element').textContent = ' ';

// assignedNodes [`#text`]
// * missing `flattened` node

The detail property - keeping that in mind.

The mixin will return only nodes whose content is not whitespace and equally for flattened nodes.

<slot-element>
  #shadow-root
  <slot>
    <img src="icon.svg" />
  </slot>
</slot-element>

<slot-element>
  <p>sdfas</p>
  <p>2jfie</p>
</slot-element>

event.detail

{
  "assignedSlotContent": {
    "slotName": "",
    "assignedSlot": slot
  },
  "assignedNodesContent": {
    "assignedNodesByNode": [
      {
        "flatten": false,
        "assignedNodes": p,
        "assignedSlot": slot
      },
      {
        "flatten": false,
        "assignedNodes": p,
        "assignedSlot": slot
      }
    ],
    "assignedNodes": [p, p]
  },
  "flattenedNodesContent": {
    "assignedNodesByNode": [
      {
        "flatten": true,
        "assignedNodes": img,
        "assignedSlot": null
      }
    ],
    "assignedNodes": [img]
  },
  "originalEvent": {
    "event": {
      "isTrusted": true,
      "type": "slotchange",
      "target": null,
      "currentTarget": null,
      // ...
    },
    "assignedNodes": [text, p, text, p, text, text, text]
  }
}
<slot-element>
  #shadow-root
  <slot></slot>
</slot-element>

<slot-element> </slot-element>

event.detail

{
  "assignedSlotContent": {
    "slotName": "",
    "assignedSlot": null
  },
  "assignedNodesContent": {
    "assignedNodesByNode": [],
    "assignedNodes": []
  },
  "flattenedNodesContent": {
    "assignedNodesByNode": [],
    "assignedNodes": []
  },
  "originalEvent": {
    "event": {
      "isTrusted": true,
      "type": "slotchange",
      "target": null,
      "currentTarget": null,
      // ...
    },
    "assignedNodes": [text]
  }
}

src/BlockquoteMixinSlotContent.js:

mixin: BlockquoteMixinSlotContent

Mixins

| Name | Module | Package | | ------------- | ------ | --------------------- | | dedupeMixin | | @open-wc/dedupe-mixin |

Parameters

| Name | Type | Default | Description | | ------ | ---- | ------- | ----------- | | Base | | | |

Methods

| Name | Privacy | Description | Parameters | Return | Inherited From | | --------------- | ------- | ----------- | ----------- | ------ | -------------- | | _onSlotChange | | | ev: Event | | |

Exports

| Kind | Name | Declaration | Module | Package | | ---- | ---------------------------- | -------------------------- | --------------------------------- | ------- | | js | BlockquoteMixinSlotContent | BlockquoteMixinSlotContent | src/BlockquoteMixinSlotContent.js | |

src/index.js:

Exports

| Kind | Name | Declaration | Module | Package | | ---- | ---------------------------- | -------------------------- | ------------------------------- | ------- | | js | BlockquoteMixinSlotContent | BlockquoteMixinSlotContent | ./BlockquoteMixinSlotContent.js | |