mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 14:14:55 +00:00
Fix sci
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
"devDependencies": {
|
||||
"@fullhuman/postcss-purgecss": "^2.1.2",
|
||||
"@tailwindcss/ui": "^0.1.3",
|
||||
"dev": "^0.1.3",
|
||||
"purgecss": "^2.1.0",
|
||||
"shadow-cljs": "2.8.81",
|
||||
"tailwindcss": "^1.2.0"
|
||||
|
||||
@@ -5,10 +5,7 @@
|
||||
:builds
|
||||
{:app
|
||||
{:target :browser
|
||||
:module-loader true
|
||||
:modules {:main {:init-fn frontend.core/init}
|
||||
:sci {:entries [frontend.extensions.sci]
|
||||
:depends-on #{:main}}}
|
||||
:modules {:main {:init-fn frontend.core/init}}
|
||||
|
||||
:output-dir "../resources/static/js"
|
||||
:asset-path "/static/js"
|
||||
|
||||
@@ -25,12 +25,10 @@
|
||||
[frontend.mixins :as mixins]
|
||||
[frontend.extensions.latex :as latex]
|
||||
[frontend.extensions.code :as code]
|
||||
[frontend.extensions.sci :as sci]
|
||||
["/frontend/utils" :as utils]
|
||||
[frontend.format.block :as block]
|
||||
[clojure.walk :as walk]
|
||||
[shadow.lazy :as lazy]))
|
||||
|
||||
(def sci-eval-string (lazy/loadable frontend.extensions.sci/eval-string))
|
||||
[clojure.walk :as walk]))
|
||||
|
||||
;; local state
|
||||
(defonce *heading-children
|
||||
@@ -954,29 +952,6 @@
|
||||
[:div.ml-4.text-lg
|
||||
(blocks config result)]]))
|
||||
|
||||
(defn sci-clojure-eval-inner
|
||||
[code]
|
||||
[:div
|
||||
[:code "Results:"]
|
||||
[:div.results.mt-1
|
||||
[:pre.pre-wrap-white-space.code
|
||||
(try
|
||||
(let [result (@sci-eval-string code)]
|
||||
(str result))
|
||||
(catch js/Error e
|
||||
(str "Error: " (gobj/get e "message"))))]]])
|
||||
|
||||
(def sci-loading? (atom true))
|
||||
|
||||
(rum/defc sci-clojure-eval < rum/reactive
|
||||
[code]
|
||||
(let [loading? (rum/react sci-loading?)]
|
||||
(if (lazy/ready? sci-eval-string)
|
||||
(sci-clojure-eval-inner code)
|
||||
(do
|
||||
(lazy/load sci-eval-string (fn [_] (reset! sci-loading? false)))
|
||||
(widgets/loading "loading @borkdude/sci")))))
|
||||
|
||||
(defn block
|
||||
[config item]
|
||||
(try
|
||||
@@ -1010,7 +985,7 @@
|
||||
(if (and (= language "clojure") (contains? (set options) ":results"))
|
||||
[:div
|
||||
(code/highlight (str (dc/squuid)) attr code)
|
||||
(sci-clojure-eval code)]
|
||||
(sci/eval-result code)]
|
||||
(code/highlight (str (dc/squuid)) attr code)))
|
||||
["Quote" l]
|
||||
(->elem
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
[frontend.state :as state]))
|
||||
|
||||
(defonce dev? ^boolean goog.DEBUG)
|
||||
;; (defonce dev? true)
|
||||
|
||||
(def website
|
||||
(if dev?
|
||||
|
||||
@@ -1,12 +1,41 @@
|
||||
(ns frontend.extensions.sci
|
||||
(:require [sci.core :as sci]))
|
||||
(:require [rum.core :as rum]
|
||||
[frontend.loader :as loader]
|
||||
[frontend.components.widgets :as widgets]
|
||||
[frontend.config :as config]
|
||||
[goog.object :as gobj]))
|
||||
|
||||
;; #+begin_src clojure :results
|
||||
;; (+ 1 4)
|
||||
;; #+end_src
|
||||
(defn loaded? []
|
||||
js/window.sci)
|
||||
|
||||
;; TODO: lazy load extensions
|
||||
(defonce *loading? (atom true))
|
||||
|
||||
(defn ^:export eval-string
|
||||
(defn eval-string
|
||||
[code]
|
||||
(sci/eval-string code))
|
||||
(when loaded?
|
||||
(js/window.sci.evalString code)))
|
||||
|
||||
(rum/defc eval-result < rum/reactive
|
||||
{:did-mount (fn [state]
|
||||
(if (loaded?)
|
||||
(reset! *loading? false)
|
||||
(do
|
||||
(reset! *loading? true)
|
||||
(loader/load
|
||||
(config/asset-uri "/static/js/sci.min.js")
|
||||
(fn []
|
||||
(reset! *loading? false)))))
|
||||
state)}
|
||||
[code]
|
||||
(let [loading? (rum/react *loading?)]
|
||||
(if loading?
|
||||
(widgets/loading "loading @borkdude/sci")
|
||||
[:div
|
||||
[:code "Results:"]
|
||||
[:div.results.mt-1
|
||||
[:pre.pre-wrap-white-space.code
|
||||
(try
|
||||
(let [result (eval-string code)]
|
||||
(str result))
|
||||
(catch js/Error e
|
||||
(str "Error: " (gobj/get e "message"))))]]])))
|
||||
|
||||
@@ -138,13 +138,6 @@ base64-js@^1.0.2:
|
||||
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
|
||||
integrity sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==
|
||||
|
||||
bindings@^1.3.1:
|
||||
version "1.5.0"
|
||||
resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df"
|
||||
integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==
|
||||
dependencies:
|
||||
file-uri-to-path "1.0.0"
|
||||
|
||||
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
|
||||
version "4.11.8"
|
||||
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
|
||||
@@ -444,13 +437,6 @@ detective@^5.2.0:
|
||||
defined "^1.0.0"
|
||||
minimist "^1.1.1"
|
||||
|
||||
dev@^0.1.3:
|
||||
version "0.1.3"
|
||||
resolved "https://registry.yarnpkg.com/dev/-/dev-0.1.3.tgz#89fdc08705e0e7eaef92d012e26751e4d744322a"
|
||||
integrity sha1-if3AhwXg5+rvktAS4mdR5NdEMio=
|
||||
dependencies:
|
||||
inotify ">= 0.1.6"
|
||||
|
||||
diff@^4.0.2:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
|
||||
@@ -527,11 +513,6 @@ fast-xml-parser@^3.16.0:
|
||||
resolved "https://registry.yarnpkg.com/fast-xml-parser/-/fast-xml-parser-3.17.4.tgz#d668495fb3e4bbcf7970f3c24ac0019d82e76477"
|
||||
integrity sha512-qudnQuyYBgnvzf5Lj/yxMcf4L9NcVWihXJg7CiU1L+oUCq8MUnFEfH2/nXR/W5uq+yvUN1h7z6s7vs2v1WkL1A==
|
||||
|
||||
file-uri-to-path@1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
|
||||
integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==
|
||||
|
||||
follow-redirects@1.5.10:
|
||||
version "1.5.10"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
|
||||
@@ -663,14 +644,6 @@ inherits@2.0.3:
|
||||
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
|
||||
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=
|
||||
|
||||
"inotify@>= 0.1.6":
|
||||
version "1.4.6"
|
||||
resolved "https://registry.yarnpkg.com/inotify/-/inotify-1.4.6.tgz#c5a51852df1647d1a589d46c4baa2771ed36b8d2"
|
||||
integrity sha512-WW8/uqIA04O3AePQVe/Ms3ZLR0yGamaz8YOEpaXc4WBAGOPZfzu58wWErEPSUYaPyDrJRIeCn6PEIQgC1ZyQ5w==
|
||||
dependencies:
|
||||
bindings "^1.3.1"
|
||||
nan "^2.12.1"
|
||||
|
||||
isarray@^1.0.0, isarray@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
|
||||
@@ -790,11 +763,6 @@ ms@2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
|
||||
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=
|
||||
|
||||
nan@^2.12.1:
|
||||
version "2.14.0"
|
||||
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
|
||||
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==
|
||||
|
||||
nested-property@^1.0.4:
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/nested-property/-/nested-property-1.0.4.tgz#4068c4289d1f3ac9f367e784502ff342d277ee2f"
|
||||
|
||||
Reference in New Issue
Block a user