Skip to content

Commit

Permalink
Revert "feat: JSON.stringify encode idcode"
Browse files Browse the repository at this point in the history
This reverts commit a1c8d94.
  • Loading branch information
tpoisseau committed Oct 17, 2024
1 parent a1c8d94 commit 6c0a5cc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
14 changes: 7 additions & 7 deletions examples/generic_editor/web_component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1>Generic editor - &lt;openchemlib-editor> (Web Component) demo</h1>

<p>Molecule <code>ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@</code></p>
<openchemlib-editor
idcode='"ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@"'
idcode="ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@"
></openchemlib-editor>

<p>
Expand All @@ -34,7 +34,7 @@ <h1>Generic editor - &lt;openchemlib-editor> (Web Component) demo</h1>
</code>
</p>
<openchemlib-editor
idcode='"ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUhCyqHiCHy@leBhMEh]B\sa^kp"'
idcode="ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUhCyqHiCHy@leBhMEh]B\sa^kp"
fragment
></openchemlib-editor>

Expand All @@ -44,12 +44,12 @@ <h1>Generic editor - &lt;openchemlib-editor> (Web Component) demo</h1>
</p>
<openchemlib-editor
readonly
idcode='"ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@"'
idcode="ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@"
></openchemlib-editor>

<p>Reaction <code>gJX@@eKU@@ gGQHDHaImfh@!defH@DAIfUVjj`@</code></p>
<openchemlib-editor
idcode='"gJX@@eKU@@ gGQHDHaImfh@!defH@DAIfUVjj`@"'
idcode="gJX@@eKU@@ gGQHDHaImfh@!defH@DAIfUVjj`@"
mode="reaction"
></openchemlib-editor>

