Skip to content

Commit 2ddac0b

Browse files
committed
Add all imports to also work straight from default export
1 parent 4f3bfcd commit 2ddac0b

File tree

10 files changed

+3151
-2172
lines changed

10 files changed

+3151
-2172
lines changed

babel.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
}], "@babel/preset-typescript"],
77
plugins: [
88
["@babel/plugin-transform-runtime", {corejs: 3}],
9-
"@babel/plugin-proposal-class-properties"
9+
"@babel/plugin-proposal-class-properties",
10+
"@babel/plugin-proposal-private-methods"
1011
]
1112
}

dist/neovis-without-dependencies.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/neovis-without-dependencies.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/neovis.d.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,26 @@ import type * as Neo4jTypes from 'neo4j-driver';
22
import { EventFunctionTypes, NeoVisEvents } from './events';
33
import type * as VisNetwork from 'vis-network';
44
import { Cypher, Edge, NEOVIS_DEFAULT_CONFIG, NeovisConfig, Node, NonFlatNeovisConfig, NumberOrInteger } from './types';
5-
import { Font } from 'vis-network';
65
export * from './events';
76
export * from './types';
7+
/**
8+
* create html display of the node
9+
* @param neo4jObject node to create html from
10+
* @param titleProperties which properties to map
11+
*/
12+
export declare function objectToTitleHtml(neo4jObject: Neo4jTypes.Node<NumberOrInteger> | Neo4jTypes.Relationship<NumberOrInteger>, titleProperties: string[]): HTMLDivElement;
13+
/**
14+
* create string display of the node
15+
* @param neo4jObject node to create title string from
16+
* @param titleProperties which properties to map
17+
*/
18+
export declare function objectToTitleString(neo4jObject: Neo4jTypes.Node<NumberOrInteger> | Neo4jTypes.Relationship<NumberOrInteger>, titleProperties: string[]): string;
819
export declare class NeoVis {
920
#private;
21+
static NEOVIS_DEFAULT_CONFIG: symbol;
22+
static NEOVIS_ADVANCED_CONFIG: symbol;
23+
static objectToTitleHtml: typeof objectToTitleHtml;
24+
static objectToTitleString: typeof objectToTitleString;
1025
/**
1126
* All view nodes as DataSet
1227
* @link https://visjs.github.io/vis-data/data/dataset.html
@@ -71,18 +86,6 @@ export declare class NeoVis {
7186
*/
7287
updateWithCypher(query: Cypher): void;
7388
}
74-
/**
75-
* create html display of the node
76-
* @param neo4jObject node to create html from
77-
* @param titleProperties which properties to map
78-
*/
79-
export declare function objectToTitleHtml(neo4jObject: Neo4jTypes.Node<NumberOrInteger> | Neo4jTypes.Relationship<NumberOrInteger>, titleProperties: string[]): HTMLDivElement;
80-
/**
81-
* create string display of the node
82-
* @param neo4jObject node to create title string from
83-
* @param titleProperties which properties to map
84-
*/
85-
export declare function objectToTitleString(neo4jObject: Neo4jTypes.Node<NumberOrInteger> | Neo4jTypes.Relationship<NumberOrInteger>, titleProperties: string[]): string;
8689
/**
8790
* @deprecated for migration only
8891
*/
@@ -92,7 +95,7 @@ export interface OldLabelConfig {
9295
community?: string;
9396
sizeCypher?: string;
9497
image?: string;
95-
font?: string | Font;
98+
font?: string | VisNetwork.Font;
9699
title_properties?: string[];
97100
}
98101
/**

dist/neovis.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/neovis.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/types.d.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ import type * as Neo4jTypes from 'neo4j-driver';
22
import type * as VisNetwork from 'vis-network';
33
export declare const NEOVIS_DEFAULT_CONFIG: unique symbol;
44
export declare const NEOVIS_ADVANCED_CONFIG: unique symbol;
5-
export declare type NumberOrInteger = number | Neo4jTypes.Integer;
6-
export declare type RecursiveMapToDist<T, New> = T extends object ? RecursiveMapTo<T, New> : New;
5+
export type NumberOrInteger = number | Neo4jTypes.Integer;
6+
export type RecursiveMapToDist<T, New> = T extends object ? RecursiveMapTo<T, New> : New;
77
/**
88
* Maps a type recursively and replace each non object type with the new type
99
* @param <T> type to map
1010
* @param <New> type to map to for each non object type
1111
*/
12-
export declare type RecursiveMapTo<T, New> = {
12+
export type RecursiveMapTo<T, New> = {
1313
[P in keyof T]: RecursiveMapToDist<T[P], New>;
1414
};
15-
export declare type RecursiveMapToFunctionDist<T, PARAM_TYPE> = T extends object ? ((param: PARAM_TYPE) => T) | (RecursiveMapToFunction<T, PARAM_TYPE>) : (param: PARAM_TYPE) => T;
15+
export type RecursiveMapToFunctionDist<T, PARAM_TYPE> = T extends object ? ((param: PARAM_TYPE) => T) | (RecursiveMapToFunction<T, PARAM_TYPE>) : (param: PARAM_TYPE) => T;
1616
/**
1717
* Maps a type recursively and adds the ability for each object property to be a function that returns the same type
1818
* but replace each non object type with a function that returns the same type
1919
* @param <T> type to map
2020
* @param <PARAM_TYPE> type of parameter the functions get
2121
*/
22-
export declare type RecursiveMapToFunction<T, PARAM_TYPE> = {
22+
export type RecursiveMapToFunction<T, PARAM_TYPE> = {
2323
[P in keyof T]: RecursiveMapToFunctionDist<T[P], PARAM_TYPE>;
2424
};
2525
/**
2626
* Cypher quarry
2727
*/
28-
export declare type Cypher = string;
28+
export type Cypher = string;
2929
export interface NeoVisAdvanceConfig<VIS_TYPE, NEO_TYPE> {
3030
/**
3131
* Static values that will the same for every node/relationship
@@ -40,7 +40,7 @@ export interface NeoVisAdvanceConfig<VIS_TYPE, NEO_TYPE> {
4040
export interface NonFlatNeoVisAdvanceConfig<VIS_TYPE, NEO_TYPE> extends NeoVisAdvanceConfig<VIS_TYPE, NEO_TYPE> {
4141
property?: RecursiveMapTo<VIS_TYPE, string>;
4242
}
43-
export declare type NeovisDataConfig<VIS_TYPE, NEO_TYPE> = RecursiveMapTo<VIS_TYPE, string> & {
43+
export type NeovisDataConfig<VIS_TYPE, NEO_TYPE> = RecursiveMapTo<VIS_TYPE, string> & {
4444
[NEOVIS_ADVANCED_CONFIG]?: NeoVisAdvanceConfig<VIS_TYPE, NEO_TYPE>;
4545
};
4646
/**
@@ -80,10 +80,6 @@ export interface Neo4jConfig {
8080
/**
8181
* @link https://neo4j.com/docs/api/javascript-driver/current/function/index.html#configuration
8282
*/
83-
/**
84-
* All view nodes as DataSet
85-
* @link https://visjs.github.io/vis-data/data/dataset.html
86-
*/
8783
driverConfig?: Neo4jTypes.Config;
8884
}
8985
export interface BaseNeovisConfig {
@@ -243,8 +239,8 @@ export interface NeovisConfig extends BaseNeovisConfig {
243239
[NEOVIS_DEFAULT_CONFIG]?: RelationshipConfig;
244240
};
245241
}
246-
export declare type NonFlatLabelConfig = NonFlatNeoVisAdvanceConfig<VisNetwork.Node, Neo4jTypes.Node<number>>;
247-
export declare type NonFlatRelationsipConfig = NonFlatNeoVisAdvanceConfig<VisNetwork.Edge, Neo4jTypes.Relationship<number>>;
242+
export type NonFlatLabelConfig = NonFlatNeoVisAdvanceConfig<VisNetwork.Node, Neo4jTypes.Node<number>>;
243+
export type NonFlatRelationsipConfig = NonFlatNeoVisAdvanceConfig<VisNetwork.Edge, Neo4jTypes.Relationship<number>>;
248244
/**
249245
* non flat version of the configuration (without Symbols)
250246
* look at the normal config for more information

package.json

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,44 +38,45 @@
3838
},
3939
"homepage": "https://github.com/neo4j-contrib/neovis.js#readme",
4040
"devDependencies": {
41-
"@babel/cli": "^7.17.10",
42-
"@babel/core": "^7.18.5",
43-
"@babel/plugin-transform-runtime": "^7.18.5",
44-
"@babel/preset-env": "^7.18.2",
45-
"@babel/preset-typescript": "^7.17.12",
41+
"@babel/cli": "^7.21.5",
42+
"@babel/core": "^7.21.8",
43+
"@babel/plugin-proposal-private-methods": "^7.18.6",
44+
"@babel/plugin-transform-runtime": "^7.21.4",
45+
"@babel/preset-env": "^7.21.5",
46+
"@babel/preset-typescript": "^7.21.5",
4647
"@egjs/hammerjs": "^2.0.17",
47-
"@types/jest": "^28.1.3",
48-
"@typescript-eslint/eslint-plugin": "^5.29.0",
49-
"@typescript-eslint/parser": "^5.29.0",
50-
"babel-loader": "^8.2.5",
48+
"@types/jest": "^29.5.1",
49+
"@typescript-eslint/eslint-plugin": "^5.59.5",
50+
"@typescript-eslint/parser": "^5.59.5",
51+
"babel-loader": "^9.1.2",
5152
"component-emitter": "^1.3.0",
52-
"core-js": "^3.23.3",
53+
"core-js": "^3.30.2",
5354
"cross-env": "^7.0.3",
54-
"css-loader": "^6.7.1",
55-
"eslint": "^8.18.0",
56-
"eslint-plugin-jest": "^26.5.3",
57-
"jest": "^28.1.1",
58-
"jest-canvas-mock": "^2.4.0",
59-
"jest-environment-jsdom": "^28.1.1",
55+
"css-loader": "^6.7.3",
56+
"eslint": "^8.40.0",
57+
"eslint-plugin-jest": "^27.2.1",
58+
"jest": "^29.5.0",
59+
"jest-canvas-mock": "^2.5.0",
60+
"jest-environment-jsdom": "^29.5.0",
6061
"keycharm": "^0.4.0",
6162
"npm-run-all": "^4.1.5",
62-
"rimraf": "^3.0.2",
63-
"style-loader": "^3.3.1",
63+
"rimraf": "^5.0.0",
64+
"style-loader": "^3.3.2",
6465
"timsort": "^0.3.0",
65-
"typedoc": "^0.22.18",
66-
"typescript": "^4.7.4",
67-
"uuid": "^8.3.2",
68-
"vis-data": "^7.1.4",
66+
"typedoc": "^0.24.7",
67+
"typescript": "^5.0.4",
68+
"uuid": "^9.0.0",
69+
"vis-data": "^7.1.6",
6970
"vis-util": "^5.0.3",
70-
"webpack": "^5.73.0",
71-
"webpack-cli": "^4.10.0"
71+
"webpack": "^5.82.0",
72+
"webpack-cli": "^5.1.0"
7273
},
7374
"dependencies": {
74-
"@babel/runtime-corejs3": "^7.18.3",
75-
"deepmerge": "^4.2.2",
75+
"@babel/runtime-corejs3": "^7.21.5",
76+
"deepmerge": "^4.3.1",
7677
"neo4j-driver": "^4.4.6",
7778
"neo4j-driver-core": "^4.4.6",
78-
"vis-network": "^9.1.2"
79+
"vis-network": "^9.1.6"
7980
},
8081
"jest": {
8182
"moduleNameMapper": {

src/neovis.ts

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,77 @@ import {
2828
RecursiveMapToFunction,
2929
RelationshipConfig
3030
} from './types';
31-
import { Font } from 'vis-network';
3231

3332
export * from './events';
3433
export * from './types';
3534

3635
function isNeo4jDriver(neo4jConfig: Neo4jTypes.Driver | Neo4jConfig): neo4jConfig is Neo4jTypes.Driver {
3736
return neo4jConfig instanceof Neo4j.driver;
3837
}
38+
function _propertyToHtml<T extends { toString: () => string }>(key: string, value: T | T[]): string {
39+
if (Array.isArray(value) && value.length > 1) {
40+
let out = `<strong>${key}:</strong><br /><ul>`;
41+
for (const val of value) {
42+
out += `<li>${val}</li>`;
43+
}
44+
return out + '</ul>';
45+
}
46+
return `<strong>${key}:</strong> ${value}<br>`;
47+
}
48+
49+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
50+
function _retrieveProperty<T>(prop: string, obj: any): T {
51+
if (typeof obj?.properties === 'object') {
52+
return isInt(obj.properties[prop]) ? obj.properties[prop].toInt() : obj.properties[prop];
53+
}
54+
throw new Error('Neo4j object is not properly constructed');
55+
}
56+
57+
/**
58+
* create html display of the node
59+
* @param neo4jObject node to create html from
60+
* @param titleProperties which properties to map
61+
*/
62+
export function objectToTitleHtml(neo4jObject: Neo4jTypes.Node<NumberOrInteger> | Neo4jTypes.Relationship<NumberOrInteger>, titleProperties: string[]): HTMLDivElement {
63+
let titleString = '';
64+
if (!titleProperties) {
65+
titleProperties = Object.keys(neo4jObject.properties);
66+
}
67+
for (const key of titleProperties) {
68+
const propVal = _retrieveProperty(key, neo4jObject);
69+
if (propVal) {
70+
titleString += _propertyToHtml(key, propVal);
71+
}
72+
}
73+
const title = document.createElement('div');
74+
title.innerHTML = titleString;
75+
return title;
76+
}
77+
78+
/**
79+
* create string display of the node
80+
* @param neo4jObject node to create title string from
81+
* @param titleProperties which properties to map
82+
*/
83+
export function objectToTitleString(neo4jObject: Neo4jTypes.Node<NumberOrInteger> | Neo4jTypes.Relationship<NumberOrInteger>, titleProperties: string[]): string {
84+
let title = '';
85+
if (!titleProperties) {
86+
titleProperties = Object.keys(neo4jObject.properties);
87+
}
88+
for (const key of titleProperties) {
89+
const propVal = _retrieveProperty(key, neo4jObject);
90+
if (propVal) {
91+
title += `${key}: ${propVal}\n`;
92+
}
93+
}
94+
return title;
95+
}
3996

4097
export class NeoVis {
98+
static NEOVIS_DEFAULT_CONFIG = NEOVIS_DEFAULT_CONFIG;
99+
static NEOVIS_ADVANCED_CONFIG = NEOVIS_ADVANCED_CONFIG;
100+
static objectToTitleHtml = objectToTitleHtml;
101+
static objectToTitleString = objectToTitleString;
41102
#data = {
42103
nodes: new vis.DataSet<Node>(),
43104
edges: new vis.DataSet<Edge>()
@@ -538,65 +599,6 @@ export class NeoVis {
538599
}
539600
}
540601

541-
function _propertyToHtml<T extends { toString: () => string }>(key: string, value: T | T[]): string {
542-
if (Array.isArray(value) && value.length > 1) {
543-
let out = `<strong>${key}:</strong><br /><ul>`;
544-
for (const val of value) {
545-
out += `<li>${val}</li>`;
546-
}
547-
return out + '</ul>';
548-
}
549-
return `<strong>${key}:</strong> ${value}<br>`;
550-
}
551-
552-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
553-
function _retrieveProperty<T>(prop: string, obj: any): T {
554-
if (typeof obj?.properties === 'object') {
555-
return isInt(obj.properties[prop]) ? obj.properties[prop].toInt() : obj.properties[prop];
556-
}
557-
throw new Error('Neo4j object is not properly constructed');
558-
}
559-
560-
/**
561-
* create html display of the node
562-
* @param neo4jObject node to create html from
563-
* @param titleProperties which properties to map
564-
*/
565-
export function objectToTitleHtml(neo4jObject: Neo4jTypes.Node<NumberOrInteger> | Neo4jTypes.Relationship<NumberOrInteger>, titleProperties: string[]): HTMLDivElement {
566-
let titleString = '';
567-
if (!titleProperties) {
568-
titleProperties = Object.keys(neo4jObject.properties);
569-
}
570-
for (const key of titleProperties) {
571-
const propVal = _retrieveProperty(key, neo4jObject);
572-
if (propVal) {
573-
titleString += _propertyToHtml(key, propVal);
574-
}
575-
}
576-
const title = document.createElement('div');
577-
title.innerHTML = titleString;
578-
return title;
579-
}
580-
581-
/**
582-
* create string display of the node
583-
* @param neo4jObject node to create title string from
584-
* @param titleProperties which properties to map
585-
*/
586-
export function objectToTitleString(neo4jObject: Neo4jTypes.Node<NumberOrInteger> | Neo4jTypes.Relationship<NumberOrInteger>, titleProperties: string[]): string {
587-
let title = '';
588-
if (!titleProperties) {
589-
titleProperties = Object.keys(neo4jObject.properties);
590-
}
591-
for (const key of titleProperties) {
592-
const propVal = _retrieveProperty(key, neo4jObject);
593-
if (propVal) {
594-
title += `${key}: ${propVal}\n`;
595-
}
596-
}
597-
return title;
598-
}
599-
600602
/**
601603
* @deprecated for migration only
602604
*/
@@ -606,7 +608,7 @@ export interface OldLabelConfig {
606608
community?: string;
607609
sizeCypher?: string;
608610
image?: string;
609-
font?: string | Font;
611+
font?: string | VisNetwork.Font;
610612
title_properties?: string[];
611613
}
612614

0 commit comments

Comments
 (0)