Skip to content

Commit

Permalink
Merge pull request #60 from calcit-lang/deps-graph
Browse files Browse the repository at this point in the history
experimenting deps graph
  • Loading branch information
NoEgAm authored Aug 20, 2024
2 parents 4d9b581 + a9f7fa0 commit d4640e1
Show file tree
Hide file tree
Showing 8 changed files with 2,066 additions and 406 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
registry-url: https://registry.npmjs.org/
cache: yarn

- uses: calcit-lang/[email protected].3
- uses: calcit-lang/[email protected].4
with:
version: "0.8.50"
version: "0.9.4"

- run: caps --ci && yarn && yarn compile-server && yarn compile-page && yarn release-page

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
node-version: 20
cache: yarn

- uses: calcit-lang/[email protected].3
- uses: calcit-lang/[email protected].4
with:
version: "0.8.50"
version: "0.9.4"

- run: caps --ci && yarn && yarn compile-server && yarn compile-page && yarn release-page

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ js-out/
out-page/

/profile.json

.DS_Store
1,513 changes: 1,489 additions & 24 deletions calcit.cirru

Large diffs are not rendered by default.

223 changes: 215 additions & 8 deletions compact.cirru
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

{} (:package |app)
:configs $ {} (:init-fn |app.server/main!) (:reload-fn |app.server/reload!) (:version |0.9.1)
:configs $ {} (:init-fn |app.server/main!) (:reload-fn |app.server/reload!) (:version |0.9.3)
:modules $ [] |lilac/ |memof/ |recollect/ |cumulo-util.calcit/ |ws-edn.calcit/ |bisection-key/ |respo-markdown.calcit/
:entries $ {}
:client $ {} (:init-fn |app.client/main!) (:reload-fn |app.client/reload!)
Expand Down Expand Up @@ -713,6 +713,8 @@
comp-profile (>> states :profile) (:user store) (:id session) d
(:files d)
comp-page-files (>> states :files) (:selected-ns writer) d
(:graph d)
comp-deps-graph (>> states :graph) (:package d) (:configs d) (:entries d) (:deps-dict d) (:writer d)
(:editor d)
comp-page-editor (>> states :editor) (:stack writer) d (:pointer writer) picker-mode? theme
(:search d)
Expand Down Expand Up @@ -767,6 +769,7 @@
app.comp.configs :refer $ comp-configs
app.config :refer $ dev?
app.comp.about :as about
app.comp.graph :refer $ comp-deps-graph
|app.comp.draft-box $ %{} :FileEntry
:defs $ {}
|comp-draft-box $ %{} :CodeEntry (:doc |)
Expand Down Expand Up @@ -1086,6 +1089,196 @@
app.style :as style
app.comp.modal :refer $ comp-modal
app.util :refer $ file->cirru
|app.comp.graph $ %{} :FileEntry
:defs $ {}
|comp-deps-graph $ %{} :CodeEntry (:doc |)
:code $ quote
defcomp comp-deps-graph (states pkg configs entries deps-dict writer)
let
init-fn $ :init-fn configs
pair $ .split init-fn "\"/"
that-ns $ nth pair 0
that-def $ nth pair 1
cursor $ :cursor states
state $ either (:data states)
{}
:ns $ nth pair 0
:def $ nth pair 1
plugin-entries $ use-modal-menu (>> states :entries-menu)
{} (:title |Entries)
:style $ {} (:width 300)
:backdrop-style $ {}
:items $ concat
[] $ :: :item (:: :def that-ns that-def) init-fn
-> entries
either $ {}
, vals .to-list $ map
fn (conf)
let
pair $ .split (:init-fn conf) "\"/"
:: :item
:: :def (nth pair 0) (nth pair 1)
:init-fn conf
:on-result $ fn (result d!)
tag-match (nth result 1)
:def a-ns a-def
d! cursor $ {} (:ns a-ns) (:def a-def)
pointer $ get writer :pointer
bookmark $ if (some? pointer)
get-in writer $ [] :stack (:pointer writer)
, nil
[] (effect-navigate bookmark)
div
{} $ :style
{} $ :padding-right 24
div
{} $ :style
{} $ :padding "\"4px 16px"
span $ {}
:inner-text $ str (:ns state) "\"/" (:def state)
:on-click $ fn (e d!) (.show plugin-entries d!)
:class-name style-def-entry
.render plugin-entries
comp-entry-deps (:ns state) (:def state) deps-dict pkg $ []
|comp-entry-deps $ %{} :CodeEntry (:doc |)
:code $ quote
defn comp-entry-deps (that-ns that-def deps-dict pkg footprints)
let
entry $ :: :def that-ns that-def
this-deps $ get deps-dict entry
internal-deps $ -> this-deps (.to-list)
filter $ fn (item)
tag-match item
:reference child-ns child-def
.starts-with? child-ns $ str pkg "\"."
_ false
div
{} $ :class-name (str-spaced css/row-middle style-entry)
if
not $ empty? footprints
span $ {}
:class-name $ str-spaced css/font-code! style-def
:id $ gen-def-id that-ns that-def
:inner-text that-def
:on-click $ fn (e d!)
d! :writer/edit $ :: :def that-ns that-def
if
and
not $ empty? footprints
not= that-ns $ get (last footprints) 1
<> that-ns style-ns
if (includes? footprints entry)
div ({})
<> "\"Recur" $ str-spaced css/font-fancy style-recur
if
not $ empty? internal-deps
list->
{} $ :class-name style-deps-area
-> internal-deps $ map
fn (item)
[] (str item)
tag-match item
:reference child-ns child-def
memof1-call-by (str child-ns "\"/" child-def) comp-entry-deps child-ns child-def deps-dict pkg $ conj footprints entry
_ $ div ({})
<> $ str "\"Unknown data: " item
|effect-navigate $ %{} :CodeEntry (:doc |)
:code $ quote
defeffect effect-navigate (bookmark) (action el at?)
if
and (= action :mount) (some? bookmark)
tag-match bookmark $
:def the-ns the-def coord
try
let
id $ str "\"#" (gen-def-id the-ns the-def)
target $ .!querySelector el id
if (some? target)
do (.!scrollIntoView target)
let
s $ -> target .-style
-> s .-opacity $ set! "\"1"
-> s .-backgroundColor $ set! (hsl 0 0 100 0.4)
-> s .-padding $ set! "\"0px 8px"
; -> s .-transitionDuration $ set! "\"0ms"
; flipped js/setTimeout 100 $ fn ()
-> s .-backgroundColor $ set! (hsl 0 0 100 0)
-> s .-transitionDuration $ set! "\"1000ms"
js/console.warn "\"found no target for:" id
fn (error) (js/console.error error)
|gen-def-id $ %{} :CodeEntry (:doc |)
:code $ quote
defn gen-def-id (that-ns that-def)
-> (str "\"def__" that-ns "\"__" that-def) (.replace "\"." "\"_DOT_") (.replace "\"!" "\"_EXP_") (.replace "\"#" "\"_SHA_") (.replace "\"*" "\"_STAR_") (.replace "\"?" "\"_QUE_") (.replace "\"%" "\"_PCT_")
|style-def $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-def $ {}
"\"&" $ {} (:white-space :pre)
:color $ hsl 0 0 100
:position :sticky
:top 0
:cursor :pointer
:opacity 0.6
; :transition-duration "\"400ms"
; :transition-property "\"background-color"
:border-radius "\"8px"
"\"&:hover" $ {} (:opacity 1)
|style-def-entry $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-def-entry $ {}
"\"&" $ {} (:cursor :pointer)
:color $ hsl 0 0 80
"\"&:hover" $ {}
:color $ hsl 0 0 100
|style-deps-area $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-deps-area $ {}
"\"&" $ {} (:max-height "\"96vh") (:margin-left 8) (:overflow :auto)
:border-color $ hsl 0 0 100 0.3
:border-style :solid
:border-width "\"1px 0 0px 1px"
:border-radius "\"16px"
:padding "\"4px 0"
:transition "\"300ms"
:transition-property "\"border-color"
"\"&:hover" $ {}
:border-color $ hsl 0 0 100 0.5
|style-entry $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-entry $ {}
"\"&" $ {}
; :border-left $ str "\"1px solid " (hsl 0 0 90 0.4)
:padding-left "\"8px"
:margin-left "\"8px"
:border-radius "\"8px"
; :box-shadow "\"0 0 2px #888"
|style-ns $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-ns $ {}
"\"&" $ {} (:font-size 12) (:vertical-align :middle) (:margin-left 8) (:white-space :nowrap)
:color $ hsl 0 0 50
|style-recur $ %{} :CodeEntry (:doc |)
:code $ quote
defstyle style-recur $ {}
"\"&" $ {}
:color $ hsl 0 0 60
:border-radius "\"8px"
:background-color $ hsl 300 10 100 0.2
:margin "\"2px 8px"
:padding "\"0 8px"
:ns $ %{} :CodeEntry (:doc |)
:code $ quote
ns app.comp.graph $ :require
respo.util.format :refer $ hsl
respo-ui.core :as ui
respo-ui.css :as css
respo.core :refer $ defcomp >> <> div span create-element list-> defeffect
respo.css :refer $ defstyle
respo.comp.inspect :refer $ comp-inspect
respo.comp.space :refer $ =<
app.config :refer $ dev?
memof.once :refer $ memof1-call-by
respo-alerts.core :refer $ use-alert use-prompt use-confirm use-modal-menu
|app.comp.header $ %{} :FileEntry
:defs $ {}
|comp-header $ %{} :CodeEntry (:doc |)
Expand All @@ -1100,6 +1293,8 @@
{} $ :class-name css/row-center
render-entry |Files :files router-name $ fn (e d!)
d! $ :: :router/change (:: :files)
render-entry |Graph :graph router-name $ fn (e d!)
d! $ :: :router/change (:: :graph)
render-entry |Editor :editor router-name $ fn (e d!)
d! $ :: :router/change (:: :editor)
render-entry |Search :search router-name $ fn (e d!)
Expand Down Expand Up @@ -3180,14 +3375,15 @@
|database $ %{} :CodeEntry (:doc |)
:code $ quote
def database $ {}
:sessions $ {}
:sessions $ do session ({})
:users $ {}
:package |app
:files $ {}
:saved-files $ {}
:configs configs
:entries $ {}
:usages-dict $ {}
:deps-dict $ {}
|notification $ %{} :CodeEntry (:doc |)
:code $ quote
def notification $ {} (:id nil) (:kind nil) (:text nil) (:time nil)
Expand Down Expand Up @@ -3694,6 +3890,13 @@
get-in session $ [] :writer :draft-ns
:sessions db
:id session
(:graph)
:: :graph $ {}
:package $ :package db
:configs $ :configs db
:deps-dict $ :deps-dict db
:entries $ :entries db
:writer $ :writer session
(:editor)
:: :editor $ twig-page-editor (:files db) (:saved-files db) (:sessions db) (:users db) writer (:id session) (:usages-dict db)
(:profile)
Expand Down Expand Up @@ -4191,6 +4394,7 @@
defn parse-all-deps (files)
let
*usages $ atom ({})
*deps $ atom ({})
-> files &map:to-list $ each
fn (pair)
let
Expand All @@ -4209,14 +4413,17 @@
this-def $ &list:nth pair 0
v $ &list:nth pair 1
entry $ :: :def this-ns this-def
*entry-deps $ atom (#{})
collect! $ fn (reference)
if (&map:contains? @*usages reference)
swap! *usages update reference $ fn (coll) (&include coll entry)
swap! *usages &map:assoc reference $ #{} entry
swap! *entry-deps include reference
parse-bookmarks-collect!
tree->cirru $ &record:get v :code
, local-defs import-rules this-ns this-def collect!
, @*usages
swap! *deps assoc entry @*entry-deps
:: :deps @*deps @*usages
|parse-bookmarks-collect! $ %{} :CodeEntry (:doc |)
:code $ quote
defn parse-bookmarks-collect! (tree local-defs import-rules this-ns this-def collect!)
Expand Down Expand Up @@ -4292,10 +4499,10 @@
|refresh-usages-dict $ %{} :CodeEntry (:doc |)
:code $ quote
defn refresh-usages-dict (db op-data sid op-id op-time)
let
usages-dict $ parse-all-deps
get-in db $ [] :files
assoc db :usages-dict usages-dict
tag-match
parse-all-deps $ get-in db ([] :files)
(:deps deps-dict usages-dict)
-> db (assoc :usages-dict usages-dict) (assoc :deps-dict deps-dict)
|use-import-def $ %{} :CodeEntry (:doc |)
:code $ quote
defn use-import-def (db picked sid op-id op-time)
Expand Down Expand Up @@ -5520,7 +5727,7 @@
|db->string $ %{} :CodeEntry (:doc |)
:code $ quote
defn db->string (db)
format-cirru-edn $ -> db (dissoc :sessions) (dissoc :saved-files) (dissoc :usages-dict)
format-cirru-edn $ -> db (dissoc :sessions) (dissoc :saved-files) (dissoc :usages-dict) (dissoc :deps-dict)
|expr? $ %{} :CodeEntry (:doc |)
:code $ quote
defn expr? (x) (&record:matches? schema/CirruExpr x)
Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "@calcit/editor",
"version": "0.9.1",
"version": "0.9.3",
"description": "Tree Editor for Calcit Language",
"bin": {
"ct": "server.mjs"
},
"scripts": {
"watch-server": "cr --emit-js",
"compile-server": "cr --emit-js --once",
"compile-page": "cr --emit-js --once --entry client --emit-path out-page",
"watch-server": "cr js",
"compile-server": "cr --once js",
"compile-page": "cr --once --entry client --emit-path out-page js",
"release-page": "vite build --base=./",
"watch-page": "cr --emit-js --emit-path out-page/ --entry client"
"watch-page": "cr --emit-path out-page/ --entry client js"
},
"repository": {
"type": "git",
Expand All @@ -22,17 +22,17 @@
"bottom-tip": "^0.1.5",
"cirru-color": "^0.2.4",
"copy-text-to-clipboard": "^3.2.0",
"feather-icons": "^4.29.1",
"feather-icons": "^4.29.2",
"url-parse": "^1.5.10",
"vite": "^5.2.9"
"vite": "^5.4.1"
},
"dependencies": {
"@calcit/procs": "^0.8.50",
"@calcit/procs": "^0.9.4",
"chalk": "^5.3.0",
"dayjs": "^1.11.10",
"dayjs": "^1.11.12",
"gaze": "^1.1.3",
"latest-version": "^9.0.0",
"nanoid": "^5.0.7",
"ws": "^8.16.0"
"ws": "^8.18.0"
}
}
Loading

0 comments on commit d4640e1

Please sign in to comment.