web-documentation 1.0.28 → 1.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-documentation",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "description": "Declarative multilanguage documentation website generator",
5
5
  "keywords": [
6
6
  "documentation",
@@ -68,7 +68,7 @@
68
68
  "@webcomponents/webcomponentsjs": "^2.8.0",
69
69
  "archiver": "^8.0.0",
70
70
  "bootstrap-icons": "^1.13.1",
71
- "clientnode": "^4.0.1414",
71
+ "clientnode": "^4.0.1419",
72
72
  "css-loader": "^7.1.4",
73
73
  "cssnano": "^8.0.1",
74
74
  "default-gateway": "^7.2.2",
@@ -82,14 +82,28 @@ zip file here and inject or request via cdn in HTML:
82
82
  npm install clientnode
83
83
  ```
84
84
 
85
+ <!--showExample-->
86
+
85
87
  ```HTML
86
- <!--Inject downloaded file:
87
- <script src="index.js"></script>
88
- -->
89
- <!--Or integrate via cdn:-->
90
- <script
91
- src="https://torben.website/clientnode/data/distributionBundle/index.js"
92
- ></script>
88
+ <script src="https://unpkg.com/clientnode@latest/dist/bundle/index.js">
89
+ </script>
90
+
91
+ <div id="first-example-playground"></div>
92
+ ```
93
+
94
+ <!--showExample:JavaScript-->
95
+
96
+ ```JavaScript
97
+ const domNode = clientnode.createDomNodes('<p>some content to animate</p>');
98
+
99
+ const endless = () => {
100
+ clientnode.fadeIn(domNode)
101
+ .then(() => clientnode.fadeOut(domNode))
102
+ .then(endless)
103
+ };
104
+ endless();
105
+
106
+ document.querySelector('#first-example-playground').appendChild(domNode);
93
107
  ```
94
108
 
95
109
  The compiled bundle supports AMD, commonjs, commonjs2 and variable injection
@@ -105,13 +119,25 @@ want.
105
119
  Usage
106
120
  -----
107
121
 
108
- Function call from previous generated instance via dom node or instance
109
- reference:
110
- <!--deDE:
111
- Aufruf einer Plugin-Methode anhand der zuvor generierten Instanz bzw. über
112
- den zurückgegebene DOM-Knoten:
113
- -->
122
+ Execute a JSON based expression:
123
+ <!--deDE:Ausführung eines JSON basierten Ausdrucks:-->
124
+
125
+ <!--showExample-->
126
+
127
+ ```HTML
128
+ <div id="second-example-playground"></div>
129
+ ```
130
+
131
+ <!--showExample:JavaScript-->
114
132
 
115
133
  ```JavaScript
116
- console.log('TEST')
134
+ document.querySelector('#second-example-playground').innerText =
135
+ clientnode.evaluateExpression(
136
+ {
137
+ $operator: '+',
138
+ operand1: 2,
139
+ operand2: {$select: 'some.data.in.scope'}
140
+ },
141
+ {some: {data: {in: {scope: 3}}}}
142
+ );
117
143
  ```
package/source/index.ts CHANGED
@@ -191,7 +191,7 @@ export class WebDocumentation<
191
191
  NOTE: We have to render examples first to avoid having dots in
192
192
  example code.
193
193
  */
194
- this._showExamples()
194
+ await this._showExamples()
195
195
 
196
196
  this._makeCodeEllipsis()
197
197
 
@@ -398,7 +398,7 @@ export class WebDocumentation<
398
398
  /**
399
399
  * Shows marked example codes directly in browser.
400
400
  */
401
- _showExamples(): void {
401
+ async _showExamples(): Promise<void> {
402
402
  for (const domNode of getAll(this.hostDomNode))
403
403
  if (domNode.nodeName === this.options.showExample.domNodeName) {
404
404
  const match: null | RegExpMatchArray =
@@ -418,6 +418,7 @@ export class WebDocumentation<
418
418
 
419
419
  try {
420
420
  let domNode: HTMLElement | string = ''
421
+ let reInjectScripts = false
421
422
  if (match.length > 2 && match[2])
422
423
  if (
423
424
  ['javascript', 'javascripts', 'js']
@@ -438,19 +439,53 @@ export class WebDocumentation<
438
439
  domNode.setAttribute('type', 'text/css')
439
440
  domNode.innerText = code
440
441
  } else if (match[2].toLowerCase() === 'hidden')
441
- domNode = code
442
- else
442
+ domNode = createDomNodes(code)
443
+ else {
443
444
  domNode = createDomNodes(format(
444
- this.options.showExample.htmlWrapper,
445
- code
445
+ this.options.showExample.htmlWrapper, code
446
446
  ))
447
- else
447
+ reInjectScripts = true
448
+ }
449
+ else {
448
450
  domNode = createDomNodes(format(
449
- this.options.showExample.htmlWrapper,
450
- code
451
+ this.options.showExample.htmlWrapper, code
451
452
  ))
453
+ reInjectScripts = true
454
+ }
452
455
 
453
456
  codeDomNode.after(domNode)
457
+
458
+ if (reInjectScripts)
459
+ /*
460
+ Injected script tags are not executed by
461
+ default. So we need to reinject those.
462
+ */
463
+ for (const scriptDomNode of
464
+ domNode.querySelectorAll('script')
465
+ ) {
466
+ const newScriptDomNode =
467
+ document.createElement('script')
468
+ for (const name of
469
+ scriptDomNode.getAttributeNames()
470
+ )
471
+ newScriptDomNode.setAttribute(
472
+ name,
473
+ scriptDomNode.getAttribute(name) as
474
+ string
475
+ )
476
+ newScriptDomNode.textContent =
477
+ scriptDomNode.textContent
478
+ const promise = new Promise((resolve) => {
479
+ newScriptDomNode.addEventListener(
480
+ 'load', resolve
481
+ )
482
+ })
483
+ if (scriptDomNode.parentNode)
484
+ scriptDomNode.parentNode.replaceChild(
485
+ newScriptDomNode, scriptDomNode
486
+ )
487
+ await promise
488
+ }
454
489
  } catch (error) {
455
490
  log.critical(
456
491
  `Error while integrating code "${code}":`,
@@ -460,7 +495,6 @@ export class WebDocumentation<
460
495
  }
461
496
  }
462
497
 
463
-
464
498
  this.onExamplesLoaded()
465
499
  }
466
500
  // endregion