ontola / link-devtools Goto Github PK
View Code? Open in Web Editor NEWBrowser console debugging features for Link-Redux projects.
License: GNU General Public License v3.0
Browser console debugging features for Link-Redux projects.
License: GNU General Public License v3.0
See the extension branch for current progress.
Opening the devtools, going to the react tab, finding the right LinkedResourceContainer in the tree, going back to the console, and typing dev.data
is a bit bothersome.
As a developer, I'd love to get that data using a keyboard shortcut and clicking on a component.
In one project, I created something that does this called the HoverHelper. Hold Alt to make the Subjects light up, click to show the data in the console. It uses HTML RDFa attributes to find the subject, and then uses link to fetch the relevant data.
Here's the code:
import PropTypes from 'prop-types';
import { NamedNode } from 'rdflib';
import React, { Component } from 'react';
import { HotKeys } from 'react-hotkeys';
import { expandPath } from '../../helpers/iris';
const propTypes = {
children: PropTypes.node,
};
const TRIGGER_KEYS = ['Alt', 'AltGraph'];
class HoverHelper extends Component {
constructor(props) {
super(props);
this.state = {
activated: false,
};
}
static getElement(e) {
e.preventDefault();
e.stopPropagation();
e.nativeEvent.stopImmediatePropagation();
const x = e.clientX;
const y = e.clientY;
const elementMouseIsOver = document.elementFromPoint(x, y);
let currentElement = elementMouseIsOver;
const maxDepth = 100;
for (let i = 0; i < maxDepth; i++) {
const resourceLink = currentElement.getAttribute('resource')
|| expandPath(currentElement.getAttribute('href'));
if (resourceLink) {
/* global dev:true */
const trips = dev.getLRS().tryEntity(NamedNode.find(resourceLink));
console.log(dev.toObject(trips)); // eslint-disable-line no-console
break;
}
if (currentElement.tagName === 'BODY') {
console.log('Nothing found!'); // eslint-disable-line no-console
break;
}
currentElement = currentElement.parentElement;
}
}
handleKeyDown(e) {
if (e.key === TRIGGER_KEYS) {
this.setState({
activated: true,
});
}
}
handleKeyUp(e) {
if (e.key === TRIGGER_KEYS) {
this.setState({
activated: false,
});
}
}
render() {
if (!__DEVELOPMENT__) {
return this.props.children;
}
const listeners = this.state.activated ? { onClick: e => HoverHelper.getElement(e) } : {};
const handlers = {
startHoverHelper: () => this.setState({
activated: true,
}),
stopHoverHelper: () => this.setState({
activated: false,
}),
};
return (
<HotKeys
handlers={handlers}
tabIndex={null}
>
<div
className={`${this.state.activated ? 'HoverHelper--show-borders' : ''}`}
{...listeners}
>
{this.props.children}
</div>
</HotKeys>
);
}
}
HoverHelper.propTypes = propTypes;
export default HoverHelper;
And the styles:
.HoverHelper--show-borders {
& [resource],
& [href] {
box-shadow: 0 0 1px 0 $focus-red;
// sass-lint:disable no-important
pointer-events: all !important;
&:hover {
box-shadow: 0 0 3px 2px $focus-red;
z-index: 1;
}
&:active {
box-shadow: 0 0 5px 3px $focus-red;
z-index: 1;
}
}
& *:not([resource]) {
pointer-events: none;
}
}
Perhaps something similar to this could be useful for this repo.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.