Browse Source

removed old (reagent-only) frontend

Brandon Wong 3 years ago
parent
commit
cb1ea1101a

+ 0 - 20
old-frontend/.gitignore

@@ -1,20 +0,0 @@
-/target
-/classes
-/checkouts
-profiles.clj
-pom.xml
-pom.xml.asc
-*.jar
-*.class
-/.lein-*
-/.nrepl-port
-/resources/public/js
-/public/js
-/out
-/.repl
-*.log
-/.env
-.rebel_readline_history
-node_modules
-dist/
-*.swp

+ 0 - 22
old-frontend/LICENSE

@@ -1,22 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2014 reagent-project
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-

+ 0 - 22
old-frontend/README.md

@@ -1,22 +0,0 @@
-
-### Development mode
-To start the Figwheel compiler, navigate to the project folder and run the following command in the terminal:
-
-```
-lein figwheel
-```
-
-Figwheel will automatically push cljs changes to the browser.
-Once Figwheel starts up, you should be able to open the `public/index.html` page in the browser.
-
-### REPL
-
-The project is setup to start nREPL on port `7002` once Figwheel starts.
-Once you connect to the nREPL, run `(cljs)` to switch to the ClojureScript REPL.
-
-### Building for production
-
-```
-lein clean
-lein package
-```

+ 0 - 11
old-frontend/env/dev/clj/user.clj

@@ -1,11 +0,0 @@
-(ns user
- (:require [figwheel-sidecar.repl-api :as ra]))
-
-(defn start-fw []
- (ra/start-figwheel!))
-
-(defn stop-fw []
- (ra/stop-figwheel!))
-
-(defn cljs []
- (ra/cljs-repl))

+ 0 - 15
old-frontend/env/dev/cljs/microtables_frontend/dev.cljs

@@ -1,15 +0,0 @@
-(ns ^:figwheel-no-load microtables-frontend.dev
-  (:require
-    [microtables-frontend.core :as core]
-    [devtools.core :as devtools]))
-
-(extend-protocol IPrintWithWriter
-  js/Symbol
-  (-pr-writer [sym writer _]
-    (-write writer (str "\"" (.toString sym) "\""))))
-
-(enable-console-print!)
-
-(devtools/install!)
-
-(core/init!)

+ 0 - 8
old-frontend/env/prod/cljs/microtables_frontend/prod.cljs

@@ -1,8 +0,0 @@
-(ns microtables-frontend.prod
-  (:require
-    [microtables-frontend.core :as core]))
-
-;;ignore println statements in prod
-(set! *print-fn* (fn [& _]))
-
-(core/init!)

+ 0 - 18
old-frontend/package.json

@@ -1,18 +0,0 @@
-{
-  "name": "microtables-frontend",
-  "author": "Brandon Wong <projects@brwong.net> (https://www.brwong.net)",
-  "description": "Frontend of the Microtables project",
-  "version": "1.0.0",
-  "main": "index.js",
-  "dependencies": {
-    "mathjs": "6.2.3",
-    "webpack": "4.41.2",
-    "webpack-cli": "3.3.9"
-  },
-  "devDependencies": {},
-  "scripts": {
-    "test": "echo \"Error: no test specified\" && exit 1"
-  },
-  "keywords": [],
-  "license": "ISC"
-}

+ 0 - 59
old-frontend/project.clj

