Skip to content

Commit

Permalink
re-org, notebook formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuebert committed Jul 8, 2023
1 parent 990adf9 commit 0db83e8
Show file tree
Hide file tree
Showing 31 changed files with 428 additions and 401 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns cells.api
(ns cells.core
(:require [cells.async :as async]
[cells.hooks :as hooks]
[cells.impl :as impl]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
(ns clerkify.maria
(ns maria.clerkify
(:require ["jszip" :as jszip]
["file-saver" :as file-saver]
[applied-science.js-interop :as j]
[maria.editor.doc :as editor.doc]
[maria.editor.keymaps :as keymaps]
[shadow.resource :as rc]))

(defn download-clerkified-zip
Expand All @@ -17,4 +20,11 @@
source))
(.generateAsync #js{:type "blob"})
(.then (fn [content]
(file-saver/saveAs content "clerkified-maria.zip")))))
(file-saver/saveAs content "clerkified-maria.zip")))))

(keymaps/register-commands!
{:file/save-as-clerk-project {:kind :prose
:f (fn [state dispatch view]
(download-clerkified-zip
(-> (j/get-in view [:state :title])
editor.doc/doc->clj)))}})
9 changes: 5 additions & 4 deletions editor2/src/main/maria/cloud/core.cljs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
(ns maria.cloud.core
(:require [applied-science.js-interop :as j]
[clojure.edn :as edn]
[maria.cloud.persistence]
[maria.clerkify]
[maria.cloud.menubar :as menu]
[maria.cloud.persistence]
[maria.cloud.routes :as routes]
[maria.cloud.sidebar :as sidebar]
[maria.cloud.views]
[maria.editor.code-blocks.docbar :as docbar]
[maria.editor.code-blocks.docbar]
[maria.editor.code.docbar :as docbar]
[maria.editor.code.docbar]
[maria.editor.command-bar :as command-bar]
[maria.scratch]
[maria.ui :as ui :refer [defview]]
[maria.ui :refer [defview]]
[re-db.api :as db]
[yawn.hooks :as h]
[yawn.root :as root]
Expand Down
4 changes: 2 additions & 2 deletions editor2/src/main/maria/cloud/github.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
[applied-science.js-interop :as j]
[maria.cloud.config.public :refer [env]]
[maria.cloud.local :as local]
[maria.editor.keymaps :as keymaps]
[maria.editor.util :as u]
[promesa.core :as p]
[re-db.reactive :as r]
[maria.editor.keymaps :as keymaps]))
[re-db.reactive :as r]))

;; TODO ...
;; wait to load gist page until we have an auth result (in/out)
Expand Down
5 changes: 2 additions & 3 deletions editor2/src/main/maria/cloud/menubar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
(:require ["@radix-ui/react-menubar" :as menu :refer [Item Separator Root Menu Trigger Portal Content]]
["@radix-ui/react-avatar" :as ava]
[clojure.string :as str]
[maria.cloud.github :as gh]
[maria.cloud.sidebar :as sidebar]
[maria.editor.command-bar :as command-bar]
[maria.editor.icons :as icons]
[maria.cloud.github :as gh]
[maria.editor.keymaps :as keymaps]
[maria.ui :as ui]
[yawn.view :as v]
[shadow.resource :as rc]))
[yawn.view :as v]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Components
Expand Down
1 change: 0 additions & 1 deletion editor2/src/main/maria/cloud/sidebar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
[maria.ui :as ui]
[promesa.core :as p]
[re-db.api :as db]
[re-db.reactive :as r]
[re-db.hooks :as hooks]
[yawn.view :as v]))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns maria.curriculum.animation-quickstart
{:curriculum/title "Animation Quickstart"
:curriculum/description "Get a running start at making basic animations using the Shapes library."}
(:require [cells.api :refer :all]
(:require [cells.core :refer :all]
[shapes.core :refer :all]))

;; # Animations Quick-Start
Expand Down
2 changes: 1 addition & 1 deletion editor2/src/main/maria/curriculum/data_flow.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns maria.curriculum.data-flow
{:curriculum/title "Data Flow"}
(:require [cells.api :as cell :refer [defcell cell]]
(:require [cells.core :as cell :refer [defcell cell]]
[shapes.core :refer :all]))

