Skip to content

Commit 0cd8f3d

Browse files
committed
convert to .ts
1 parent 16c8d9f commit 0cd8f3d

13 files changed

+1444
-6185
lines changed

.eslintrc

-13
This file was deleted.

.eslintrc.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
node: true,
6+
},
7+
extends: [
8+
'eslint:recommended',
9+
],
10+
parser: '@typescript-eslint/parser',
11+
parserOptions: {
12+
ecmaVersion: 'latest',
13+
sourceType: 'script', // Changed to 'script' for CommonJS
14+
},
15+
plugins: [
16+
'@typescript-eslint',
17+
],
18+
rules: {
19+
'no-unused-vars': ['warn', {
20+
argsIgnorePattern: '^_',
21+
varsIgnorePattern: '^_',
22+
}],
23+
},
24+
};
25+

lib/paneRegistry.d.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { PaneDefinition } from './types';
2+
/**
3+
* PaneRegistry class manages a collection of PaneDefinitions.
4+
*/
5+
export declare class PaneRegistry {
6+
list: PaneDefinition[];
7+
paneForIcon: {
8+
[key: string]: PaneDefinition;
9+
};
10+
paneForPredicate: {
11+
[key: string]: {
12+
pred: string;
13+
code: number;
14+
};
15+
};
16+
/**
17+
* Registers a new PaneDefinition.
18+
* @param pane - The PaneDefinition to register.
19+
* @param requireQueryButton - Whether a query button is required for this pane.
20+
*/
21+
register(pane: PaneDefinition, requireQueryButton?: boolean): void;
22+
/**
23+
* Retrieves a PaneDefinition by its name.
24+
* @param name - The name of the PaneDefinition to find.
25+
* @returns The PaneDefinition if found, null otherwise.
26+
*/
27+
byName(name: string): PaneDefinition | null;
28+
}
29+
/**
30+
* Creates and exports a singleton instance of the PaneRegistry.
31+
*/
32+
declare const paneRegistry: PaneRegistry;
33+
export default paneRegistry;

lib/paneRegistry.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"use strict";
2+
// paneRegistry.ts (Replacement for paneRegistry.js)
3+
Object.defineProperty(exports, "__esModule", { value: true });
4+
exports.PaneRegistry = void 0;
5+
/**
6+
* PaneRegistry class manages a collection of PaneDefinitions.
7+
*/
8+
class PaneRegistry {
9+
constructor() {
10+
this.list = [];
11+
this.paneForIcon = {};
12+
this.paneForPredicate = {};
13+
}
14+
/**
15+
* Registers a new PaneDefinition.
16+
* @param pane - The PaneDefinition to register.
17+
* @param requireQueryButton - Whether a query button is required for this pane.
18+
*/
19+
register(pane, requireQueryButton) {
20+
pane.requireQueryButton = requireQueryButton;
21+
if (!pane.name) {
22+
console.log('*** No name for pane!');
23+
return;
24+
}
25+
console.log(' registering pane: ' + pane.name);
26+
if (!pane.label) {
27+
console.log('*** No label for pane!');
28+
return;
29+
}
30+
this.list.push(pane);
31+
if (!(pane.name in this)) {
32+
// don't overwrite methods
33+
// @ts-ignore
34+
this[pane.name] = pane;
35+
}
36+
if (pane.icon) {
37+
this.paneForIcon[pane.icon] = pane;
38+
}
39+
if (pane.predicates) {
40+
for (const x in pane.predicates) {
41+
this.paneForPredicate[x] = { pred: x, code: pane.predicates[x] };
42+
}
43+
}
44+
}
45+
/**
46+
* Retrieves a PaneDefinition by its name.
47+
* @param name - The name of the PaneDefinition to find.
48+
* @returns The PaneDefinition if found, null otherwise.
49+
*/
50+
byName(name) {
51+
for (let i = 0; i < this.list.length; i++) {
52+
if (this.list[i].name === name)
53+
return this.list[i];
54+
}
55+
console.warn(`No view with name ${name} found in the registry of views (aka paneRegistry)`);
56+
return null;
57+
}
58+
}
59+
exports.PaneRegistry = PaneRegistry;
60+
/**
61+
* Creates and exports a singleton instance of the PaneRegistry.
62+
*/
63+
const paneRegistry = new PaneRegistry();
64+
exports.default = paneRegistry;

lib/types.d.ts

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import type { LiveStore, NamedNode } from 'rdflib';
2+
import type { SolidLogic } from 'solid-logic';
3+
export interface DataBrowserSession {
4+
paneRegistry: PaneRegistry;
5+
store: LiveStore;
6+
logic: SolidLogic;
7+
}
8+
export interface DataBrowserContext {
9+
dom: HTMLDocument;
10+
getOutliner: (dom: HTMLDocument) => unknown;
11+
session: DataBrowserSession;
12+
}
13+
export interface PaneDefinition {
14+
icon: string;
15+
global?: boolean;
16+
name: string;
17+
audience?: NamedNode[];
18+
label: (subject: NamedNode, context: DataBrowserContext) => string | null;
19+
render: (subject: NamedNode, context: DataBrowserContext, options?: unknown) => HTMLElement;
20+
shouldGetFocus?: (subject: NamedNode) => boolean;
21+
requireQueryButton?: boolean;
22+
mintClass?: NamedNode;
23+
mintNew?: (context: DataBrowserContext, options: NewPaneOptions) => Promise<NewPaneOptions & {
24+
newInstance: NamedNode;
25+
}>;
26+
predicates?: {
27+
[key: string]: number;
28+
};
29+
classes?: {
30+
[key: string]: number;
31+
};
32+
}
33+
export interface NewPaneOptions {
34+
appPathSegment?: string;
35+
div: HTMLElement;
36+
dom: HTMLDocument;
37+
folder: NamedNode;
38+
iconEle: HTMLImageElement;
39+
me?: NamedNode;
40+
newBase: string;
41+
newInstance?: NamedNode;
42+
noIndexHTML: boolean;
43+
noun: string;
44+
pane: PaneDefinition;
45+
refreshTarget?: HTMLTableElement;
46+
}
47+
export interface PaneRegistry {
48+
list: PaneDefinition[];
49+
paneForIcon: {
50+
[key: string]: PaneDefinition;
51+
};
52+
paneForPredicate: {
53+
[key: string]: {
54+
pred: string;
55+
code: number;
56+
};
57+
};
58+
register(pane: PaneDefinition, requireQueryButton?: boolean): void;
59+
byName(name: string): PaneDefinition | null;
60+
[key: string]: any;
61+
}

lib/types.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

0 commit comments

Comments
 (0)