william-vw / n3-editor-js

A Notation3 Editor in JavaScript
Apache License 2.0
13 stars 5 forks source link

usage of sintaxica as sparql editor; #12

Open damianw27 opened 1 year ago

william-vw commented 1 year ago

@damianw27 This is great work. I created and pushed a separate branch (integrating some later changes I had made to the main code) to work on: https://github.com/william-vw/n3-editor-js/tree/pull_12

One problem is that if I copy paste a bunch of SPARQL queries (plain text, no formatting) I get the following (a bunch of whitespace on the left).

Screenshot 2023-07-19 at 5 22 48 PM

Also the layout is bunched to the left (this may also be related to my crappy HTML code):

Screenshot 2023-07-20 at 7 59 02 AM

Would it be possible to fix these issues?

damianw27 commented 1 year ago

Yup, I will have a look at this after I do my job duties.

damianw27 commented 1 year ago

I found few problems in styles. Now everything should fit fine.

william-vw commented 1 year ago

@damianw27 The updated editor.js still doesn't work for the editor (nor your online editor) when programmatically setting the editor value.

This is the code you used to update the editor value (with a hard-coded query):

$("#code-textarea--input").val("CONSTRUCT {?x ?y ?z} WHERE {?x ?y z} .") 

If you try it then the query appears, but after clicking in the editor window, it disappears. Feel free try it yourself here: http://n3-editor.herokuapp.com/n3/editor/sspin3.html

Also, when directly setting the query after loading the page nothing happens; if I delay this operation for two seconds, then the query does appear (but with the same "disappearing act" as before). Is there some specific onload event I should be listening for? (As I said, I already wait for the page onload event.)

damianw27 commented 1 year ago

In my case, the following code works just fine

  var observer = new MutationObserver(function() {
    const textarea = document.getElementById('code-textarea--input');

    if (textarea !== null) {
      textarea.value = "CONSTRUCT {?x ?y ?z} WHERE {?x ?y z} .";
      observer.disconnect();
    }
  });

  observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true});

Is there any way to test the app with hot reload?

william-vw commented 1 year ago

@damianw27

Is there any way to test the app with hot reload?

You can clone the latest repo (sparql_to_n3 branch) and run nodemon app.js - the location defaults to localhost:3002/n3/editor/sspin3.html (version with syntaxica). Most features won't work but they're also not needed in this case.

See lines 296-300 for my efforts on updating the editor, as per the code you had previously shared (and trying the aforementioned delay).

damianw27 commented 1 year ago

@william-vw with usage of MutationObserver everything works fine

william-vw commented 1 year ago

@damianw27 if you can show me an updated PR with functioning code then I will integrate into the editor next week