parent
95ed77e414
commit
029276e205
@ -0,0 +1,119 @@ |
||||
<!-- |
||||
// Copyright (c) 2022-2024 Niko Bonnieure, Par le Peuple, NextGraph.org developers |
||||
// All rights reserved. |
||||
// Licensed under the Apache License, Version 2.0 |
||||
// <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0> |
||||
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>, |
||||
// at your option. All files in the project carrying such |
||||
// notice may not be copied, modified, or distributed except |
||||
// according to those terms. |
||||
--> |
||||
|
||||
<script lang="ts"> |
||||
import { onMount, tick, onDestroy } from "svelte"; |
||||
import { |
||||
sparql_query, |
||||
toast_error, |
||||
toast_success, |
||||
reset_toasts |
||||
} from "../store"; |
||||
import { |
||||
in_memory_discrete, open_viewer, set_viewer |
||||
} from "../tab"; |
||||
import{ Sun, RocketLaunch } from "svelte-heros-v2"; |
||||
import { t } from "svelte-i18n"; |
||||
|
||||
import { Table, TableBody, TableBodyCell, TableBodyRow, TableHead, TableHeadCell, Toggle } from 'flowbite-svelte'; |
||||
|
||||
import CodeMirror from "svelte-codemirror-editor"; |
||||
import {StreamLanguage} from "@codemirror/language" |
||||
import { sparql } from "@codemirror/legacy-modes/mode/sparql"; |
||||
import {basicSetup} from "codemirror" |
||||
|
||||
import Highlight, { LineNumbers } from "svelte-highlight"; |
||||
import hljs from "highlight.js"; |
||||
import { definer } from "../turtle"; |
||||
import "svelte-highlight/styles/github.css"; |
||||
import { each } from "svelte/internal"; |
||||
const language = { |
||||
name: "turtle", |
||||
register: (hljs) => { |
||||
return definer(hljs); |
||||
}, |
||||
}; |
||||
|
||||
onMount(()=>{ |
||||
if (!$in_memory_discrete){ |
||||
$in_memory_discrete = "SELECT ?subject ?predicate ?object WHERE {\n ?subject ?predicate ?object .\n} LIMIT 10"; |
||||
} |
||||
}); |
||||
let union = false; |
||||
const run = async () => { |
||||
try{ |
||||
reset_toasts(); |
||||
results = await sparql_query($in_memory_discrete, union); |
||||
} catch(e) { |
||||
toast_error(e); |
||||
} |
||||
} |
||||
const openTurtle = () => { |
||||
reset_toasts(); |
||||
set_viewer("n:g:z:rdf_viewer:turtle"); |
||||
} |
||||
let results = undefined; |
||||
|
||||
</script> |
||||
<div class="flex-col"> |
||||
|
||||
<CodeMirror bind:value={$in_memory_discrete} lineWrapping useTab={false} extensions={[basicSetup,StreamLanguage.define(sparql)]} styles={{ |
||||
"&": { |
||||
maxWidth: "100%", |
||||
}, |
||||
}}/> |
||||
<Toggle class="mt-1 ml-2" bind:checked={union}>Query all docs</Toggle> |
||||
<button |
||||
on:click={run} |
||||
on:keypress={run} |
||||
class="select-none ml-2 mt-2 mb-10 text-white bg-primary-700 hover:bg-primary-700/90 focus:ring-4 focus:ring-primary-500/50 rounded-lg text-base p-2 text-center inline-flex items-center dark:focus:ring-primary-700/55" |
||||
> |
||||
<RocketLaunch tabindex="-1" class="mr-2 focus:outline-none" /> |
||||
Run Query |
||||
</button> |
||||
<button |
||||
on:click={openTurtle} |
||||
on:keypress={openTurtle} |
||||
class="select-none ml-2 mt-2 mb-10 text-gray-600 focus:ring-4 focus:ring-primary-500/50 rounded-lg text-base p-2 text-center inline-flex items-center dark:focus:ring-primary-700/55" |
||||
> |
||||
<Sun class="mr-2 focus:outline-none" tabindex="-1" /> |
||||
View Graph |
||||
</button> |
||||
{#if results!==undefined} |
||||
<div> |
||||
<span class="ml-2 font-bold">Results: <br/></span> |
||||
{#if Array.isArray(results)} |
||||
<Highlight {language} code={results.join(" .\r\n") + " ."} class="mb-10" let:highlighted > |
||||
<LineNumbers {highlighted} wrapLines hideBorder /> |
||||
</Highlight> |
||||
{:else if results?.head} |
||||
<Table> |
||||
<TableHead> |
||||
{#each results.head.vars as variable} |
||||
<TableHeadCell>{variable}</TableHeadCell> |
||||
{/each} |
||||
</TableHead> |
||||
<TableBody tableBodyClass="divide-y"> |
||||
{#each results.results.bindings as row} |
||||
<TableBodyRow> |
||||
{#each results.head.vars as variable} |
||||
<TableBodyCell class="px-6 py-4 whitespace-break-spaces font-medium">{row[variable].value}</TableBodyCell> |
||||
{/each} |
||||
</TableBodyRow> |
||||
{/each} |
||||
</TableBody> |
||||
</Table> |
||||
{:else} |
||||
<span class="ml-2">{results}</span> |
||||
{/if} |
||||
</div> |
||||
{/if} |
||||
</div> |
@ -0,0 +1,81 @@ |
||||
<!-- |
||||
// Copyright (c) 2022-2024 Niko Bonnieure, Par le Peuple, NextGraph.org developers |
||||
// All rights reserved. |
||||
// Licensed under the Apache License, Version 2.0 |
||||
// <LICENSE-APACHE2 or http://www.apache.org/licenses/LICENSE-2.0> |
||||
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>, |
||||
// at your option. All files in the project carrying such |
||||
// notice may not be copied, modified, or distributed except |
||||
// according to those terms. |
||||
--> |
||||
|
||||
<script lang="ts"> |
||||
import { onMount, tick, onDestroy } from "svelte"; |
||||
import { |
||||
sparql_update, |
||||
toast_error, |
||||
toast_success |
||||
} from "../store"; |
||||
import { |
||||
in_memory_discrete, open_viewer, set_viewer, set_editor, set_view_or_edit, cur_tab |
||||
} from "../tab"; |
||||
import{ PencilSquare, RocketLaunch } from "svelte-heros-v2"; |
||||
import { t } from "svelte-i18n"; |
||||
import { Button, Progressbar, Spinner, Alert } from "flowbite-svelte"; |
||||
|
||||
import Highlight, { LineNumbers } from "svelte-highlight"; |
||||
import hljs from "highlight.js"; |
||||
import { definer } from "../turtle"; |
||||
import "svelte-highlight/styles/github.css"; |
||||
const language = { |
||||
name: "turtle", |
||||
register: (hljs) => { |
||||
return definer(hljs); |
||||
}, |
||||
}; |
||||
|
||||
export let commits = {graph:[]}; |
||||
let source = ""; |
||||
$: source = commits.graph.join(" .\r\n") + " ."; |
||||
|
||||
const openQuery = () => { |
||||
set_viewer("n:g:z:sparql_query"); |
||||
} |
||||
const openUpdate = () => { |
||||
set_editor("n:g:z:sparql_update"); |
||||
set_view_or_edit(false); |
||||
} |
||||
|
||||
onMount(()=>{ |
||||
|
||||
}); |
||||
|
||||
</script> |
||||
<div class="flex-col"> |
||||
|
||||
<button |
||||
on:click={openQuery} |
||||
on:keypress={openQuery} |
||||
class="select-none ml-2 mt-2 mb-2 text-white bg-primary-700 hover:bg-primary-700/90 focus:ring-4 focus:ring-primary-500/50 rounded-lg text-base p-2 text-center inline-flex items-center dark:focus:ring-primary-700/55" |
||||
> |
||||
<RocketLaunch tabindex="-1" class="mr-2 focus:outline-none" /> |
||||
SPARQL Query |
||||
</button> |
||||
{#if $cur_tab.doc.can_edit} |
||||
<button |
||||
on:click={openUpdate} |
||||
on:keypress={openUpdate} |
||||
class="select-none ml-2 mt-2 text-gray-600 focus:ring-4 focus:ring-primary-500/50 rounded-lg text-base p-2 text-center inline-flex items-center dark:focus:ring-primary-700/55" |
||||
> |
||||
<PencilSquare class="mr-2 focus:outline-none" tabindex="-1" /> |
||||
SPARQL Update |
||||
</button> |
||||
{/if} |
||||
|
||||
<Highlight {language} code={source} class="mb-10" let:highlighted > |
||||
<LineNumbers {highlighted} wrapLines hideBorder /> |
||||
</Highlight> |
||||
|
||||
|
||||
</div> |
||||
|
@ -0,0 +1,139 @@ |
||||
/* |
||||
Language: Turtle |
||||
Author: Redmer KRONEMEIJER <redmer.kronemeijer@rdmr.eu> |
||||
Contributors: Mark ELLIS <mark.ellis@stardog.com>, Vladimir ALEXIEV <vladimir.alexiev@ontotext.com> |
||||
*/ |
||||
|
||||
|
||||
function hljsDefineTurtle(hljs) { |
||||
// export default function (hljs) {
|
||||
var KEYWORDS = { |
||||
keyword: "BASE|2 PREFIX|5 @base|10 @prefix|10", |
||||
literal: "true false", |
||||
built_in: "a", |
||||
}; |
||||
|
||||
var IRI_LITERAL = { |
||||
// https://www.w3.org/TR/turtle/#grammar-production-IRIREF
|
||||
className: "literal", |
||||
relevance: 1, // XML tags look also like relative IRIs
|
||||
begin: /</, |
||||
end: />/, |
||||
// illegal: /[^\x00-\x20"{}|^`\\]/, // TODO: https://www.w3.org/TR/turtle/#grammar-production-UCHAR
|
||||
}; |
||||
|
||||
// https://www.w3.org/TR/turtle/#terminals
|
||||
var PN_CHARS_BASE = |
||||
"A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u10000-\uEFFFF"; |
||||
var PN_CHARS_U = PN_CHARS_BASE + "_"; |
||||
var PN_CHARS = "-" + PN_CHARS_U + "0-9\u00B7\u0300-\u036F\u203F-\u2040"; |
||||
var BLANK_NODE_LABEL = |
||||
"_:[" + PN_CHARS_U + "0-9]([" + PN_CHARS + ".]*[" + PN_CHARS + "])?"; |
||||
var PN_PREFIX = |
||||
"[" + PN_CHARS_BASE + "]([" + PN_CHARS + ".]*[" + PN_CHARS + "])?"; |
||||
var PERCENT = "%[0-9A-Fa-f][0-9A-Fa-f]"; |
||||
var PN_LOCAL_ESC = "\\\\[_~.!$&'()*+,;=/?#@%-]"; |
||||
var PLX = PERCENT + "|" + PN_LOCAL_ESC; |
||||
var PNAME_NS = "(" + PN_PREFIX + ")?:"; |
||||
var PN_LOCAL = |
||||
"([" + |
||||
PN_CHARS_U + |
||||
":0-9]|" + |
||||
PLX + |
||||
")([" + |
||||
PN_CHARS + |
||||
".:]|" + |
||||
PLX + |
||||
")*([" + |
||||
PN_CHARS + |
||||
":]|" + |
||||
PLX + |
||||
")?"; |
||||
var PNAME_LN = PNAME_NS + PN_LOCAL; |
||||
var PNAME_NS_or_LN = PNAME_NS + "(" + PN_LOCAL + ")?"; |
||||
|
||||
var PNAME = { |
||||
begin: PNAME_NS_or_LN, |
||||
relevance: 0, |
||||
className: "symbol", |
||||
}; |
||||
|
||||
var BLANK_NODE = { |
||||
begin: BLANK_NODE_LABEL, |
||||
relevance: 10, |
||||
className: "template-variable", |
||||
}; |
||||
|
||||
var LANGTAG = { |
||||
begin: /@[a-zA-Z]+([a-zA-Z0-9-]+)*/, |
||||
className: "type", |
||||
relevance: 0, // also catches objectivec keywords like: @protocol, @optional
|
||||
}; |
||||
|
||||
var DATATYPE = { |
||||
begin: "\\^\\^" + PNAME_LN, |
||||
className: "type", |
||||
relevance: 10, |
||||
}; |
||||
|
||||
var TRIPLE_APOS_STRING = { |
||||
begin: /'''/, |
||||
end: /'''/, |
||||
className: "string", |
||||
relevance: 0, |
||||
}; |
||||
|
||||
var TRIPLE_QUOTE_STRING = { |
||||
begin: /"""/, |
||||
end: /"""/, |
||||
className: "string", |
||||
relevance: 0, |
||||
}; |
||||
|
||||
var APOS_STRING_LITERAL = JSON.parse(JSON.stringify(hljs.APOS_STRING_MODE)); |
||||
APOS_STRING_LITERAL.relevance = 0; |
||||
|
||||
var QUOTE_STRING_LITERAL = JSON.parse(JSON.stringify(hljs.QUOTE_STRING_MODE)); |
||||
QUOTE_STRING_LITERAL.relevance = 0; |
||||
|
||||
return { |
||||
name: "Turtle", |
||||
case_insensitive: true, // however `true` and `@prefix` are oblig. cased thus
|
||||
keywords: KEYWORDS, |
||||
aliases: ["turtle", "ttl", "n3"], |
||||
contains: [ |
||||
LANGTAG, |
||||
DATATYPE, |
||||
IRI_LITERAL, |
||||
BLANK_NODE, |
||||
PNAME, |
||||
TRIPLE_APOS_STRING, |
||||
TRIPLE_QUOTE_STRING, // order matters
|
||||
APOS_STRING_LITERAL, |
||||
QUOTE_STRING_LITERAL, |
||||
hljs.C_NUMBER_MODE, |
||||
hljs.HASH_COMMENT_MODE, |
||||
], |
||||
exports: { |
||||
LANGTAG: LANGTAG, |
||||
DATATYPE: DATATYPE, |
||||
IRI_LITERAL: IRI_LITERAL, |
||||
BLANK_NODE: BLANK_NODE, |
||||
PNAME: PNAME, |
||||
TRIPLE_APOS_STRING: TRIPLE_APOS_STRING, |
||||
TRIPLE_QUOTE_STRING: TRIPLE_QUOTE_STRING, |
||||
APOS_STRING_LITERAL: APOS_STRING_LITERAL, |
||||
QUOTE_STRING_LITERAL: QUOTE_STRING_LITERAL, |
||||
NUMBER: hljs.C_NUMBER_MODE, |
||||
KEYWORDS: KEYWORDS, |
||||
}, |
||||
}; |
||||
} |
||||
|
||||
// module.exports = function (hljs) {
|
||||
// hljs.registerLanguage("turtle", hljsDefineTurtle);
|
||||
// };
|
||||
|
||||
// module.exports.definer = hljsDefineTurtle;
|
||||
|
||||
export const definer = hljsDefineTurtle; |
Loading…
Reference in new issue