Skip to content

Commit

Permalink
wip: start working on CanvasEditor extension
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Jul 19, 2024
1 parent 2a5f763 commit d6a206b
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.4.1
22
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default [
...cheminfo,
...unicorn,
{
files: ['*.js'],
files: ['*.js', 'lib/**'],
languageOptions: {
sourceType: 'commonjs',
},
Expand Down
5 changes: 5 additions & 0 deletions examples/css/generic_editor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#editor-area {
width: 600px;
height: 600px;
background-color: #b5e2ff;
}
3 changes: 0 additions & 3 deletions examples/generic-editor.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
<head>
<title>Generic editor - OpenChemLib JS examples</title>
<link rel="stylesheet" href="css/base.css" />
<link rel="stylesheet" href="css/generic_editor.css" />
</head>
<body>
<h1>Generic editor</h1>
<div id="editor-area"></div>
<script type="module" src="generic-editor.ts"></script>
<script type="module" src="generic_editor.ts"></script>
</body>
</html>
12 changes: 12 additions & 0 deletions examples/generic_editor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import OCL from '../distesm/full.pretty';

const editorArea = document.getElementById('editor-area') as HTMLElement;

const editor = new OCL.CanvasEditor(editorArea, {
width: 500,
height: 500,
});

const molecule = OCL.Molecule.fromSmiles('COCO');

editor.setMolecule(molecule);
2 changes: 1 addition & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<body>
<h1>OpenChemLib JS examples</h1>
<ul>
<li><a href="generic-editor.html">Generic editor</a></li>
<li><a href="generic_editor.html">Generic editor</a></li>
</ul>
</body>
</html>
1 change: 1 addition & 0 deletions full.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export {
AtomHighlightCallback,
BondHighlightCallback,
ChangeListenerCallback,
CanvasEditor,
} from './types';
3 changes: 3 additions & 0 deletions full.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

const OCL = require('./dist/openchemlib-full.js');
const createCanvasEditor = require('./lib/canvas_editor');

exports.CanvasEditor = createCanvasEditor(OCL.EditorArea, OCL.EditorToolbar);

exports.default = OCL;
exports.CanonizerUtil = OCL.CanonizerUtil;
Expand Down
3 changes: 3 additions & 0 deletions full.pretty.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
'use strict';

const OCL = require('./dist/openchemlib-full.pretty.js');
const createCanvasEditor = require('./lib/canvas_editor');

exports.CanvasEditor = createCanvasEditor(OCL.EditorArea, OCL.EditorToolbar);

exports.default = OCL;
exports.CanonizerUtil = OCL.CanonizerUtil;
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<html lang="en">
<head>
<title>Redirecting...</title>
<meta http-equiv="refresh" content="0; url=examples/" />
<meta http-equiv="refresh" content="0; url=/examples/" />
</head>
<body>
<p>Redirecting to <a href="examples/">examples/</a>...</p>
<p>Redirecting to <a href="/examples/">/examples/</a>...</p>
</body>
</html>
12 changes: 12 additions & 0 deletions lib/canvas_editor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

function createCanvasEditor(EditorArea, EditorToolbar) {
return class CanvasEditor {
setMolecule(molecule) {
console.log('WITH WATCH');
this.molecule = molecule;
}
};
}

module.exports = createCanvasEditor;
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"build-debug-minimal": "npm run build:pretty -- -m minimal --verbose",
"build-minimal": "npm run build:min -- -m minimal",
"build-full-pretty": "npm run build:pretty -- -m full",
"build-esm": "npm run build-full-pretty && npm run build-esm-bundle",
"build-esm-bundle": "esbuild full.pretty.js --bundle --format=esm --outfile=distesm/full.pretty.js && echo \"export * from '../full.pretty';\" > distesm/full.pretty.d.ts",
"build-esm": "npm run build-full-pretty && npm run build-esm-bundle-export",
"build-esm-bundle": "esbuild full.pretty.js --bundle --format=esm --outfile=distesm/full.pretty.js",
"build-esm-bundle-watch": "npm run build-esm-bundle -- --watch",
"build-esm-bundle-export": "npm run build-esm-bundle && echo \"export * from '../full.pretty';\" > distesm/full.pretty.d.ts",
"eslint": "eslint .",
"eslint-fix": "npm run eslint -- --fix",
"prettier": "prettier --check .",
Expand Down Expand Up @@ -88,6 +90,6 @@
"yargs": "^17.7.2"
},
"volta": {
"node": "22.4.1"
"node": "22.5.1"
}
}
17 changes: 17 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3679,3 +3679,20 @@ export declare namespace SVGRenderer {
height: number,
): string;
}

export interface CanvasEditorOptions {
/**
* The width of the canvas.
*/
width: number;
/**
* The height of the canvas.
*/
height: number;
}

export declare class CanvasEditor {
constructor(element: HTMLElement, options?: CanvasEditorOptions);

setMolecule(molecule: Molecule): void;
}

0 comments on commit d6a206b

Please sign in to comment.