Commit f0a94193 authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Export browser extension as external package

parent 95f8c7e4ac26
......@@ -9,8 +9,16 @@ echo "=========================================="
(cd "$ROOT/rdflib-types"; npm install)
(cd "$ROOT/rdflib-types"; npm run build)
echo ""
echo "=========================================="
echo "= Building @logilab/libview"
echo "=========================================="
(cd "$ROOT/libview"; npm install)
(cd "$ROOT/libview"; npm run build)
\ No newline at end of file
(cd "$ROOT/libview"; npm run build)
echo ""
echo "=========================================="
echo "= Building @logilab/ld-browser"
echo "=========================================="
(cd "$ROOT/extension"; npm install)
(cd "$ROOT/extension"; npm run build)
\ No newline at end of file
{
"name": "cubicweb-generic-client",
"name": "@logilab/ld-browser",
"version": "0.1.0",
"description": "A browser for the web of data.",
"scripts": {
......@@ -14,19 +14,21 @@
"url": "https://bitbucket.org/laurentw/logilab-cubicweb-client"
},
"keywords": [
"BuckleScript"
"DataBrowser",
"Typescript"
],
"author": "LOGILAB <contact@logilab.fr>",
"license": "LGPL-3.0",
"dependencies": {
"@logilab/libview": "file:../libview",
"@types/chrome": "0.0.69",
"@types/rdflib": "file:../rdflib-types",
"@types/react": "^16.4.6",
"@types/react-dom": "^16.0.6",
"@types/react-router": "^4.0.28",
"@types/react-router-dom": "^4.2.7",
"bootstrap": "^4.1.1",
"jquery": "^1.12.4",
"libview": "file:../libview",
"popper.js": "^1.14.3",
"rdflib": "^0.17.0",
"react": "^16.2.0",
......
......@@ -18,6 +18,7 @@
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
import { definition } from "@logilab/libview";
import {
NO_DATA,
MIME,
......@@ -34,7 +35,6 @@ import { Message } from "../common/messages";
/// <reference path="./fallback.d.ts"/>
let F = require("./fallback");
import "chrome";
import { ViewRegistry, loadDescriptors } from "../common/view-registry";
import { DEFAULTS_SOURCE } from "../common/view-defaults";
/**
......@@ -45,7 +45,7 @@ let allTabs: { [index: number]: TabData } = {};
/**
* The reference view registry
*/
let registry: ViewRegistry = new ViewRegistry();
let registry: definition.ViewRegistry = new definition.ViewRegistry();
registry.sources.push(DEFAULTS_SOURCE);
/**
......@@ -395,4 +395,4 @@ chrome.runtime.onMessage.addListener(
}
);
loadDescriptors(registry);
definition.loadRegistry(registry);
......@@ -19,8 +19,6 @@
******************************************************************************/
import { RawContent, TabData, fetchSource } from "./data";
/// <reference path="./rdflib-interface.d.ts"/>
import { RDF, RdfStore, Term } from "rdflib";
let _rdf = require("rdflib");
......
/*******************************************************************************
* Copyright 2003-2018 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
* contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
*
* This file is part of CubicWeb.
*
* CubicWeb is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 2.1 of the License, or (at your option)
* any later version.
*
* CubicWeb is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/**
* RDF stubs for Typescript
*/
declare module "rdflib" {
export interface Term {
termType: string;
value: string;
equals(other: Term): boolean;
}
export interface NamedNode extends Term {
uri: string;
}
export interface BlankNode extends Term {
id: string;
}
export interface Literal extends Term {
language: string;
datatype: NamedNode;
}
export interface Variable extends Term {}
export interface DefaultGraph extends Term {}
export type SubjectNode = NamedNode | BlankNode;
export interface Quad {
subject: SubjectNode;
predicate: NamedNode;
object: Term;
graph: NamedNode;
why: NamedNode;
equals(other: Quad): boolean;
}
export interface Triple extends Quad {}
export interface RdfStore {
statements: Triple[];
add(
subject: SubjectNode,
predicate: NamedNode,
object: Term,
why: NamedNode
): void;
any(
subject: SubjectNode,
predicate: NamedNode,
object: Term,
why: NamedNode
): Term;
each(
subject: SubjectNode,
predicate: NamedNode,
object: Term,
why: NamedNode
): Term[];
}
export type Namespace = (fragment: string) => NamedNode;
export interface RDF {
graph(): RdfStore;
parse(
input: string,
store: RdfStore,
origin: string,
contentType: string
): void;
sym(iri: string): NamedNode;
bnode(): BlankNode;
literal(value: string): Literal;
literal(value: string, language: string): Literal;
literal(value: string, language: string, datatype: NamedNode): Literal;
Namespace(iriRadical: string): Namespace;
}
let $rdf: RDF;
export default $rdf;
}
......@@ -18,20 +18,17 @@
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/// <reference path="./rdflib-interface.d.ts"/>
import { RdfStore, Triple, Term, NamedNode, BlankNode, Literal } from "rdflib";
import * as React from "react";
import { ViewDescriptor } from "./view-registry";
import { ViewImplementation, registerImplementation } from "./view-impl";
import { definition, application, implementation } from "@logilab/libview";
import {
DEFAULT_DESCRIPTOR_TRIPLES,
DEFAULT_DESCRIPTOR_DBPEDIA_PERSON
} from "./view-defaults";
import { $rdf, getValueOf } from "./rdf";
import { ViewRenderer } from "./application";
export class RdfTriplesRendering implements ViewImplementation {
descriptor: ViewDescriptor;
export class RdfTriplesRendering implements implementation.ViewImplementation {
descriptor: definition.ViewDescriptor;
constructor() {
this.descriptor = DEFAULT_DESCRIPTOR_TRIPLES;
......@@ -44,7 +41,7 @@ export class RdfTriplesRendering implements ViewImplementation {
}
render(
renderer: ViewRenderer,
renderer: application.ViewRenderer,
store: RdfStore,
root: string,
target: string
......@@ -142,8 +139,9 @@ function hasTraitDbPediaPerson(store: RdfStore, primaryTopic: string): boolean {
return a != null && a != undefined && a.length > 0;
}
export class DBPediaPersonRendering implements ViewImplementation {
descriptor: ViewDescriptor;
export class DBPediaPersonRendering
implements implementation.ViewImplementation {
descriptor: definition.ViewDescriptor;
constructor() {
this.descriptor = DEFAULT_DESCRIPTOR_DBPEDIA_PERSON;
this.priorityFor = this.priorityFor.bind(this);
......@@ -155,7 +153,7 @@ export class DBPediaPersonRendering implements ViewImplementation {
}
render(
renderer: ViewRenderer,
renderer: application.ViewRenderer,
store: RdfStore,
root: string,
target: string
......@@ -193,5 +191,5 @@ export class DBPediaPersonRendering implements ViewImplementation {
/**
* Registers the views
*/
registerImplementation(new RdfTriplesRendering());
registerImplementation(new DBPediaPersonRendering());
implementation.registerImplementation(new RdfTriplesRendering());
implementation.registerImplementation(new DBPediaPersonRendering());
......@@ -18,46 +18,39 @@
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
import {} from "libview";
/*import {
ViewRegistrySourceInline,
ViewRegistrySourceKind,
ViewLocationKind,
ViewDescriptor
} from "libview";*/
import { definition } from "@logilab/libview";
/**
* The decsriptor for the default Rdf triples view
*/
export const DEFAULT_DESCRIPTOR_TRIPLES: ViewDescriptor = {
export const DEFAULT_DESCRIPTOR_TRIPLES: definition.ViewDescriptor = {
identifier: "::Defaults::Triples",
name: "RDF Triples",
description: "Renders a complete RDF dataset using the N-Triples syntax",
entrypoint: "VIEW_DEFAULTS_TRIPLES",
location: {
kind: ViewLocationKind.Embedded
kind: definition.ViewLocationKind.Embedded
}
};
/**
* The descritptor for the default Dbpedia person view
*/
export const DEFAULT_DESCRIPTOR_DBPEDIA_PERSON: ViewDescriptor = {
export const DEFAULT_DESCRIPTOR_DBPEDIA_PERSON: definition.ViewDescriptor = {
identifier: "::Defaults::DbPediaPerson",
name: "DbPedia Person",
description: "Renders a person from DbPedia",
entrypoint: "VIEW_DEFAULTS_DBPEDIA_PERSON",
location: {
kind: ViewLocationKind.Embedded
kind: definition.ViewLocationKind.Embedded
}
};
/**
* The source for the default views
*/
export const DEFAULTS_SOURCE: ViewRegistrySourceInline = {
export const DEFAULTS_SOURCE: definition.ViewRegistrySourceInline = {
name: "Source of default views",
kind: ViewRegistrySourceKind.Inlined,
kind: definition.ViewRegistrySourceKind.Inlined,
descriptors: [DEFAULT_DESCRIPTOR_TRIPLES, DEFAULT_DESCRIPTOR_DBPEDIA_PERSON]
};
......@@ -18,10 +18,9 @@
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
/// <reference path="../common/rdflib-interface.d.ts"/>
import { RdfStore } from "rdflib";
import { Application, ViewRenderer } from "../common/application";
import * as React from "react";
import { application } from "@logilab/libview";
enum StateType {
Loading,
......@@ -35,14 +34,15 @@ class State {
root: string;
}
export class Viewer extends React.Component<any, State> implements Application {
export class Viewer extends React.Component<any, State>
implements application.Application {
state: State = {
stateType: StateType.Loading,
message: "Loading",
content: null,
root: null
};
renderer: ViewRenderer = null;
renderer: application.ViewRenderer = null;
constructor(props: any) {
super(props);
......@@ -56,7 +56,7 @@ export class Viewer extends React.Component<any, State> implements Application {
* @param root The URI of the root resource
*/
public onContent(
renderer: ViewRenderer,
renderer: application.ViewRenderer,
content: RdfStore,
root: string
): void {
......
......@@ -18,7 +18,6 @@
* with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
import { Application, ViewRenderer } from "../common/application";
import { TabData, Link, NO_DATA } from "../common/data";
import { Message } from "../common/messages";
import { loadRdfStore } from "../common/rdf";
......@@ -26,14 +25,13 @@ import { Viewer } from "./app-viewer";
import * as React from "react";
import * as ReactDOM from "react-dom";
import "chrome";
import { ViewRegistry } from "../common/view-registry";
import { newRenderer } from "../common/view-impl";
import { application, definition, implementation } from "@logilab/libview";
require("../common/view-defaults-impl");
/**
* The current application
*/
let currentApp: Application = null;
let currentApp: application.Application = null;
/**
* Reacts to the deactivation
......@@ -56,10 +54,12 @@ function onUpdateActivate(tabData: TabData): void {
senderId: "content",
payload: null
},
(registry: ViewRegistry) => {
newRenderer(currentApp, registry).then((renderer: ViewRenderer) => {
currentApp.onContent(renderer, store, tabData.primaryTopic);
});
(registry: definition.ViewRegistry) => {
implementation
.newRenderer(currentApp, registry)
.then((renderer: application.ViewRenderer) => {
currentApp.onContent(renderer, store, tabData.primaryTopic);
});
}
);
})
......@@ -150,7 +150,7 @@ function injectApplication() {
document.body.insertBefore(appContent, document.body.firstChild);
let viewer = <Viewer />;
let x = ReactDOM.render(viewer, document.getElementById(ID));
currentApp = (x as Viewer) as Application;
currentApp = (x as Viewer) as application.Application;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment