Skip to content

Commit

Permalink
fix: chromium derived do not support custom element extending builtin…
Browse files Browse the repository at this point in the history
… element
  • Loading branch information
tpoisseau committed Jul 25, 2024
1 parent 0b67d9c commit d486cdc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
16 changes: 8 additions & 8 deletions examples/web_component/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ <h1>Generic editor - Demo CanvasEditorElement (WebComponent)</h1>
<p>Empty editor</p>
</openchemlib-editor>

<!-- <openchemlib-editor-->
<!-- idcode="ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@"-->
<!-- readonly-->
<!-- >-->
<!-- <p>-->
<!-- Readonly editor with idcode ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@-->
<!-- </p>-->
<!-- </openchemlib-editor>-->
<openchemlib-editor
idcode="ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@"
readonly
>
<p>
Readonly editor with idcode ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@
</p>
</openchemlib-editor>
</body>
</html>
2 changes: 1 addition & 1 deletion lib/canvas_editor/init/canvas_editor_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function initCanvasEditorElement(CanvasEditor, Molecule, ReactionEncoder) {
* <openchemlib-editor></openchemlib-editor>
* ```
*/
class CanvasEditorElement extends HTMLDivElement {
class CanvasEditorElement extends HTMLElement {
/** @type {{MOLECULE: 'molecule', REACTION: 'reaction'}} */
static MODE = Object.freeze(
Object.create({
Expand Down
4 changes: 1 addition & 3 deletions lib/canvas_editor/init/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ function init(OCL) {
const constructor = customElements.get('openchemlib-editor');
if (constructor) return constructor;

customElements.define('openchemlib-editor', CanvasEditorElement, {
extends: 'div',
});
customElements.define('openchemlib-editor', CanvasEditorElement);

const css = new CSSStyleSheet();
css.replaceSync(`
Expand Down
43 changes: 43 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3803,8 +3803,51 @@ interface CanvasEditorElementConstructor extends CustomElementConstructor {
}

/**
* a Webcomponent to wrap CanvasEditor
*
* The class CanvasEditorElement is not exposed in OCL scope.
* You can obtain it from `registerCustomElement`
*
* Usage:
*
* ```js
* import {registerCustomElement} from 'openchemlib/minimal';
*
* // register CanvasEditorElement with `openchemlib-editor` tag name
* const CanvasEditorElement = registerCustomElement();
*
* // CanvasEditorElementConstructor.MODE return enums of possible modes
*
* ```
*
* @example
*
* ```html
* Molecule
* <openchemlib-editor idcode="ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@"></openchemlib-editor>
*
* Molecule Fragment
* <openchemlib-editor
* idcode="ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUhCyqHiCHy@leBhMEh]B\sa^kp"
* fragment
* ></openchemlib-editor>
*
* Reaction
* <openchemlib-editor
* idcode="gJX@@eKU@@ gGQHDHaImfh@!defH@DAIfUVjj`@"
* mode="reaction"
* ></openchemlib-editor>
*
* Reaction Fragment
* <openchemlib-editor
* idcode="gJX@@eKU@P gGQHDHaImfhB!defH@DAIfUVjj`B"
* mode="reaction"
* fragment
* ></openchemlib-editor>
*
* Molecule readonly
* <openchemlib-editor readonly idcode="ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@"></openchemlib-editor>
* ```
*/
declare interface CanvasEditorElement extends HTMLElement {
/**
Expand Down

0 comments on commit d486cdc

Please sign in to comment.