Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ import react from 'eslint-plugin-react';

export default tseslint.config(
eslint.configs.recommended,
tseslint.configs.recommended,
tseslint.configs.recommendedTypeChecked,
react.configs.flat.recommended,
react.configs.flat['jsx-runtime'],
{
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ['*.js', '*.mjs', 'vitest.config.mts'],
},
tsconfigRootDir: import.meta.dirname,
},
},
},
{
ignores: ['dist/'],
},
Expand Down Expand Up @@ -35,6 +45,9 @@ export default tseslint.config(
'no-control-regex': 'off',
'quotes': ['warn', 'single'],
'semi': ['warn', 'always'],
'@typescript-eslint/no-misused-promises': ['warn', {
checksVoidReturn: false,
}],
'@typescript-eslint/no-empty-object-type': ['warn', {
allowInterfaces: 'with-single-extends',
allowWithName: 'Props$',
Expand All @@ -46,6 +59,10 @@ export default tseslint.config(
}],
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/prefer-promise-reject-errors': 'off',
'@typescript-eslint/unbound-method': ['warn', {
ignoreStatic: true,
}],
},
},
{
Expand All @@ -69,6 +86,8 @@ export default tseslint.config(
SwitchCase: 1,
}],
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
},
}
);
2 changes: 1 addition & 1 deletion examples/classicWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function ClassicWorkspaceExample() {
}

const diagram = tryLoadLayoutFromLocalStorage();
model.importLayout({
await model.importLayout({
diagram,
dataProvider,
validateLinks: true,
Expand Down
2 changes: 1 addition & 1 deletion examples/i18n.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as Reactodia from '../src/workspace';

import { ExampleToolbarMenu, mountOnLoad, tryLoadLayoutFromLocalStorage } from './resources/common';

const TURTLE_DATA = require('./resources/orgOntology.ttl');
const TURTLE_DATA = require('./resources/orgOntology.ttl') as string;

const Layouts = Reactodia.defineLayoutWorker(() => new Worker('layout.worker.js'));

Expand Down
6 changes: 4 additions & 2 deletions examples/resources/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function ExampleToolbarMenu() {
const task = overlay.startTask({title: 'Importing a layout from file'});
try {
const json = await file.text();
const diagramLayout = JSON.parse(json);
const diagramLayout = JSON.parse(json) as Reactodia.SerializedDiagram;
await model.importLayout({
dataProvider: model.dataProvider,
diagram: diagramLayout,
Expand Down Expand Up @@ -136,7 +136,9 @@ export function tryLoadLayoutFromLocalStorage(): Reactodia.SerializedDiagram | u
if (layoutKey) {
try {
const unparsedLayout = localStorage.getItem(layoutKey);
const entry = unparsedLayout && JSON.parse(unparsedLayout);
const entry = unparsedLayout
? JSON.parse(unparsedLayout) as Reactodia.SerializedDiagram
: undefined;
return entry;
} catch (e) {
/* ignore */
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/exampleMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ type Vocabulary<Keys extends string[]> = {
};

function vocabulary<const Keys extends string[]>(prefix: string, keys: Keys): Vocabulary<Keys> {
const result: { [key: string]: string } = Object.create(null);
const result = Object.create(null) as { [key: string]: string };
for (const key of keys) {
result[key] = prefix + key;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/sparql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function SparqlExample() {
imagePropertyUris: ['http://xmlns.com/foaf/0.1/img'],
}, Reactodia.OwlStatsSettings);

model.importLayout({
await model.importLayout({
diagram,
dataProvider: dataProvider,
validateLinks: true,
Expand Down
2 changes: 1 addition & 1 deletion examples/stressTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function StressTestExample() {
const canvas = view.findAnyCanvas();
if (canvas) {
canvas.renderingState.syncUpdate();
canvas.zoomToFit();
await canvas.zoomToFit();
}
}
}, []);
Expand Down
6 changes: 3 additions & 3 deletions examples/styleCustomization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import * as Reactodia from '../src/workspace';

import { ExampleToolbarMenu, mountOnLoad, tryLoadLayoutFromLocalStorage } from './resources/common';

const BOOK_ICON = require('@vscode/codicons/src/icons/book.svg');
const CERTIFICATE_ICON = require('@vscode/codicons/src/icons/symbol-class.svg');
const COG_ICON = require('@vscode/codicons/src/icons/gear.svg');
const BOOK_ICON = require('@vscode/codicons/src/icons/book.svg') as string;
const CERTIFICATE_ICON = require('@vscode/codicons/src/icons/symbol-class.svg') as string;
const COG_ICON = require('@vscode/codicons/src/icons/gear.svg') as string;

const EXAMPLE_DIAGRAM = require('./resources/exampleDiagram.json') as Reactodia.SerializedDiagram;
const TURTLE_DATA = require('./resources/orgOntology.ttl') as string;
Expand Down
4 changes: 2 additions & 2 deletions examples/wikidata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ function WikidataExample() {
<ExampleToolbarMenu />
<Reactodia.ToolbarAction
title='Clear locally-cached data previously fetched from Wikidata'
onSelect={() => {
onSelect={async () => {
const {model: {dataProvider}} = getContext();
if (dataProvider instanceof Reactodia.IndexedDbCachedProvider) {
dataProvider.clearCache();
await dataProvider.clearCache();
}
}}>
Clear Wikidata cache
Expand Down
2 changes: 1 addition & 1 deletion src/coreUtils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class EventSource<Data> implements Events<Data>, EventTrigger<Data> {

if (this.anyListeners) {
for (const anyListener of this.anyListeners) {
anyListener({[eventKey]: data} as any);
anyListener({[eventKey]: data} as unknown as Partial<Data>);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/coreUtils/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
* @category Utilities
*/
export class Debouncer {
// TODO: fix
private scheduled: any;
private scheduled: number | undefined;

private _timeout: number | 'frame';
private callback: (() => void) | undefined;
Expand Down Expand Up @@ -38,7 +37,7 @@ export class Debouncer {
if (this.timeout === 'frame') {
this.scheduled = requestAnimationFrame(this.runSynchronously);
} else {
this.scheduled = setTimeout(this.runSynchronously, this.timeout);
this.scheduled = setTimeout(this.runSynchronously, this.timeout) as unknown as number;
}
}
}
Expand All @@ -48,12 +47,12 @@ export class Debouncer {
callback?.();
}

runSynchronously() {
runSynchronously = () => {
const wasScheduled = this.cancelScheduledTimeout();
if (wasScheduled) {
this.run();
}
}
};

dispose() {
this.cancelScheduledTimeout();
Expand Down
9 changes: 5 additions & 4 deletions src/data/indexedDb/indexedDbCachedProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export class IndexedDbCachedProvider implements DataProvider {

private onClose = async () => {
this.closeSignal.removeEventListener('abort', this.onClose);
this.closeDatabase();
await this.closeDatabase();
};

private async closeDatabase(): Promise<void> {
Expand Down Expand Up @@ -410,7 +410,7 @@ export class IndexedDbCachedProvider implements DataProvider {
const lock = await this.linkLock.acquire();
try {
const ranges = await this.readLinkRanges(db, request);
const blocks = await this.selectMissingLinkBlocks(request, ranges);
const blocks = this.selectMissingLinkBlocks(request, ranges);
if (blocks.length > 0) {
await this.fetchAndCacheLinks(db, blocks, params.signal);
await this.updateLinkRanges(db, ranges, request);
Expand Down Expand Up @@ -799,7 +799,8 @@ async function fetchSingleWithDbCache<K extends IDBValidKey, V>(
{
const readTx = db.transaction(storeName, 'readonly');
const readStore = readTx.objectStore(storeName);
const cached: V | undefined = await indexedDbRequestAsPromise(
const cached = await indexedDbRequestAsPromise<V | undefined>(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
readStore.get(key)
);
readTx.commit();
Expand Down Expand Up @@ -1068,7 +1069,7 @@ function indexedDbSilentAbort(tx: IDBTransaction): void {
}

function serializeForDb<T>(value: T): T {
return JSON.parse(JSON.stringify(value));
return JSON.parse(JSON.stringify(value)) as T;
}

function isMissingRecord<K extends string>(value: { readonly id: K }): value is MissingRecord<K> {
Expand Down
11 changes: 8 additions & 3 deletions src/data/sparql/responseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ interface MutableElementModel {

export function getElementsInfo(
response: SparqlResponse<ElementBinding>,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
types: ReadonlyMap<ElementIri, ReadonlySet<ElementTypeIri>> = EMPTY_MAP,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
propertyByPredicate: ReadonlyMap<string, readonly PropertyConfiguration[]> = EMPTY_MAP,
labelPredicate: PropertyTypeIri,
openWorldProperties: boolean
Expand Down Expand Up @@ -316,7 +318,9 @@ interface MutableLinkModel {

export function getLinksInfo(
bindings: ReadonlyArray<LinkBinding>,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
types: ReadonlyMap<ElementIri, ReadonlySet<ElementTypeIri>> = EMPTY_MAP,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
linkByPredicateType: ReadonlyMap<string, readonly LinkConfiguration[]> = EMPTY_MAP,
openWorldLinks: boolean = true
): LinkModel[] {
Expand Down Expand Up @@ -365,6 +369,7 @@ export interface ConnectedLinkType {

export function getConnectedLinkTypes(
response: SparqlResponse<ConnectedLinkTypeBinding>,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
linkByPredicateType: ReadonlyMap<string, readonly LinkConfiguration[]> = EMPTY_MAP,
openWorldLinks: boolean = true
): ConnectedLinkType[] {
Expand Down Expand Up @@ -419,7 +424,7 @@ export function getFilteredData(
labelPredicate: PropertyTypeIri,
openWorldLinks: boolean
): DataProviderLookupItem[] {
const predicateToConfig = linkByPredicateType ?? EMPTY_MAP;
const predicateToConfig: typeof linkByPredicateType = linkByPredicateType ?? EMPTY_MAP;

const instances = new Map<ElementIri, MutableElementModel>();
const resultTypes = new Map<ElementIri, Set<ElementTypeIri>>();
Expand Down Expand Up @@ -466,13 +471,13 @@ export function getFilteredData(
model.types.sort();
const outLinks = new Set(translateLinkPredicates(
sourceTypes,
outPredicates.get(model.id) ?? EMPTY_SET,
outPredicates.get(model.id) ?? (EMPTY_SET as ReadonlySet<string>),
predicateToConfig,
openWorldLinks
));
const inLinks = new Set(translateLinkPredicates(
targetTypes,
inPredicates.get(model.id) ?? EMPTY_SET,
inPredicates.get(model.id) ?? (EMPTY_SET as ReadonlySet<string>),
predicateToConfig,
openWorldLinks
));
Expand Down
8 changes: 4 additions & 4 deletions src/data/sparql/sparqlDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1160,11 +1160,11 @@ async function executeSparqlQuery<Binding>(
}
const response = await internalQuery;
if (response.ok) {
const sparqlResponse: SparqlResponse<Binding> = await response.json();
const sparqlResponse = await response.json() as SparqlResponse<Binding>;
return mapSparqlResponseIntoRdfJs(sparqlResponse, factory);
} else {
const error = new Error(response.statusText);
(error as any).response = response;
(error as { response?: Response }).response = response;
throw error;
}
}
Expand Down Expand Up @@ -1205,7 +1205,7 @@ async function executeSparqlConstruct(
return parser.parse(turtleText);
} else {
const error = new Error(response.statusText);
(error as any).response = response;
(error as { response?: Response }).response = response;
throw error;
}
}
Expand All @@ -1221,7 +1221,7 @@ function appendQueryParams(endpoint: string, queryParams: { [key: string]: strin
function queryInternal(params: {
url: string;
body?: string;
headers: any;
headers: { [header: string]: string };
method: string;
signal?: AbortSignal;
}) {
Expand Down
2 changes: 1 addition & 1 deletion src/diagram/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export function restoreViewport(canvas: CanvasApi): Command {
return {center, scale};
}
function apply({center, scale}: CapturedViewport): void {
canvas.centerTo(center, {scale});
void canvas.centerTo(center, {scale});
}
const initialViewport = capture();
const command = Command.create(TranslatedText.text('commands.restore_viewport.title'), () => {
Expand Down
4 changes: 3 additions & 1 deletion src/diagram/elementLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class ElementLayer extends React.Component<ElementLayerProps, State> {
}

private requestRedraw = (element: Element, request: RedrawFlags) => {
const flagsWithForAll = this.redrawBatch.forAll | request;
const flagsWithForAll: RedrawFlags = this.redrawBatch.forAll | request;
if (flagsWithForAll === this.redrawBatch.forAll) {
// forAll flags already include the request
return;
Expand Down Expand Up @@ -254,9 +254,11 @@ function applyRedrawRequests(
state = {
element,
templateProps:
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
(request & RedrawFlags.RecomputeTemplate) === RedrawFlags.RecomputeTemplate
? computeTemplateProps(state.element) : state.templateProps,
blurred:
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
(request & RedrawFlags.RecomputeBlurred) === RedrawFlags.RecomputeBlurred
? computeIsBlurred(state.element, view) : state.blurred,
};
Expand Down
4 changes: 2 additions & 2 deletions src/diagram/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export async function calculateLayout(params: {
elements = elements.filter(el => selectedElements.has(el));
}

const nodes: { [id: string]: LayoutNode } = Object.create(null);
const bounds: { [id: string]: Rect } = Object.create(null);
const nodes = Object.create(null) as { [id: string]: LayoutNode };
const bounds = Object.create(null) as { [id: string]: Rect };

for (const element of elements) {
nodes[element.id] = {
Expand Down
Loading