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

no wrapper span #1416

Merged
merged 26 commits into from
Jun 5, 2024
Merged

no wrapper span #1416

merged 26 commits into from
Jun 5, 2024

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Jun 1, 2024

Rather than producing an inline span,

<span id="cell-6212702c"></span>

inline expressions now produce a special comment:

<!--:6212702c:-->

This comment does not serve as a container for any rendered content but rather serves as a marker: rendered content (calls to display) are inserted before the comment. The rendered contents are tracked in the _nodes array and removed as needed (rather than clearing the container via innerHTML).

This eliminates the need for a wrapper span for inline expressions, which means things like this now work:

<div class="grid grid-cols-4">
  ${d3.range(10).map((i) => html`<div class="card">${i}</div>`)}
</div>

This also fixes rendering inline expressions into SVG and some edge cases with incremental update during preview.

Fixes #11.
Fixes #1414.
Fixes #1415.

Adding in #1425:
Fixes #375.
Fixes #396.
Fixes #597.
Fixes #636.

@mbostock mbostock requested a review from Fil June 1, 2024 00:17
@mbostock
Copy link
Member Author

mbostock commented Jun 1, 2024

I don’t have a great way of automating tests for this functionality, but here are some of the new things you can do:

<div class="flexy">
  ${d3.range(10).map((i) => html`<div>${i}</div>`)}
</div>

<style type="text/css">

.flexy {
  display: flex;
}

.flexy > * {
  flex-grow: 1;
}

</style>
<table>
  <thead>
    <tr>
      <td>i</td>
      <td>one</td>
      <td>two</td>
    </tr>
  </thead>
  <tbody>
    ${d3.range(10).map((i) => html`<tr>
      <td>${i}</td>
      <td>one</td>
      <td>two</td>
    </tr>`)}
  </tbody>
</table>
<h2>hello</h2> editme
<svg width=640 height=120 fill=red>
  <text x=20 y=20>${now}</text>
</svg>
<svg width=640 height=120>
  ${d3.range(10).map((i) => svg`<text x=${20 + i * 10} y=20 fill=${d3.interpolateTurbo(i / 10)}>${i}</text>`)}
</svg>

@Fil
Copy link
Contributor

Fil commented Jun 1, 2024

(erroneous comment deleted)

Nice! I wonder if this could help fix #375: now a comment with inline code <!-- ${1 + 2} --> shows -->, which is (slightly) worse than before.

@mbostock
Copy link
Member Author

mbostock commented Jun 3, 2024

Fixing that requires fundamental changes to our parser as described in #597. I don’t think we should tie these two things together. Interpolating within comments is broken and will remain broken in this PR.

Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK that was my only comment :)

@mbostock mbostock enabled auto-merge (squash) June 5, 2024 15:41
@mbostock mbostock merged commit e6af534 into main Jun 5, 2024
4 checks passed
@mbostock mbostock deleted the mbostock/no-wrapper-span branch June 5, 2024 15:43
mbostock added a commit that referenced this pull request Jun 6, 2024
@mbostock mbostock mentioned this pull request Jun 6, 2024
mbostock added a commit that referenced this pull request Jun 6, 2024
* Revert "no wrapper span (#1416)"

This reverts commit e6af534.

* Revert "clear old content on undefine (#1431)"

This reverts commit 7a25fc4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment