Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow exporting without a script #9

Closed
phistuck opened this issue Jan 17, 2019 · 7 comments
Closed

Allow exporting without a script #9

phistuck opened this issue Jan 17, 2019 · 7 comments
Assignees

Comments

@phistuck
Copy link

phistuck commented Jan 17, 2019

Define a new HTML content attribute, export or exportname or namedexport (and defaultexport?) or something similar that allows elements to be exported without any inline scripts.

<!-- module.html -->
<div namedexport="content">
Warning - this might hurt.
</div>
// main.js
import {content} from "module.html";
document.body.appendChild(content);

I imagine some HTML modules might have no scripting logic, they would only exist to share content and inline scripts are too wordy for those cases.

That could maybe make them available from HTML directly as well...

<!-- Bonus -->
<!-- page.html -->
<content import="module.html" namedimport="content"></content>

A little bit like server-side includes. But this is crazy talk.

@travisleithead
Copy link
Contributor

travisleithead commented Jan 17, 2019

We've definitely had discussions about this possibility, since it seems very natural to enable import/export declaratively. One thing we are losing with HTML Modules, which was available via HTML Imports is the declarative import via link[rel=import]. It's not a huge loss, since static module imports can be readily identified in top-level script texts almost as easily. Our approach was "wait and see", as declarative support can be added later with no backward compatibility issues.

Do you have thoughts on how import/export might work with template? If you think about template as able to import an external html module, I think things start to get interesting...

@kenchris
Copy link
Contributor

kenchris commented Jan 22, 2019

Instead of using

<content import="module.html" namedimport="content"></content>

we probably want something similar to named slots

<p><slot importname="my-text">My default text</slot></p>

@kenchris
Copy link
Contributor

@travisleithead maybe something like:

<template import="summary-data.html">
  <details>
    <summary>
      <code class="name">&lt;<slot name="element-name">NEED NAME</slot>&gt;</code>
      <i class="desc"><slot name="description">NEED DESCRIPTION</slot></i>
    </summary>
    <div class="attributes">
      <h4>Attributes</h4>
      <slot name="attributes"><p>None</p></slot>
    </div>
  </details>
  <hr>
</template>

@Jamesernator
Copy link

This would be nice if it works without scripting enabled too as we could have a nice fallback that is downloaded only if scripting isn't enabled rather than shipping it to everyone:

<noscript>
  <content import="no-script-fallback.html"></content>
</noscript>

@matthewp
Copy link

matthewp commented Mar 6, 2019

This is definitely an interesting issue. However there's also some overlap I feel with the declarative custom elements strawman. Given that, it might be advantageous to defer this until after HTML modules have landed. Otherwise I feel there is risk that the whole thing becomes blocked. From what I can tell I don't feel this proposal would be affected by any of the choices already made in HTML modules (meaning it could be added later).

@domenic
Copy link

domenic commented Mar 6, 2019

I tend to agree this seems additive, and it's worth getting the foundations down first.

@travisleithead
Copy link
Contributor

Closing this issue and opening a linking issue in the webcomponents repo. (WICG/webcomponents#863)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants