@gouvfr/dsfr-roller 1.0.66 → 1.0.68
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 +2 -2
- package/src/component/components/badge.js +28 -0
- package/src/node/directive/components/badge/badge-leaf-directive.js +18 -0
- package/src/node/directive/components/card/card-container-directive.js +11 -1
- package/src/node/node-factory.js +3 -1
- package/src/page/body/badges.js +86 -0
- package/src/page/head/resource.js +2 -1
- package/src/template/templates/editorial-template.js +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gouvfr/dsfr-roller",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.68",
|
|
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.68",
|
|
60
60
|
"@gouvfr/dsfr-publisher": "npm:@gouvfr/dsfr@1.14.2",
|
|
61
61
|
"deepmerge": "^4.3.1",
|
|
62
62
|
"ejs": "^3.1.10",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Component } from '../component.js';
|
|
2
|
+
|
|
3
|
+
class Badge extends Component {
|
|
4
|
+
constructor (data) {
|
|
5
|
+
super(data, 'badge');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
get ejsPath () {
|
|
9
|
+
return 'src/dsfr/component/badge/template/ejs/badge.ejs';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async format () {
|
|
13
|
+
const classes = ['fr-mb-6v'];
|
|
14
|
+
classes.push(...(this.data.classes || []));
|
|
15
|
+
return {
|
|
16
|
+
markup: this.data.markup || 'span',
|
|
17
|
+
size: this.data.size || 'sm',
|
|
18
|
+
label: this.data.label ?? this.data.text,
|
|
19
|
+
id: this.data.id,
|
|
20
|
+
classes: classes,
|
|
21
|
+
attributes: this.data.attributes,
|
|
22
|
+
type: this.data.type || 'info',
|
|
23
|
+
icon: this.data.icon,
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { Badge };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Node } from '../../../node.js';
|
|
2
|
+
import { Badge } from '../../../../component/components/badge.js';
|
|
3
|
+
|
|
4
|
+
class BadgeLeafDirective extends Node {
|
|
5
|
+
constructor (data) {
|
|
6
|
+
super(data);
|
|
7
|
+
this.badge = new Badge({...this.data.properties, ...this.data.attributes});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async render () {
|
|
11
|
+
const data = { label: await this.renderChildren() };
|
|
12
|
+
return this.badge.render(data);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
BadgeLeafDirective.NAME = 'fr-badge';
|
|
17
|
+
|
|
18
|
+
export { BadgeLeafDirective };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Node } from '../../../node.js'
|
|
2
|
+
import { Badges } from '../../../../page/body/badges.js';
|
|
2
3
|
|
|
3
4
|
class CardContainerDirective extends Node {
|
|
4
5
|
structure (data) {
|
|
@@ -30,6 +31,7 @@ class CardContainerDirective extends Node {
|
|
|
30
31
|
const contentDescription = contentChildren.find(child => child.type === 'paragraph');
|
|
31
32
|
const hintStart = this.structureHintStart;
|
|
32
33
|
const hintEnd = this.structureHintEnd;
|
|
34
|
+
const badges = this.structureBadges;
|
|
33
35
|
const classes = ['fr-card'];
|
|
34
36
|
switch (true) {
|
|
35
37
|
case data.properties.enlargeLink === true:
|
|
@@ -87,7 +89,8 @@ class CardContainerDirective extends Node {
|
|
|
87
89
|
...image
|
|
88
90
|
}
|
|
89
91
|
]
|
|
90
|
-
}
|
|
92
|
+
},
|
|
93
|
+
badges
|
|
91
94
|
]
|
|
92
95
|
} : {}
|
|
93
96
|
]
|
|
@@ -142,6 +145,13 @@ class CardContainerDirective extends Node {
|
|
|
142
145
|
return structureHintStart;
|
|
143
146
|
}
|
|
144
147
|
|
|
148
|
+
get structureBadges() {
|
|
149
|
+
let structureBadges = {};
|
|
150
|
+
if (this._data.badge) {
|
|
151
|
+
structureBadges = new Badges({ids: this._data.badge, resource: this._data.fragments.badge}).node;
|
|
152
|
+
}
|
|
153
|
+
return structureBadges;
|
|
154
|
+
}
|
|
145
155
|
}
|
|
146
156
|
|
|
147
157
|
CardContainerDirective.NAME = 'fr-card';
|
package/src/node/node-factory.js
CHANGED
|
@@ -40,7 +40,8 @@ import { HpFaqContainerDirective } from './directive/home/hp-faq-container-direc
|
|
|
40
40
|
import { HpAnalyticsContainerDirective } from './directive/home/hp-analytics-container-directive.js';
|
|
41
41
|
import { AccordionContainerDirective } from './directive/components/accordion/accordion-container-directive.js';
|
|
42
42
|
import { AccordionsGroupContainerDirective } from './directive/components/accordion/accordions-group-container-directive.js';
|
|
43
|
-
import { ButtonLeafDirective } from './directive/components/button/button-leaf-directive.js'
|
|
43
|
+
import { ButtonLeafDirective } from './directive/components/button/button-leaf-directive.js';
|
|
44
|
+
import { BadgeLeafDirective } from './directive/components/badge/badge-leaf-directive.js';
|
|
44
45
|
import { CardContainerDirective } from './directive/components/card/card-container-directive.js';
|
|
45
46
|
import { TableContainerDirective } from './directive/components/table/table-container-directive.js';
|
|
46
47
|
import { TabContainerDirective } from './directive/components/tabs/tab-container-directive.js'
|
|
@@ -123,6 +124,7 @@ const DIRECTIVE_CONTAINERS = [
|
|
|
123
124
|
PreventPermalinksContainerDirective
|
|
124
125
|
];
|
|
125
126
|
const DIRECTIVE_LEAFS = [
|
|
127
|
+
BadgeLeafDirective,
|
|
126
128
|
ButtonLeafDirective,
|
|
127
129
|
StorybookLeafDirective,
|
|
128
130
|
FigmaLeafDirective,
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { log } from '@gouvfr/dsfr-forge';
|
|
2
|
+
|
|
3
|
+
const BadgeVariants = {
|
|
4
|
+
BETA: {
|
|
5
|
+
id: 'beta',
|
|
6
|
+
type: 'info',
|
|
7
|
+
icon: false,
|
|
8
|
+
size: 'sm',
|
|
9
|
+
},
|
|
10
|
+
NEW: {
|
|
11
|
+
id: 'new',
|
|
12
|
+
type: 'new',
|
|
13
|
+
icon: true,
|
|
14
|
+
size: 'sm',
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const BadgesMap = new Map(Object.values(BadgeVariants).map(badge => [badge.id, badge]));
|
|
19
|
+
|
|
20
|
+
class Badges {
|
|
21
|
+
constructor(data) {
|
|
22
|
+
let {ids, resource} = data;
|
|
23
|
+
if (typeof ids === 'string') ids = ids.split(',');
|
|
24
|
+
if (!Array.isArray(ids)) {
|
|
25
|
+
log.error(`Badge must be a string or an array of strings, received: ${typeof ids}`);
|
|
26
|
+
this._node = {};
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const badges = ids.map(id => this._formatBadge(id, resource));
|
|
30
|
+
if (badges.every(badge => Object.keys(badge).length === 0)) {
|
|
31
|
+
this._node = {};
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this._node = {
|
|
35
|
+
type: 'htmlContainer',
|
|
36
|
+
tagName: 'ul',
|
|
37
|
+
classes: ['fr-badges-group', 'fr-mb-2v'],
|
|
38
|
+
children: badges
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_getIconClasses (icon) {
|
|
43
|
+
if (icon === false) {
|
|
44
|
+
return ['fr-badge--no-icon'];
|
|
45
|
+
}
|
|
46
|
+
if (icon === true) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
return [`fr-icon-${icon}`];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_formatBadge (id, resource) {
|
|
53
|
+
const badgeData = BadgesMap.get(id);
|
|
54
|
+
if (!badgeData) {
|
|
55
|
+
log.error(`Unknown badge type: ${id}`);
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
type: 'htmlContainer',
|
|
60
|
+
tagName: 'li',
|
|
61
|
+
children: [
|
|
62
|
+
{
|
|
63
|
+
type: 'paragraph',
|
|
64
|
+
classes: [
|
|
65
|
+
'fr-badge',
|
|
66
|
+
`fr-badge--${badgeData.type}`,
|
|
67
|
+
`fr-badge--${badgeData.size}`,
|
|
68
|
+
...this._getIconClasses(badgeData.icon)
|
|
69
|
+
],
|
|
70
|
+
children: [
|
|
71
|
+
{
|
|
72
|
+
type: 'text',
|
|
73
|
+
value: resource[id],
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get node () {
|
|
82
|
+
return this._node;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export { Badges };
|
|
@@ -6,7 +6,8 @@ class Resource extends Renderable {
|
|
|
6
6
|
meta: this._data.resource.meta,
|
|
7
7
|
search: this._data.resource.search,
|
|
8
8
|
pagination: this._data.resource.pagination,
|
|
9
|
-
consent: this._data.resource.consent
|
|
9
|
+
consent: this._data.resource.consent,
|
|
10
|
+
badge: this._data.resource.badge
|
|
10
11
|
};
|
|
11
12
|
return `<script>
|
|
12
13
|
window.resource = ${JSON.stringify(resource)};
|
|
@@ -4,6 +4,7 @@ import { Breadcrumb } from '../../component/components/breadcrumb.js';
|
|
|
4
4
|
import { TOC } from '../../page/body/toc.js';
|
|
5
5
|
import { Edit } from '../../page/body/edit.js';
|
|
6
6
|
import { Mesh } from '../../page/body/mesh.js';
|
|
7
|
+
import { Badges } from '../../page/body/badges.js';
|
|
7
8
|
|
|
8
9
|
class EditorialTemplate extends Template {
|
|
9
10
|
constructor (data) {
|
|
@@ -20,6 +21,12 @@ class EditorialTemplate extends Template {
|
|
|
20
21
|
structure (data) {
|
|
21
22
|
this._hasEditUrl = data?.editUrl != null;
|
|
22
23
|
this._hasMesh = data?.mesh?.items?.length;
|
|
24
|
+
this._hasBadge = data?.badge != null;
|
|
25
|
+
|
|
26
|
+
if (this._hasBadge) {
|
|
27
|
+
const badges = new Badges({ids: data.badge, resource: data.resource.badge});
|
|
28
|
+
data.nodes.unshift(badges.node);
|
|
29
|
+
}
|
|
23
30
|
|
|
24
31
|
if (this._hasEditUrl) {
|
|
25
32
|
const edit = new Edit({...data.resource.edit, editUrl: data.editUrl, blankLabel: data.fragments.blank});
|