Expand All @@ -58,7 +58,7 @@ <h1>Generic editor - &lt;openchemlib-editor> (Web Component) demo</h1>
<code>gJX@@eKU@P gGQHDHaImfhB!defH@DAIfUVjj`B</code>
</p>
<openchemlib-editor
idcode='"gJX@@eKU@P gGQHDHaImfhB!defH@DAIfUVjj`B"'
idcode="gJX@@eKU@P gGQHDHaImfhB!defH@DAIfUVjj`B"
mode="reaction"
fragment
></openchemlib-editor>
Expand All @@ -67,7 +67,7 @@ <h1>Generic editor - &lt;openchemlib-editor> (Web Component) demo</h1>
Reaction readonly <code>gJX@@eKU@@ gGQHDHaImfh@!defH@DAIfUVjj`@</code>
</p>
<openchemlib-editor
idcode='"gJX@@eKU@@ gGQHDHaImfh@!defH@DAIfUVjj`@"'
idcode="gJX@@eKU@@ gGQHDHaImfh@!defH@DAIfUVjj`@"
mode="reaction"
readonly
></openchemlib-editor>
Expand All @@ -79,7 +79,7 @@ <h1>Generic editor - &lt;openchemlib-editor> (Web Component) demo</h1>
!Bb@Jw@oy??`C~@K\B !Bb@K~_{\BbOvH?_y?##</code
>
<openchemlib-editor
idcode='"gOp@DjWkjj`@ gOp@DjWkjj`@!gOp@DjWkjj`@##!BbOvw?_x@?g?~_{_} !Bb@Jw@oy??`C~@K\B !Bb@K~_{\BbOvH?_y?##"'
idcode="gOp@DjWkjj`@ gOp@DjWkjj`@!gOp@DjWkjj`@##!BbOvw?_x@?g?~_{_} !Bb@Jw@oy??`C~@K\B !Bb@K~_{\BbOvH?_y?##"
mode="reaction"
></openchemlib-editor>
</p>
Expand Down
8 changes: 3 additions & 5 deletions lib/canvas_editor/init/canvas_editor_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function initCanvasEditorElement(CanvasEditor, Molecule, ReactionEncoder) {

set idcode(value) {
this.#state.idcode = String(value);
this.setAttribute('idcode', JSON.stringify(this.#state.idcode));
this.setAttribute('idcode', this.#state.idcode);
}

get fragment() {
Expand Down Expand Up @@ -286,10 +286,8 @@ function initCanvasEditorElement(CanvasEditor, Molecule, ReactionEncoder) {
* Custom element added to page.
*/
connectedCallback() {
const jsonIdcode = this.getAttribute('idcode');

this.#state = {
idcode: JSON.parse(jsonIdcode) || '',
idcode: this.getAttribute('idcode') || '',
fragment: this.hasAttribute('fragment'),
mode: this.getAttribute('mode') || CanvasEditorElement.MODE.MOLECULE,
readonly: this.hasAttribute('readonly'),
Expand Down Expand Up @@ -325,7 +323,7 @@ function initCanvasEditorElement(CanvasEditor, Molecule, ReactionEncoder) {
const mutatorHandler = (() => {
switch (name) {
case 'idcode': {
this.#state.idcode = JSON.parse(String(newValue));
this.#state.idcode = String(newValue);
return () => this.#initIdCode();
}
case 'fragment': {
Expand Down
17 changes: 6 additions & 11 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3921,17 +3921,13 @@ interface CanvasEditorElementConstructor extends CustomElementConstructor {
* ```
*
* In HTML
*
* /!\ The `idcode` attribute MUST be encoded with `JSON.stringify`.
* `idcode` can include special characters like `\u007F` which are not valid in `UVString`
*
* ```html
* <p>Empty editor</p>
* <openchemlib-editor></openchemlib-editor>
*
* <p>Molecule <code>ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@</code></p>
* <openchemlib-editor
* idcode="&quot;ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@&quot;"
* idcode="ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@"
* ></openchemlib-editor>
*
* <p>
Expand All @@ -3941,13 +3937,13 @@ interface CanvasEditorElementConstructor extends CustomElementConstructor {
* </code>
* </p>
* <openchemlib-editor
* idcode="&quot;ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUhCyqHiCHy@leBhMEh]B\sa^kp&quot;"
* idcode="ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUhCyqHiCHy@leBhMEh]B\sa^kp"
* fragment
* ></openchemlib-editor>
*
* <p>Reaction <code>gJX@@eKU@@ gGQHDHaImfh@!defH@DAIfUVjj`@</code></p>
* <openchemlib-editor
* idcode="&quot;gJX@@eKU@@ gGQHDHaImfh@!defH@DAIfUVjj`@&quot;"
* idcode="gJX@@eKU@@ gGQHDHaImfh@!defH@DAIfUVjj`@"
* mode="reaction"
* ></openchemlib-editor>
*
Expand All @@ -3956,7 +3952,7 @@ interface CanvasEditorElementConstructor extends CustomElementConstructor {
* <code>gJX@@eKU@P gGQHDHaImfhB!defH@DAIfUVjj`B</code>
* </p>
* <openchemlib-editor
* idcode="&quot;gJX@@eKU@P gGQHDHaImfhB!defH@DAIfUVjj`B&quot;"
* idcode="gJX@@eKU@P gGQHDHaImfhB!defH@DAIfUVjj`B"
* mode="reaction"
* fragment
* ></openchemlib-editor>
Expand All @@ -3967,7 +3963,7 @@ interface CanvasEditorElementConstructor extends CustomElementConstructor {
* </p>
* <openchemlib-editor
* readonly
* idcode="&quot;ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@&quot;"
* idcode="ffc`P@H`QxNQQJJIJIZJHiSkQSejB`jFjhhaEqFUh@"
* ></openchemlib-editor>
* ```
*
Expand All @@ -3987,8 +3983,7 @@ interface CanvasEditorElementConstructor extends CustomElementConstructor {
*/
declare interface CanvasEditorElement extends HTMLElement {
/**
* If set from attributes, init from DOM, it MUST be encoded with JSON.stringify.
* @defaultValue '""'
* @defaultValue ''
*/
idcode: string;
/**
Expand Down

0 comments on commit 6c0a5cc

Please sign in to comment.