@@ -19,28 +19,52 @@ const encodeHtmlEntities = (value: string) => value.replace(/&/g, '&').repla
1919 * @param {string } editor2Value the value of the second editor.
2020 * @return {string } the page HTML.
2121 */
22- const page = ( editor1Value : string , editor2Value : string ) => `
22+ const page = ( editor1Value : string , editor2Value : string , editor3Value : string , editor4Value : string ) => `
2323 <!DOCTYPE html>
2424 <html lang="en">
2525 <head>
2626 <meta charset="utf-8"/>
2727 <title>TinyMCE WebComponent Form Demo Page</title>
2828 <link rel="icon" href="data:;base64,iVBORw0KGgo=">
29+ <script>
30+ class TinyMceEditorNested extends HTMLElement {
31+ connectedCallback() {
32+ const count = parseInt(this.getAttribute('nested') || '1', 10);
33+ const content = this.getAttribute('value');
34+ const shadow = this.attachShadow({ mode: 'open' });
35+ const target = document.createElement('tinymce-editor' + (count > 1 ? '-nested' : ''));
36+ [...this.attributes].forEach( attr => { target.setAttribute(attr.nodeName, attr.nodeValue) });
37+ target.setAttribute('nested', count - 1);
38+ target.appendChild(document.createTextNode(content));
39+ shadow.appendChild(target);
40+ }
41+ }
42+ window.customElements.define('tinymce-editor-nested', TinyMceEditorNested);
43+ </script>
2944 </head>
3045 <body>
3146 <h1>TinyMCE WebComponent in Form</h1>
3247 <h2>Editor 1 (outside form with form attribute)</h2>
3348 <tinymce-editor name="editor1" form="myform">${ encodeHtmlEntities ( editor1Value ) } </tinymce-editor>
34- <h2>Editor 2 (inside form)</h2>
49+ <h2>Editor 2 (nested in shadow dom, outside form with form attribute)</h2>
50+ <tinymce-editor-nested nested="2" name="editor2" form="myform" value="${ encodeHtmlEntities ( editor2Value ) } "></tinymce-editor-nested>
3551 <form id="myform" method="POST" action="/">
36- <tinymce-editor name="editor2">${ encodeHtmlEntities ( editor2Value ) } </tinymce-editor>
52+ <h2>Editor 3 (inside form)</h2>
53+ <tinymce-editor name="editor3">${ encodeHtmlEntities ( editor3Value ) } </tinymce-editor>
54+ <h2>Editor 4 (nested in shadow dom, inside form)</h2>
55+ <tinymce-editor-nested nested="2" name="editor4" value="${ encodeHtmlEntities ( editor4Value ) } "></tinymce-editor-nested>
3756 <input type="submit" value="Submit">
3857 </form>
58+
3959 <h2>Posted Content</h2>
4060 <h3>Editor 1 value</h3>
4161 <div style="border: 1px solid black">${ editor1Value } </div>
4262 <h3>Editor 2 value</h3>
4363 <div style="border: 1px solid black">${ editor2Value } </div>
64+ <h3>Editor 3 value</h3>
65+ <div style="border: 1px solid black">${ editor3Value } </div>
66+ <h3>Editor 4 value</h3>
67+ <div style="border: 1px solid black">${ editor4Value } </div>
4468 <script src="/tinymce/tinymce.js"></script>
4569 <script src="/dist/tinymce-webcomponent.js"></script>
4670 </body>
@@ -57,12 +81,12 @@ app.use('/tinymce', express.static(tinyPath));
5781app . use ( '/dist' , express . static ( distPath ) ) ;
5882
5983app . get ( '/' , ( request , response ) => {
60- response . send ( page ( '' , '' ) ) ;
84+ response . send ( page ( '' , '' , '' , '' ) ) ;
6185} ) ;
6286
6387// Access the parse results as request.body
6488app . post ( '/' , ( request , response ) => {
65- response . send ( page ( request . body . editor1 as string , request . body . editor2 as string ) ) ;
89+ response . send ( page ( request . body . editor1 as string , request . body . editor2 as string , request . body . editor3 as string , request . body . editor4 as string ) ) ;
6690} ) ;
6791
6892app . listen ( 3000 , ( ) => console . log ( 'http://localhost:3000/' ) ) ;
0 commit comments