From 434201c657d54d69360c4576fe64bf37e4797c53 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Mon, 5 Aug 2024 00:27:20 +0300 Subject: [PATCH] discrete doc: Codemirror+Yjs --- Cargo.lock | 4 +- ng-app/package.json | 5 +- ng-app/src/api.ts | 7 + ng-app/src/apps/CodeMirrorEditor.svelte | 72 +++++++++++ ng-app/src/apps/ContainerView.svelte | 1 - ng-app/src/apps/PreTextViewer.svelte | 0 ng-app/src/lib/Document.svelte | 3 +- ng-app/src/lib/FullLayout.svelte | 4 +- ng-app/src/lib/components/NavBar.svelte | 19 +-- ng-app/src/routes/NURI.svelte | 5 +- ng-app/src/store.ts | 34 ++++- ng-app/src/tab.ts | 50 ++++++-- ng-app/src/zeras.ts | 2 +- ng-net/src/app_protocol.rs | 72 +++++++++-- ng-repo/src/errors.rs | 3 + ng-repo/src/types.rs | 6 + ng-sdk-js/src/lib.rs | 43 +++++++ ng-verifier/Cargo.toml | 2 +- ng-verifier/src/commits/mod.rs | 2 + ng-verifier/src/commits/transaction.rs | 164 +++++++++++++++++------- ng-verifier/src/request_processor.rs | 69 +++++++++- ng-verifier/src/rocksdb_user_storage.rs | 16 +++ ng-verifier/src/types.rs | 71 +++++++++- ng-verifier/src/user_storage/branch.rs | 24 +++- ng-verifier/src/user_storage/storage.rs | 29 +++++ ng-verifier/src/verifier.rs | 29 ++++- pnpm-lock.yaml | 58 +++++++++ 27 files changed, 702 insertions(+), 92 deletions(-) create mode 100644 ng-app/src/apps/CodeMirrorEditor.svelte create mode 100644 ng-app/src/apps/PreTextViewer.svelte diff --git a/Cargo.lock b/Cargo.lock index 6deb20d..a327cd0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7216,9 +7216,9 @@ dependencies = [ [[package]] name = "yrs" -version = "0.18.2" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4058d69bbbc97181d53d9d093a4b892001b84601f2fc4e27f48c8862bc8b369" +checksum = "a8ca5126331b9a5ef5bb10f3f1c3d01b05f298d348c66f8fb15497d83ee73176" dependencies = [ "arc-swap", "atomic_refcell", diff --git a/ng-app/package.json b/ng-app/package.json index e0fcff2..f461975 100644 --- a/ng-app/package.json +++ b/ng-app/package.json @@ -18,6 +18,7 @@ "dependencies": { "@codemirror/autocomplete": "^6.17.0", "@codemirror/commands": "^6.6.0", + "@codemirror/lang-javascript": "^6.2.2", "@codemirror/language": "^6.10.2", "@codemirror/legacy-modes": "^6.4.0", "@codemirror/lint": "^6.8.1", @@ -39,7 +40,9 @@ "svelte-i18n": "^4.0.0", "svelte-inview": "^4.0.2", "svelte-spa-router": "^3.3.0", - "vite-plugin-top-level-await": "^1.3.1" + "vite-plugin-top-level-await": "^1.3.1", + "y-codemirror.next": "^0.3.5", + "yjs": "^13.6.18" }, "devDependencies": { "@sveltejs/vite-plugin-svelte": "^2.0.0", diff --git a/ng-app/src/api.ts b/ng-app/src/api.ts index 5d582d0..36350cd 100644 --- a/ng-app/src/api.ts +++ b/ng-app/src/api.ts @@ -222,6 +222,13 @@ const handler = { let removes_json_str = new TextDecoder().decode(Uint8Array.from(event.payload.V0.Patch.graph.removes)); event.payload.V0.Patch.graph.removes = JSON.parse(removes_json_str); } + if (event.payload.V0.State?.discrete) { + let crdt = Object.getOwnPropertyNames(event.payload.V0.State.discrete)[0]; + event.payload.V0.State.discrete[crdt] = Uint8Array.from(event.payload.V0.State.discrete[crdt]); + } else if (event.payload.V0.Patch?.discrete) { + let crdt = Object.getOwnPropertyNames(event.payload.V0.Patch.discrete)[0]; + event.payload.V0.Patch.discrete[crdt] = Uint8Array.from(event.payload.V0.Patch.discrete[crdt]); + } let ret = callback(event.payload); if (ret === true) { await tauri.invoke("cancel_stream", {stream_id}); diff --git a/ng-app/src/apps/CodeMirrorEditor.svelte b/ng-app/src/apps/CodeMirrorEditor.svelte new file mode 100644 index 0000000..ad690f2 --- /dev/null +++ b/ng-app/src/apps/CodeMirrorEditor.svelte @@ -0,0 +1,72 @@ + + + +
+ + + +
\ No newline at end of file diff --git a/ng-app/src/apps/ContainerView.svelte b/ng-app/src/apps/ContainerView.svelte index bbeed74..95981cd 100644 --- a/ng-app/src/apps/ContainerView.svelte +++ b/ng-app/src/apps/ContainerView.svelte @@ -21,7 +21,6 @@ function contained(graph) { let ret = []; for (const g of graph) { - console.log(g) if (g.substring(104,137) === "http://www.w3.org/ns/ldp#contains") { let nuri = g.substring(140,240); let hash = nuri.substring(9,16); diff --git a/ng-app/src/apps/PreTextViewer.svelte b/ng-app/src/apps/PreTextViewer.svelte new file mode 100644 index 0000000..e69de29 diff --git a/ng-app/src/lib/Document.svelte b/ng-app/src/lib/Document.svelte index f0919ec..f51fecf 100644 --- a/ng-app/src/lib/Document.svelte +++ b/ng-app/src/lib/Document.svelte @@ -24,7 +24,7 @@ import { t } from "svelte-i18n"; import { Button, Progressbar, Spinner, Alert } from "flowbite-svelte"; import { inview } from 'svelte-inview'; - import { cur_tab_doc_can_edit, nav_bar, can_have_header, header_icon, header_title, header_description, cur_branch, set_header_in_view, edit_header_button, cur_app, load_official_app, nav_bar_reset_newest } from "../tab"; + import { cur_tab, cur_tab_doc_can_edit, nav_bar, can_have_header, header_icon, header_title, header_description, cur_branch, set_header_in_view, edit_header_button, cur_app, load_official_app, nav_bar_reset_newest } from "../tab"; import NavIcon from "./icons/NavIcon.svelte"; export let nuri = ""; @@ -68,6 +68,7 @@ class:"w-8 h-8 mr-2 mb-2 flex-none focus:outline-none" }}/> {/if} + {#if !$header_title} {$cur_tab.doc.nuri.substring(2,9)} {/if} {#if $cur_tab_doc_can_edit}