Skip to content

Commit

Permalink
updating name
Browse files Browse the repository at this point in the history
adding zmq
removing old ui code
  • Loading branch information
almibe committed Dec 11, 2024
1 parent a5bcb7d commit f15be27
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 110 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<link rel="icon" type="image/svg+xml" href="/src/assets/logo.svg" />
<title>Ligature Notebook</title>
<title>Ligature Desktop</title>
</head>

<body>
Expand Down
132 changes: 132 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-dialog = "2"
tauri-plugin-fs = "2"
zmq = "0.10.0"

13 changes: 8 additions & 5 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
#[tauri::command(async)]
fn run_wander(script: String) -> String {
let ctx = zmq::Context::new();
let socket = ctx.socket(zmq::REQ).unwrap();
socket.connect("tcp://127.0.0.1:4200").unwrap();
socket.send(&script, 0).unwrap();
socket.recv_string(0).unwrap().unwrap()
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
Expand All @@ -10,7 +13,7 @@ pub fn run() {
.plugin(tauri_plugin_fs::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![greet])
.invoke_handler(tauri::generate_handler![run_wander])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
6 changes: 3 additions & 3 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "ligature-notebook",
"productName": "ligature-desktop",
"version": "0.1.0",
"identifier": "dev.ligature.notebook",
"identifier": "dev.ligature.desktop",
"build": {
"beforeDevCommand": "npm run dev",
"devUrl": "http://localhost:1420",
Expand All @@ -12,7 +12,7 @@
"app": {
"windows": [
{
"title": "ligature-notebook",
"title": "Ligature Desktop",
"width": 800,
"height": 600
}
Expand Down
15 changes: 9 additions & 6 deletions src/components/Application.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { createSignal, onMount } from "solid-js"
import { showEditor } from "@ligature/ligature-components/src/editor/editor"
import { run as runScript } from "@ligature/ligature"
import { readValue } from "@ligature/ligature"
import { runWander } from "../lib/ligature-client"
import { EditorView } from "codemirror";
import { showText } from "@ligature/ligature-components/src/text/text"
import { showGraph } from "@ligature/ligature-components/src/graph/graph"
import Split from 'split-grid'

export function Application() {
let [resultText, setResultText] = createSignal("")
let editor: EditorView = null;
onMount(() => {
Split({
Expand All @@ -17,9 +19,11 @@ export function Application() {
editor = showEditor(document.querySelector("#editor"), "")
})

function run() {
let result = runScript(editor.state.doc.toString())
setResultText(JSON.stringify(result))
async function run() {
let result = await runWander(editor.state.doc.toString())
let value = readValue(result)
showText(document.querySelector("#results"), value)
//showGraph(document.querySelector("#results"), value)
}

return <div style="height:100%; width: 100%">
Expand All @@ -32,7 +36,6 @@ export function Application() {
</div>
<div class="gutter-row gutter-row-1"></div>
<div id="results" style="overflow: auto">
{resultText}
</div>
</div>
</div>
Expand Down
96 changes: 1 addition & 95 deletions src/components/Store.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,3 @@
import { open, save } from '@tauri-apps/plugin-dialog';
import { exists, readTextFile, writeTextFile } from '@tauri-apps/plugin-fs';
import { open as openFile } from '@tauri-apps/plugin-fs';
import { createStore } from 'solid-js/store';

export type CellModel = {
type: 'markdown' | 'wander',
output: 'text' | 'table' | 'graph',
source: string
}

export const [store, setStore] = createStore({
cells: []
})

export function newDocument() {
setStore("cells", [])
}

export function addCell() {
setStore("cells", [
...store.cells,
{
type: 'markdown',
output: 'text',
source: '# New Cell'
}
])
}

export async function openDocument() {
// Open a dialog
const path = await open({
multiple: false,
directory: false,
});
const text = await readTextFile(path);
let newCells = JSON.parse(text)
setStore("cells", newCells.cells)
}

export async function saveDocument() {
const doc = { cells: store.cells }
const path = await save({
filters: [
{
name: '.wander',
extensions: ['wander']
}
]
})
if (path != null | path != undefined) {
await writeTextFile(path, JSON.stringify(doc))
}
}

export function updateType(id: number, type: 'markdown' | 'wander') {
setStore("cells", id, { type: type })
}

export function updateSource(id: number, source: string) {
setStore("cells", id, { source: source })
}

export function moveUp(index: number) {
if (index > 0) {
const cells = store.cells
const newCells = cells.slice(0, index-1).concat([cells[index]], [cells[index-1]], cells.slice(index+1, cells.length))
setStore("cells", newCells)
}
}

export function moveDown(index: number) {
if (index+1 < store.cells.length) {
const cells = store.cells
const newCells = cells.slice(0, index).concat([cells[index+1]], [cells[index]], cells.slice(index+2, cells.length))
setStore("cells", newCells)
}
}

export function appendAfter(index: number) {
const newCell = {
type: 'markdown',
output: 'text',
source: '# New Cell'
}

setStore("cells", store.cells.slice(0, index+1).concat([newCell], store.cells.slice(index+1, store.cells.length)))
}

export function removeCell(index: number) {
setStore("cells", store.cells.slice(0, index).concat(store.cells.slice(index+1, store.cells.length)))
}

export function lookupCell(id: number) {
return store.cells[id]
}
export const [store, setStore] = createStore({})
Loading

0 comments on commit f15be27

Please sign in to comment.