 ;; Representations
 ;;*********************************************************
 
+(defdom table-map-ui [table]
+  [:table {:className "table"
+           :onContextMenu (ref-menu table)}
+   [:thead
+    [:tr
+     (each [k (@table "headers")]
+           [:th (item-ui (conj table ["headers" index]))])]
+    [:tbody
+     (each [row (@table "rows")]
+           [:tr
+            (let [path ["rows" index]]
+              (each [v row]
+                    [:td (item-ui (conj table (conj path index)))]))])]]])
+
 (defdom table-ui [table]
-  (let [ks (keys @table)]
-    [:table {:className "table"
-             :onContextMenu (ref-menu table)}
-     [:thead
-      [:tr
-       (each [k ks]
-             [:th (item-ui (conj table [{::key k}]))])]
-      [:tbody
-       [:tr
-        (each [v (vals @table)]
-              [:td (item-ui (conj table (nth ks index)))])]]]]))
+  [:table {:className "table"
+           :onContextMenu (ref-menu table)}
+   [:thead
+    [:tr
+     (each [k (table/headers @table)]
+           [:th k])]
+    [:tbody
+     (each [row (table/-rows @table)]
+           [:tr
+            (let [path ["rows" index]]
+              (each [v row]
+                    [:td (row index)]))])]]])
 
 
 (defdom list-ui [list]

;;*********************************************************

(def run-stack (atom nil))
(def cur-state (atom {"counter" 0}))
(def prev nil)

(defn run-index [index notebook page state]

(defn datatype-name [x]
  (cond
   (#{:ref/id :ref/js} (:type x)) "ref"
   (satisfies? table/ITable x) "table"
   (or (true? x) (false? x)) "boolean"
   (keyword? x) "keyword"
   (number? x) "number"