@@ -1,59 +0,0 @@
-(defproject microtables-frontend "0.1.0-SNAPSHOT"
-  :description "FIXME: write description"
-  :url "http://example.com/FIXME"
-  :license {:name "Eclipse Public License"
-            :url "http://www.eclipse.org/legal/epl-v10.html"}
-
-  :dependencies [[org.clojure/clojure "1.10.1"]
-                 [org.clojure/clojurescript "1.10.520"]
-                 [reagent "0.8.1"]]
-
-  :plugins [[lein-cljsbuild "1.1.7"]
-            [lein-figwheel "0.5.19"]]
-
-  :clean-targets ^{:protect false}
-
-  [:target-path
-   [:cljsbuild :builds :app :compiler :output-dir]
-   [:cljsbuild :builds :app :compiler :output-to]]
-
-  :resource-paths ["public"]
-
-
-  :figwheel {:http-server-root "."
-             :nrepl-port 7002
-             :nrepl-middleware [cider.piggieback/wrap-cljs-repl]
-             :css-dirs ["public/css"]}
-
-  :cljsbuild {:builds {:app
-                       {:source-paths ["src" "env/dev/cljs"]
-                        :compiler
-                        {:main "microtables-frontend.dev"
-                         :output-to "public/js/app.js"
-                         :output-dir "public/js/out"
-                         :asset-path   "js/out"
-                         :source-map true
-                         :npm-deps false
-                         :optimizations :none
-                         :pretty-print  true
-                         :foreign-libs [{:file "dist/index.bundle.js"
-                                         :provides ["mathjs"]
-                                         :global-exports {mathjs mathjs}}]}
-                        :figwheel
-                        {:on-jsload "microtables-frontend.core/mount-root"}}
-                       :release
-                       {:source-paths ["src" "env/prod/cljs"]
-                        :compiler
-                        {:output-to "public/js/app.js"
-                         :output-dir "public/js/release"
-                         :optimizations :advanced
-                         :infer-externs true
-                         :pretty-print false}}}}
-
-  :aliases {"package" ["do" "clean" ["cljsbuild" "once" "release"]]}
-
-  :profiles {:dev {:source-paths ["src" "env/dev/clj"]
-                   :dependencies [[binaryage/devtools "0.9.10"]
-                                  [figwheel-sidecar "0.5.19"]
-                                  [nrepl "0.6.0"]
-                                  [cider/piggieback "0.4.1"]]}})

+ 0 - 121
old-frontend/public/css/site.css

@@ -1,121 +0,0 @@
-body {
-  font-family: 'Helvetica Neue', Verdana, Helvetica, Arial, sans-serif;
-  max-width: 600px;
-  margin: 0 auto;
-  padding-top: 72px;
-  -webkit-font-smoothing: antialiased;
-  font-size: 1.125em;
-  color: #333;
-  line-height: 1.5em;
-}
-
-h1, h2, h3 {
-  color: #000;
-}
-h1 {
-  font-size: 2.5em
-}
-
-h2 {
-  font-size: 2em
-}
-
-h3 {
-  font-size: 1.5em
-}
-
-a {
-  text-decoration: none;
-  color: #09f;
-}
-
-a:hover {
-  text-decoration: underline;
-}
-
-table {
-    border-collapse: collapse;
-}
-
-td, th {
-    border: 1px solid black;
-    padding: 0;
-}
-th {
-    text-align: center;
-    min-width: 40px;
-}
-td {
-    text-align: right;
-    position: relative;
-}
-
-td input {
-    border: none;
-    padding: 5px;
-    width: 80px;
-}
-td input:hover {
-    background-color: #ccc;
-}
-td input:focus {
-    background-color: #ccf;
-}
-td input:not(:focus) {
-    text-align: right;
-}
-
-
-.smartborder {
-    width: calc(100% + 2px);
-    height: calc(100% + 2px);
-    border: 3px solid blue;
-    position: absolute;
-    left: -4px;
-    top: -4px;
-    background: none;
-    z-index: 999;
-    /*pointer-events: none;*/
-}
-
-td input:not(:focus) + .smartborder {
-    visibility: hidden;
-}
-
-
-.smartborder .button {
-    --button-size: 20px;
-    --half-button-size: 10px;
-    /*pointer-events: all;/* TODO check this (what is "initial"?) */
-    width: var(--button-size);
-    height: var(--button-size);
-    background-color: blue;
-    color: white;
-    border-radius: var(--half-button-size);
-    position: absolute;
-}
-.extendrange.button {
-    left: 100%;
-    top: 100%;
-}
-.fillrange.button {
-    top: 100%;
-    left: calc(50% - var(--half-button-size));
-}
-.moverange.button {
-    top: calc(50% - var(--half-button-size));
-    left: calc(0px - var(--button-size));
-}
-.emptyrange.button {
-    top: calc(0px - var(--button-size));
-    left: calc(100% - var(--button-size) - 5px);
-}
-.deleterange.button {
-    top: calc(0px - var(--button-size));
-    left: 100%;
-}
-.copyrange.button {
-    top: calc(0px - var(--button-size));
-    left: 0;
-}
-

+ 0 - 17
old-frontend/public/index.html

