Work with tables and expose state variables as model.

The table support is achieved by searching for a suitable viewport element.
Currently, this just means skipping table elements and anything where the
content is not a single element.

Also fixed a few edge-case problems where the number of active rows
was not calculated properly. Lots of test cases in the demo now.