# The Grid Ed: Overlay widgets

**URL:** <https://discuss.prosemirror.net/t/the-grid-ed-overlay-widgets/150>\
**Category:** Show\
**Created:** [January 27, 2016, 12:17pm UTC](https://discuss.prosemirror.net/t/the-grid-ed-overlay-widgets/150 "2016-01-27T12:17:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![forresto](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/forresto/32/108_2.png) [@forresto](https://discuss.prosemirror.net/u/forresto)\
**Post date:** [January 27, 2016, 12:17pm UTC](https://discuss.prosemirror.net/t/the-grid-ed-overlay-widgets/150/1 "2016-01-27T12:17:10Z")

</div>

Moved this to not hijack the proseMirror-widget project thread.

We’re working on a related challenge from a different angle: widgets overlaid with PM editable content, outside of the editable flow.

Demo, with a CodeMirror widget in an iframe overlay: [http://the-grid.github.io/ed/](http://the-grid.github.io/ed/)

There is only one extension to the schema: divs that act as placeholders for the overlays to stay in sync with. There is a little trickiness to keep the positions synchronized, but it seems to work.

TODO: making cut and paste work, making arrow ↑ ↓ caret navigation work as expected.

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [February 9, 2016, 8:55pm UTC](https://discuss.prosemirror.net/t/the-grid-ed-overlay-widgets/150/2 "2016-02-09T20:55:46Z")

</div>

This is interesting. I only saw it just now due to overeager spam filtering by my mail client. The widgets appear to be inline in the editor’s DOM. Can you go into a little more detail on how they are implemented?

---

<div class="post-metadata">

**Author:** ![forresto](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/forresto/32/108_2.png) [@forresto](https://discuss.prosemirror.net/u/forresto)\
**Post date:** [February 11, 2016, 3:24am UTC](https://discuss.prosemirror.net/t/the-grid-ed-overlay-widgets/150/3 "2016-02-11T03:24:12Z")

</div>

It is a bit hacky, but working surprisingly well (I’ve been trying this in a few permutations over the past year).

1. Ed parses a Grid API post array into a PM Doc. HTML type blocks belong to PM, all others PM just renders as DIVs to make room in the contenteditable flow.
2. Ed listens for PM’s `draw` signal, and looks for and measures the placeholder DIVs.
3. Ed mounts the widgets and positions them with placeholders. Some types are iframes (like CodeMirror), others are React components.
4. When a widget’s inner height changes, it tells PM to update the placeholder `height` attribute. (GOTO 2)

---

<div class="post-metadata">

**Author:** ![forresto](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/forresto/32/108_2.png) [@forresto](https://discuss.prosemirror.net/u/forresto)\
**Post date:** [February 19, 2016, 1:13am UTC](https://discuss.prosemirror.net/t/the-grid-ed-overlay-widgets/150/4 "2016-02-19T01:13:58Z")

</div>

@marijn Maybe all of this overlay hackery wouldn’t be needed if PM had examples with contenteditable=false divs in the flow. Is anything like that in the works?

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [February 19, 2016, 8:51am UTC](https://discuss.prosemirror.net/t/the-grid-ed-overlay-widgets/150/5 "2016-02-19T08:51:49Z")

</div>

Is there anything about this that is causing you confusion? Nodes without content are automatically set to `contenteditable=false` when rendered. So it seems like the right thing just happens, as seen in the most basic form in the horizontal\_rule node, but you can create a node like that that renders its content in a more complicated way. (Just be aware that ProseMirror might occasionally decide to redraw the node when its surroundings change.)

---

<div class="post-metadata">

**Author:** ![forresto](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/forresto/32/108_2.png) [@forresto](https://discuss.prosemirror.net/u/forresto)\
**Post date:** [February 20, 2016, 2:20pm UTC](https://discuss.prosemirror.net/t/the-grid-ed-overlay-widgets/150/6 "2016-02-20T14:20:57Z")

</div>

Is there a canonical way to listen for these nodes getting redrawn, if their content is cleared at that point? (Or just listen for `draw` then loop through DOM?)

---

<div class="post-metadata">

**Author:** ![marijn](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/marijn/32/15_2.png) [@marijn](https://discuss.prosemirror.net/u/marijn)\
**Post date:** [February 22, 2016, 10:16am UTC](https://discuss.prosemirror.net/t/the-grid-ed-overlay-widgets/150/7 "2016-02-22T10:16:04Z")

</div>

Listening to `"draw"` sounds like it’d work with little extra complexity.

---

<div class="post-metadata">

**Author:** ![forresto](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/forresto/32/108_2.png) [@forresto](https://discuss.prosemirror.net/u/forresto)\
**Post date:** [January 26, 2017, 8:05pm UTC](https://discuss.prosemirror.net/t/the-grid-ed-overlay-widgets/150/8 "2017-01-26T20:05:30Z")

</div>

To update this show & tell, the Grid’s Ed v2 has hit master, updated for PM 0.17.x. Widgets are no longer overlaid & synced. Now there is an inline representation that is rendered as a NodeView and and editor representation that is rendered as a modal.

- Changes: [https://github.com/the-grid/ed/blob/master/CHANGES.md#201---2017-01-26](https://github.com/the-grid/ed/blob/master/CHANGES.md#201---2017-01-26)
- Demo: [https://the-grid.github.io/ed/#fixture](https://the-grid.github.io/ed/#fixture)

---

<div class="post-metadata">

**Author:** ![astevenson](https://discuss.prosemirror.net/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@astevenson](https://discuss.prosemirror.net/u/astevenson)\
**Post date:** [January 27, 2017, 4:23pm UTC](https://discuss.prosemirror.net/t/the-grid-ed-overlay-widgets/150/9 "2017-01-27T16:23:29Z")

</div>

That is looking really nice. The drag and drop improvements make a big difference.