@@ -1,17 +0,0 @@
-
-<!DOCTYPE html>
-<html>
-  <head>
-    <meta charset="utf-8">
-    <meta content="width=device-width, initial-scale=1" name="viewport">
-    <link href="/css/site.css" rel="stylesheet" type="text/css">
-  </head>
-  <body>
-    <div id="app">
-      <h3>ClojureScript has not been compiled!</h3>
-      <p>please run <b>lein figwheel</b> in order to start the compiler</p>
-    </div>
-    <script src="/js/app.js" type="text/javascript"></script>
-    
-  </body>
-</html>

+ 0 - 41
old-frontend/src/js/index.js

@@ -1,41 +0,0 @@
-
-// to include an npm module/package into clojurescript:
-// https://figwheel.org/docs/npm.html
-
-// to reduce the bundle size:
-// https://mathjs.org/docs/custom_bundling.html
-
-import { parse, evaluate } from 'mathjs';
-
-function getVariables(expression) {
-    if( !expression || typeof expression !== 'string' ) {
-        console.log('not correct input', expression, typeof expression);
-        return [];
-    }
-    try {
-        const expressionObject = parse(expression);
-        console.log('now returning', expressionObject);
-        return expressionObject
-            .filter(x => x.isSymbolNode)
-            .map(x => x.name)
-            .map(x => x.toUpperCase())
-            .filter(x => /^[A-Z]+[0-9]+$/.test(x));
-    }
-    catch(e) {
-        console.error('error in parsing or filtering for variables', e.message || e);
-        return [];
-    }
-}
-
-function customEval(...args) {
-    try {
-        return evaluate(...args);
-    }
-    catch(e) {
-        console.error('error in evaluating expression', e.message || e);
-        return {error: e.message};
-    }
-}
-
-window.mathjs = {parse, evaluate: customEval, getVariables};
-

+ 0 - 225
old-frontend/src/microtables_frontend/core.cljs