;; # Data Flow
Expand Down
2 changes: 1 addition & 1 deletion editor2/src/main/maria/curriculum/example_gallery.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns maria.curriculum.example-gallery
{:curriculum/title "Example Gallery"
:curriculum/description "See what other people have made using Maria"}
(:require [cells.api :refer :all]
(:require [cells.core :refer :all]
[shapes.core :refer :all]))

;; # Example Gallery
Expand Down
2 changes: 1 addition & 1 deletion editor2/src/main/maria/curriculum/welcome_to_cells.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns maria.curriculum.welcome-to-cells
{:curriculum/title "Cells Quickstart"
:curriculum/description "Learn how to make things come alive and change over time."}
(:require [cells.api :refer :all]
(:require [cells.core :refer :all]
[shapes.core :refer :all]))

;; # Say Hello to Cells
Expand Down
2 changes: 1 addition & 1 deletion editor2/src/main/maria/curriculum/what_if.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{:curriculum/title "What if"
:curriculum/description "The if statement explained."}
(:require [shapes.core :refer :all]
[maria.editor.code-blocks.repl :refer :all]))
[maria.editor.code.repl :refer :all]))

;; # What if?

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns maria.editor.code-blocks.NodeView
(ns maria.editor.code.NodeView
(:require ["@codemirror/commands" :as cmd]
["@codemirror/language" :as lang]
["@codemirror/state" :refer [EditorState]]
Expand All @@ -10,13 +10,13 @@
[applied-science.js-interop :as j]
[applied-science.js-interop.alpha :refer [js]]
[clojure.string :as str]
[maria.editor.code-blocks.commands :as commands]
[maria.editor.code-blocks.completions :as completions]
[maria.editor.code-blocks.docbar :as eldoc]
[maria.editor.code-blocks.error-marks :as error-marks]
[maria.editor.code-blocks.eval-region :as eval-region]
[maria.editor.code-blocks.styles :as styles]
[maria.editor.code-blocks.views :as views]
[maria.editor.code.commands :as commands]
[maria.editor.code.completions :as completions]
[maria.editor.code.docbar :as eldoc]
[maria.editor.code.error-marks :as error-marks]
[maria.editor.code.eval-region :as eval-region]
[maria.editor.code.styles :as styles]
[maria.editor.code.views :as views]
[maria.editor.keymaps :as keymaps]
[maria.editor.prosemirror.schema :as prose-schema]
[nextjournal.clojure-mode :as clj-mode]
Expand All @@ -37,16 +37,16 @@
(reset! !focused-view nil))))

(js
(defn focus! [{:keys [codeView on-mount]}]
(on-mount #(.focus codeView))))
(defn focus! [{:keys [CodeView on-mount]}]
(on-mount #(.focus CodeView))))

(js
(defn set-initial-focus!
"If ProseMirror cursor is within code view, focus it."
[{:as this :keys [getPos proseView codeView]}]
(let [cursor (dec (.. proseView -state -selection -$anchor -pos))
[{:as this :keys [getPos ProseView CodeView]}]
(let [cursor (dec (.. ProseView -state -selection -$anchor -pos))
start (getPos)
length (.. codeView -state -doc -length)
length (.. CodeView -state -doc -length)
end (+ (getPos) length)]
(when (and (>= cursor start)
(< cursor end))
Expand All @@ -55,11 +55,11 @@
(js
(defn code:forward-update
"When the code-editor is focused, forward events from it to ProseMirror."
[{:keys [codeView proseView getPos code-updating?]} code-update]
(let [{prose-state :state} proseView]
[{:keys [CodeView ProseView getPos code-updating?]} code-update]
(let [{prose-state :state} ProseView]
(when (.-focusChanged code-update)
(set-focus! codeView (.-hasFocus codeView)))
(when (and (.-hasFocus codeView) (not code-updating?))
(set-focus! CodeView (.-hasFocus CodeView)))
(when (and (.-hasFocus CodeView) (not code-updating?))
(let [start-pos (inc (getPos))
{from' :from to' :to} (.. code-update -state -selection -main)
{code-changed? :docChanged
Expand Down Expand Up @@ -94,21 +94,21 @@
(.-doc tr)
(+ start-pos from')
(+ start-pos to')))
(.dispatch proseView tr)))))))
(.dispatch ProseView tr)))))))

(defn- controlled-update [this f]
(j/!set this :code-updating? true)
(f)
(j/!set this :code-updating? false))

(defn code-text [^js codeView] (.. codeView -state -doc (toString)))
(defn code-text [^js CodeView] (.. CodeView -state -doc (toString)))

(js
(defn prose:set-selection
"Called when ProseMirror tries to put the selection inside the node."
[{:as this :keys [codeView dom]} anchor head]
[{:as this :keys [CodeView dom]} anchor head]
(controlled-update this
#(do (.dispatch codeView {:selection {:anchor anchor
#(do (.dispatch CodeView {:selection {:anchor anchor
:head head}})
(when-not (.contains dom (.. js/document (getSelection) -focusNode))
(focus! this))))))
Expand All @@ -135,23 +135,23 @@
:insert (.slice new-text start new-end)})))))

(js
(defn prose:forward-update [{:as this :keys [codeView]
(defn prose:forward-update [{:as this :keys [CodeView]
prev-node :proseNode} new-node]
(boolean
(when (= (.-type prev-node)
(.-type new-node))
(j/!set this :proseNode new-node)
(let [new-text (.-textContent new-node)
old-text (code-text codeView)]
old-text (code-text CodeView)]
(when (not= new-text old-text)
(controlled-update this
(fn []
(.dispatch codeView {:changes (text-diff old-text new-text)
(.dispatch CodeView {:changes (text-diff old-text new-text)
:annotations [(u/user-event-annotation "noformat")]})))))
true))))

(defn prose:select-node [^js this]
(.. this -codeView focus))
(.. this -CodeView focus))

(def language
(.define lang/LRLanguage
Expand All @@ -162,27 +162,27 @@
styles/code-styles]})})))

(js
(defn editor [{:as proseNode :keys [textContent]} proseView getPos]
(defn editor [{:as proseNode :keys [textContent]} ProseView getPos]
(let [el (doto (js/document.createElement "div")
(.. -classList (add "my-4" "md:flex" "node-view")))
(.. -classList (add "my-4" "md:flex" "NodeView")))
this (j/obj :id (str (gensym "code-view-")))
root (root/create el (views/code-row this))]
(j/extend! this
{:initialNs (str/starts-with? textContent "(ns ")
:getPos getPos
:proseView proseView
:ProseView ProseView
:proseNode proseNode
:mounted! (fn [el]
(.appendChild el (.. this -codeView -dom))
(doto (.. this -codeView -dom -classList)
(.appendChild el (.. this -CodeView -dom))
(doto (.. this -CodeView -dom -classList)
(.add "rounded-r")
(.add "overflow-hidden"))
(set-initial-focus! this)
(when-not (j/get this :mounted?)
(j/!set this :mounted? true)
^:clj (doseq [f (j/get this :on-mounts)] (f))
(j/delete! this :on-mounts)))
:codeView (-> (new EditorView
:CodeView (-> (new EditorView
{:state
(.create EditorState
{:doc textContent
Expand Down Expand Up @@ -217,7 +217,7 @@
(eldoc/extension this)
(error-marks/extension)
]})})
(j/!set :node-view this))
(j/!set :NodeView this))
:!result (atom nil)

:on-mounts []
Expand All @@ -240,8 +240,8 @@
;; keyboard events that are handled by a keymap are already stopped;
;; not sure what events should be stopped here.
(instance? js/MouseEvent e))
:destroy #(let [{:keys [codeView !result]} this]
(.destroy codeView)
:destroy #(let [{:keys [CodeView !result]} this]
(.destroy CodeView)
(root/unmount-soon root)
^:clj (let [value (:value @!result)]
(when (satisfies? r/IReactiveValue value)
Expand Down
Loading

0 comments on commit 0db83e8

Please sign in to comment.