@gouvfr/dsfr-roller 1.0.15 → 1.0.17
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": "@gouvfr/dsfr-roller",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "Le module `dsfr-roller` permet de publier le site de documentation du Système de Design de l’État - DSFR",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Système de Design de l'État",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
],
|
|
57
57
|
"main": "./index.js",
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@gouvfr/dsfr-forge": "=1.0.
|
|
59
|
+
"@gouvfr/dsfr-forge": "=1.0.17",
|
|
60
60
|
"@gouvfr/dsfr-publisher": "npm:@gouvfr/dsfr@1.13.1",
|
|
61
61
|
"deepmerge": "^4.3.1",
|
|
62
62
|
"ejs": "^3.1.10",
|
|
@@ -69,7 +69,7 @@ class CardContainerDirective extends Node {
|
|
|
69
69
|
}
|
|
70
70
|
]
|
|
71
71
|
},
|
|
72
|
-
{
|
|
72
|
+
image ? {
|
|
73
73
|
type: 'htmlContainer',
|
|
74
74
|
tagName: 'div',
|
|
75
75
|
classes: ['fr-card__header'],
|
|
@@ -86,7 +86,7 @@ class CardContainerDirective extends Node {
|
|
|
86
86
|
]
|
|
87
87
|
}
|
|
88
88
|
]
|
|
89
|
-
}
|
|
89
|
+
} : {}
|
|
90
90
|
]
|
|
91
91
|
};
|
|
92
92
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Node } from '../../node.js';
|
|
2
2
|
|
|
3
3
|
class StorybookLeafDirective extends Node {
|
|
4
|
+
constructor (data) {
|
|
5
|
+
super(data, 'iframe');
|
|
6
|
+
}
|
|
4
7
|
|
|
5
|
-
// TODO:
|
|
6
|
-
// - script externe pour le resize de l'iframe
|
|
7
|
-
// - apossibilité de multiple storybook (baser sur id de la story ?)
|
|
8
|
-
// - bug resize down
|
|
9
|
-
// - bouton communication avec iframe pour changer le theme exemple
|
|
10
|
-
// - changement theme iframe en fonction theme parent
|
|
11
8
|
async render() {
|
|
12
|
-
return
|
|
9
|
+
return `
|
|
10
|
+
<div class="dsfr-doc-storybook-leaf">
|
|
11
|
+
${await super.render()}
|
|
12
|
+
</div>
|
|
13
|
+
`;
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -1,19 +1,55 @@
|
|
|
1
|
-
import { Element } from '../core/element.js'
|
|
1
|
+
import { Element } from '../core/element.js';
|
|
2
2
|
|
|
3
3
|
class Storybook extends Element {
|
|
4
|
-
get iframe
|
|
4
|
+
get iframe() {
|
|
5
5
|
return this.element;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
init() {
|
|
9
|
-
this.
|
|
10
|
-
|
|
11
|
-
this.
|
|
9
|
+
this.isResized = false;
|
|
10
|
+
this.setIframeTheme();
|
|
11
|
+
this.listenChangeDisplay();
|
|
12
|
+
window.addEventListener('message', this.handleMessage.bind(this));
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
15
|
+
handleMessage(event) {
|
|
16
|
+
const eventType = JSON.parse(event.data)?.event?.type;
|
|
17
|
+
if (!eventType) return;
|
|
18
|
+
|
|
19
|
+
if (eventType === 'storyRendered') {
|
|
20
|
+
this._iframeDoc = this.iframe.contentDocument;
|
|
21
|
+
if (!this._iframeDoc || this.isResized) return;
|
|
22
|
+
|
|
23
|
+
this.resize();
|
|
24
|
+
this.isResized = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
resize() {
|
|
29
|
+
const height =
|
|
30
|
+
this._iframeDoc.body?.scrollHeight ??
|
|
31
|
+
this._iframeDoc.documentElement?.scrollHeight;
|
|
32
|
+
this.iframe.style.height =
|
|
33
|
+
isNaN(height) || !height ? '100%' : height + 'px';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setIframeTheme() {
|
|
37
|
+
const theme = document.documentElement.getAttribute('data-fr-theme');
|
|
38
|
+
if (theme) {
|
|
39
|
+
const url = new URL(window.location.origin + this.iframe.dataset.src);
|
|
40
|
+
url.searchParams.set('globals', `theme:${theme}`);
|
|
41
|
+
this.iframe.src = url.toString();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
listenChangeDisplay() {
|
|
46
|
+
const display = document.getElementById('fr-display');
|
|
47
|
+
const radios = display.querySelectorAll('input');
|
|
48
|
+
radios.forEach((radio) => {
|
|
49
|
+
radio.addEventListener('change', () => {
|
|
50
|
+
this.setIframeTheme();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
17
53
|
}
|
|
18
54
|
}
|
|
19
55
|
|
package/src/script/main/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { ConsentManagementPlatform } from './cmp/index.js';
|
|
|
7
7
|
|
|
8
8
|
window.onload = async () => {
|
|
9
9
|
await instantiateElements('.code-snippet--copy', CopySnippet);
|
|
10
|
-
await instantiateElements('.storybook-leaf iframe', Storybook);
|
|
10
|
+
await instantiateElements('.dsfr-doc-storybook-leaf iframe', Storybook);
|
|
11
11
|
await instantiateElements('#search', SearchBar);
|
|
12
12
|
};
|
|
13
13
|
|