@@ -1,225 +0,0 @@
-(ns microtables-frontend.core
-    (:require
-      [reagent.core :as r]
-      ["mathjs" :as mathjs]))
-
-; to generate random values
-;for(let i = 0, s = new Set(); i < 10; i++){ let r = Math.floor(Math.random() * 15)+1, c = a[Math.floor(Math.random() * a.length)], k = `${c}${r}`; if(s.has(k)){ i--; continue; } s.add(k); v.push(`{:row ${r} :col "${c}" :value "${Math.floor(Math.random() * 10000)}"}`); }
-(def sample-data [{:row 1 :col "A" :value "59" :view :display}
-                  {:row 5 :col "C" :value "269" :view :display}
-                  {:row 4 :col "B" :value "7893" :view :display}
-                  {:row 2 :col "F" :value "8650" :view :display}
-                  {:row 6 :col "D" :value "4065" :view :display}
-                  {:row 7 :col "F" :value "5316" :view :display}
-                  {:row 12 :col "A" :value "2405" :view :display}
-                  {:row 5 :col "B" :value "7863" :view :display}
-                  {:row 9 :col "E" :value "3144" :view :display}
-                  {:row 10 :col "D" :value "8272" :view :display}
-                  {:row 11 :col "D" :value "2495" :view :display}
-                  {:row 15 :col "E" :value "8968" :view :display}
-                  {:row 7 :col "B" :value "=C5 + D6" :view :display}
-                  {:row 8 :col "B" :value "=B7 * 2" :view :display}
-                  {:row 7 :col "C" :value "=D1" :view :display}
-                  {:row 12 :col "B" :value "=C12" :view :display}])
-
-(defonce data-atom (r/atom sample-data))
-
-(defn highest [dir data] (apply max (map dir data)))
-
-; COLUMN NAMES
-(defn increment-letter-code [s]
-  (let [l (last s)]
-    (cond
-      (empty? s) [65]
-      (= l 90) (conj (increment-letter-code (subvec s 0 (dec (count s)))) 65)
-      :else (conj (subvec s 0 (dec (count s))) (inc l)))))
-(defn next-letter [lc]
-  (apply str (map char (increment-letter-code (mapv #(.charCodeAt % 0) lc)))))
-(def col-letters (iterate next-letter "A"))
-
-
-; CHANGE VALUE FUNCTIONS
-(defn update-value [c r existing-datum value]
-  (if (nil? existing-datum)
-    (swap! data-atom conj {:row r :col c :value value :dirty true})
-    (swap! data-atom (partial map #(if (and (= r (:row %)) (= c (:col %))) (assoc (assoc % :dirty true) :value value) %)))))
-
-;TODO: consider changing this for a single "view" atom which points to zero or one cells, which will determine whether to show the formula or evaluation
-(defn toggle-display [data c r view-mode]
-  (println (str "  toggling " c r " to " view-mode))
-  (map #(if (and (= r (:row %)) (= c (:col %))) (assoc % :view view-mode) %) data))
-
-; CALCULATION / FORMULA EVALUATION FUNCTIONS
-
-(def parse-variables (memoize (fn [expression]
-                                (js->clj (.getVariables mathjs expression)))))
-(def evaluate-expression (memoize (fn [expression variables]
-                                    (let [answer (.evaluate mathjs expression (clj->js variables))]
-                                      (if (nil? (.-error answer))
-                                        answer
-                                        :calc-error)))))
-
-(def str->rc (memoize (fn [s]
-                        (let [c (re-find #"^[A-Z]+" s)
-                              r (.parseInt js/window (re-find #"[0-9]+$" s))]
-                          {:row r :col c}))))
-
-;TODO: deal with lowercase cell references
-(defn find-cell [data c r]
-  (some #(if (and (= (:col %) c) (= (:row %) r)) %) data))
-(defn find-ref [data cell-ref]
-  (some (fn [{:keys [row col] :as datum}] (if (and (= row (:row cell-ref)) (= col (:col cell-ref))) datum)) data))
-(defn copy-display-values [data display-values]
-  (let [original (map #(dissoc % :dirty) data)
-        removed (map #(-> % (dissoc :found) (dissoc :inputs) (dissoc :dirty)) display-values)]
-    (into original removed)))
-
-;TODO: memoize dynamically? probably not worth memoizing directly, and could take up too much memory over time
-;      https://stackoverflow.com/a/13123571/8172807
-(defn find-cycle
-  ([data datum] (find-cycle data datum #{}))
-  ([data datum ances]
-   (let [cur {:row (:row datum) :col (:col datum)}
-         this-and-above (conj ances cur)
-         refs (:refs datum)
-         found (not (empty? (clojure.set/intersection this-and-above (set refs))))]
-     (if found
-       :cycle-error
-       (some (fn [cell]
-               (find-cycle data (find-ref data cell) this-and-above)) refs)))))
-
-(defn find-val [data c r]
-  (let [l (find-cell data c r)
-        v (get l :display (get l :value))
-        formula? (and (string? v) (= (first v) "="))]
-    (cond
-      (nil? v) 0
-      ;(contains? l :error) :ref-error
-      formula? :not-yet
-      :else v)))
-
-
-
-;TODO: figure out how to re-evaluate only when the cell modified affects other cells
-(defn re-evaluate [data]
-  (let [{has-formula true original-values false} (group-by #(= (first (:value %)) "=") data)
-        found-cycles (map #(let [found (find-cycle data %)] (if found (assoc % :error found) %)) has-formula)
-        {eligible true ineligible false} (group-by #(not (contains? %  :error)) found-cycles)]
-    (loop [values (into original-values ineligible) mapped-cell-keys eligible]
-      (let [search-values (map (fn [datum] (assoc datum :found (map #(find-val (concat values mapped-cell-keys) (:col %) (:row %)) (:refs datum)))) mapped-cell-keys)
-            {not-ready true ready nil} (group-by (fn [datum] (some #(= :not-yet %) (:found datum))) search-values)
-            prepped-for-eval (map (fn [datum] (assoc datum :inputs (apply hash-map (interleave (:vars datum) (:found datum))))) ready)
-            evaluated (map (fn [datum] (assoc datum :display (evaluate-expression (subs (:value datum) 1) (:inputs datum)))) prepped-for-eval)
-            updated-values (copy-display-values values evaluated)]
-        (println "EVALUATED" evaluated)
-        (if (nil? not-ready)
-          updated-values
-          (recur updated-values not-ready))))))
-
-(defn add-parsed-variables [datum]
-  (if (= (first (:value datum)) "=")
-    (let [vars (parse-variables (subs (:value datum) 1))
-          refs (map str->rc vars)]
-      (-> datum (assoc :vars vars) (assoc :refs refs) (dissoc :error)))
-    (-> datum (dissoc :vars) (dissoc :refs) (dissoc :display) (dissoc :error))))
-
-(defn add-parsed-variables-to-specific-datum
-  "Parse variables from the value of a datum and add in :vars and :refs (for swap! data-atom).
-  If the value does not contain a fomula, remove any :vars and :refs that may have been there."
-  [c r data] (map #(if (and (= (:col %) c) (= (:row %) r))
-                     (add-parsed-variables %)
-                     %) data))
-
-(defn on-enter-cell [c r e]
-  (println (str "entering cell " c r))
-  (swap! data-atom #(toggle-display % c r :value)))
-(defn on-change [c r datum e]
-  (update-value c r datum (.. e -target -value)))
-(defn on-leave-cell [c r e]
-  (println (str "leaving cell " c r))
-  (swap! data-atom #(as-> % data
-                      (toggle-display data c r :display)
-                      (add-parsed-variables-to-specific-datum c r data)
-                      (re-evaluate data))))
-(defn on-keyPress [c r e]
-  (println "key press" c r (.. e -which) (.keys js/Object e))
-  (if (= 13 (.. e -which)) (.focus (.getElementById js/document (str c (inc r))))))
-  ;TODO TODO TODO TODO TODO TODO TODO TODO TODO
-  
-
-
-;; -------------------------
-;; Views
-
-(defn smart-border [c r]
-  [:div {:class "smartborder"}
-   [:div {:class "extendrange button"
-          :title "extend range"
-          :on-click #(println "extend range")}]
-   [:div {:class "fillrange button"
-          :title "fill range"
-          :on-click #(println "fill range")}]
-   [:div {:class "moverange button"
-          :title "move range"
-          :on-click #(println "move range")}]
-   [:div {:class "emptyrange button"
-          :title "empty range"
-          :on-click #(println "empty range")}]
-   [:div {:class "deleterange button"
-          :title "delete range"
-          :on-click #(println "delete range")}]
-   [:div {:class "copyrange button"
-          :title "copy range"
-          :on-click #(println "copy range")}]])
-   
-  
-
-(defn cell [c r data]
-  (let [datum (some #(if (and (= c (:col %)) (= r (:row %))) %) data)]
-    ^{:key (str c r)} [:td
-                       [:input {:id (str c r)
-                                    :value (if (= (get datum :view nil) :value)
-                                             (get datum :value "")
-                                             (get datum :error (get datum :display (get datum :value ""))))
-                                    :on-change (partial on-change c r datum)
-                                    :on-blur (partial on-leave-cell c r)
-                                    :on-focus (partial on-enter-cell c r)
-                                    :on-paste #(println "paste" %);TODO
-                                    :on-drop #(println "drop" %);TODO
-                                    :on-keyPress (partial on-keyPress c r)}]
-                       (smart-border c r)]))
-(defn row [r cols data]
-  ^{:key (str "row-" r)} [:tr
-                          (cons
-                            ^{:key (str "row-head-" r)} [:th (str r)]
-                            (map #(cell % r data) cols))])
-(defn header-row [cols]
-  ^{:key "header"} [:tr
-                    (cons
-                      ^{:key "corner"} [:th]
-                      (map (fn [c] ^{:key (str "col-head-" c)} [:th c]) cols))])
-
-(defn sheet [data]
-  [:table [:tbody
-           (let [maxrow (highest :row data)
-                 cols (take-while (partial not= (next-letter (highest :col data))) col-letters)]
-             (cons
-               (header-row cols)
-               (map #(row % cols data) (range 1 (inc maxrow)))))]])
-
-(defn app []
-  [:div
-   ;[:h3 "Microtables"]
-   [sheet @data-atom]])
-
-;; -------------------------
-;; Initialize app
-
-(swap! data-atom #(->> % (map add-parsed-variables) (re-evaluate))) ; evalutate any formulas the first time
-
-(defn mount-root []
-  (r/render [app] (.getElementById js/document "app")))
-
-(defn init! []
-  (mount-root))
-

+ 0 - 6
old-frontend/webpack.config.js

@@ -1,6 +0,0 @@
-module.exports = {
-    entry: './src/js/index.js',
-    output: {
-        filename: 'index.bundle.js',
-    },
-};

File diff suppressed because it is too large
+ 0 - 2978
old-frontend/yarn.lock