Skip to content

Commit

Permalink
#151 avoid using import type keyword for now
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurensRietveld committed Mar 10, 2020
1 parent 5e5a12a commit 83e8e3d
Show file tree
Hide file tree
Showing 23 changed files with 210 additions and 223 deletions.
27 changes: 12 additions & 15 deletions packages/yasgui/src/Tab.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EventEmitter } from "events";
import { addClass, removeClass, getAsValue } from "@triply/yasgui-utils";
import type { TabListEl } from "./TabElements";
import { TabListEl } from "./TabElements";
import TabPanel from "./TabPanel";
import { default as Yasqe, RequestConfig, PlainRequestConfig, Config as YasqeConfig } from "@triply/yasqe";
import { default as Yasr, Parser, Config as YasrConfig, PersistentConfig as YasrPersistentConfig } from "@triply/yasr";
Expand Down Expand Up @@ -72,7 +72,7 @@ export class Tab extends EventEmitter {
return this.persistentJson.id;
}
private draw() {
if (this.rootEl) return;//aready drawn
if (this.rootEl) return; //aready drawn
this.rootEl = document.createElement("div");
this.rootEl.className = "tabPanel";
const wrapper = document.createElement("div");
Expand Down Expand Up @@ -171,14 +171,13 @@ export class Tab extends EventEmitter {
}

private initEndpointSelectField() {
if ( !this.controlBarEl)
throw new Error("Need to initialize wrapper elements before drawing endpoint field");
const endpointSelect = this.endpointSelect = new EndpointSelect(
if (!this.controlBarEl) throw new Error("Need to initialize wrapper elements before drawing endpoint field");
const endpointSelect = (this.endpointSelect = new EndpointSelect(
this.getEndpoint(),
this.controlBarEl,
this.yasgui.config.endpointCatalogueOptions,
this.yasgui.persistentConfig.getEndpointHistory()
);
));
endpointSelect.on("select", (endpoint, endpointHistory) => {
this.setEndpoint(endpoint, endpointHistory);
});
Expand Down Expand Up @@ -254,7 +253,7 @@ export class Tab extends EventEmitter {
return this.persistentJson.name;
}
public query(): Promise<any> {
if (!this.yasqe) return Promise.reject(new Error("No yasqe editor initialized"))
if (!this.yasqe) return Promise.reject(new Error("No yasqe editor initialized"));
return this.yasqe.query();
}
public setRequestConfig(requestConfig: Partial<RequestConfig<Yasgui>>) {
Expand Down Expand Up @@ -331,15 +330,15 @@ export class Tab extends EventEmitter {
yasqeConf.hintConfig.container = this.yasgui.rootEl;
}
if (!this.yasqeWrapperEl) {
throw new Error("Expected a wrapper element before instantiating yasqe")
throw new Error("Expected a wrapper element before instantiating yasqe");
}
this.yasqe = new Yasqe(this.yasqeWrapperEl, yasqeConf);

this.yasqe.on("blur", yasqe => {
this.persistentJson.yasqe.value = yasqe.getValue();
this.emit("change", this, this.persistentJson);
});
this.yasqe.on("query", (yasqe) => {
this.yasqe.on("query", yasqe => {
//the blur event might not have fired (e.g. when pressing ctrl-enter). So, we'd like to persist the query as well if needed
if (yasqe.getValue() !== this.persistentJson.yasqe.value) {
this.persistentJson.yasqe.value = yasqe.getValue();
Expand All @@ -364,9 +363,9 @@ export class Tab extends EventEmitter {

this.yasqe.on("queryResponse", (_yasqe: Yasqe, response: any, duration: number) => {
this.emit("queryResponse", this);
if (!this.yasr) throw new Error("Resultset visualizer not initialized. Cannot draw results")
if (!this.yasr) throw new Error("Resultset visualizer not initialized. Cannot draw results");
this.yasr.setResponse(response, duration);
if (!this.yasr.results) return
if (!this.yasr.results) return;
if (!this.yasr.results.hasError()) {
this.persistentJson.yasr.response = this.yasr.results.getAsStoreObject(
this.yasgui.config.yasr.maxPersistentResponseSize
Expand All @@ -386,18 +385,17 @@ export class Tab extends EventEmitter {
});
}
private initYasr() {
if (!this.yasrWrapperEl) throw new Error('Wrapper for yasr does not exist')
if (!this.yasrWrapperEl) throw new Error("Wrapper for yasr does not exist");
const yasrConf: Partial<YasrConfig> = {
persistenceId: null, //yasgui handles persistent storing
prefixes: () => this.yasqe?.getPrefixesFromQuery() || {},
defaultPlugin: this.persistentJson.yasr.settings.selectedPlugin,
getPlainQueryLinkToEndpoint: () => {
if (this.yasqe) {

return shareLink.appendArgsToUrl(
this.getEndpoint(),
Yasqe.Sparql.getUrlArguments(this.yasqe, this.persistentJson.requestConfig as RequestConfig<any>)
)
);
}
},
plugins: mapValues(this.persistentJson.yasr.settings.pluginsConfig, conf => ({
Expand Down Expand Up @@ -436,7 +434,6 @@ export class Tab extends EventEmitter {
this.persistentJson.yasr.settings = this.yasr.getPersistentConfig();
this.yasr.on("change", () => {
if (this.yasr) {

this.persistentJson.yasr.settings = this.yasr.getPersistentConfig();
}

Expand Down
8 changes: 4 additions & 4 deletions packages/yasgui/src/TabContextMenu.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { addClass } from "@triply/yasgui-utils";
import { default as Yasgui, getRandomId } from "./";
import type Tab from './Tab'
import type { TabListEl } from "./TabElements";
import Tab from "./Tab";
import { TabListEl } from "./TabElements";
import { cloneDeep } from "lodash-es";
require("./TabContextMenu.scss");
export interface TabContextConfig {
Expand Down Expand Up @@ -79,7 +79,7 @@ export default class TabContextMenu {
rootEl.appendChild(this.contextEl);
}
public redraw() {
if (this.contextEl && this.tabRef?.tabEl) {
if (this.contextEl && this.tabRef?.tabEl) {
const bounding = this.tabRef.tabEl.getBoundingClientRect();
this.contextEl.style.top = `${window.pageYOffset + bounding.bottom}px`;
}
Expand All @@ -100,7 +100,7 @@ export default class TabContextMenu {

// Copy tab functionality`
this.copyTabEl.onclick = () => {
if (!tab) return
if (!tab) return;
const config = cloneDeep(tab.getPersistedJson());
config.id = getRandomId();
this.yasgui.addTab(true, config);
Expand Down
8 changes: 3 additions & 5 deletions packages/yasgui/src/TabElements.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type Yasgui from "./";
import Yasgui from "./";
import TabContextMenu from "./TabContextMenu";
import { hasClass, addClass, removeClass } from "@triply/yasgui-utils";
const sortablejs = require("sortablejs");
Expand All @@ -24,9 +24,8 @@ export class TabListEl {
}
public startRename() {
if (this.renameEl) {
const tab = this.yasgui.getTab(this.tabId)
const tab = this.yasgui.getTab(this.tabId);
if (tab) {

this.renameEl.value = tab.name();
addClass(this.tabEl, "renaming");
this.renameEl.focus();
Expand Down Expand Up @@ -87,7 +86,7 @@ export class TabListEl {
};
tabLinkEl.appendChild(closeBtn);

const renameEl = this.renameEl = document.createElement("input");
const renameEl = (this.renameEl = document.createElement("input"));
renameEl.type = "text";
renameEl.value = name;
renameEl.onkeyup = event => {
Expand Down Expand Up @@ -213,7 +212,6 @@ export class TabList {
public deriveTabOrderFromEls() {
const tabs: string[] = [];
if (this._tabsListEl) {

for (let i = 0; i < this._tabsListEl.children.length; i++) {
const child = this._tabsListEl.children[i]; //this is the tab div
const anchorTag = child.children[0]; //this one has an href
Expand Down
Loading

0 comments on commit 83e8e3d

Please sign in to comment.