web-documentation 1.0.28 → 1.0.29

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.29",
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",
package/source/deploy.ts CHANGED
@@ -451,7 +451,8 @@ const isFileIgnored = async (filePath: string): Promise<boolean> => (
451
451
  */
452
452
  const copyRepositoryFile = async (
453
453
  sourcePath: string, targetPath: string, file: File
454
- ): Promise<false | undefined> => {
454
+ ): Promise<false | undefined> =>
455
+ {
455
456
  if (await isFileIgnored(file.path) || basename(file.name) === 'readme.md')
456
457
  return false
457
458
 
@@ -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']
@@ -439,18 +440,39 @@ export class WebDocumentation<
439
440
  domNode.innerText = code
440
441
  } else if (match[2].toLowerCase() === 'hidden')
441
442
  domNode = code
442
- else
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 domNode.querySelectorAll('script')) {
464
+ // const newScriptDomNode = scriptDomNode.cloneNode(true)
465
+ const newScriptDomNode = document.createElement('script')
466
+ for (const name of scriptDomNode.getAttributeNames())
467
+ newScriptDomNode.setAttribute(name, scriptDomNode.getAttribute(name))
468
+ newScriptDomNode.textContent = scriptDomNode.textContent
469
+ const promise = new Promise((resolve) => {
470
+ newScriptDomNode.addEventListener('load', resolve)
471
+ })
472
+ scriptDomNode.parentNode.replaceChild(newScriptDomNode, scriptDomNode)
473
+ await promise
474
+ }
475
+ }
454
476
  } catch (error) {
455
477
  log.critical(
456
478
  `Error while integrating code "${code}":`,
@@ -460,7 +482,6 @@ export class WebDocumentation<
460
482
  }
461
483
  }
462
484
 
463
-
464
485
  this.onExamplesLoaded()
465
486
  }
466
487
  // endregion