Skip to content

Commit 9c5996c

Browse files
committed
wip: allow web component element on modulix
1 parent d4d8eb9 commit 9c5996c

File tree

8 files changed

+111
-0
lines changed

8 files changed

+111
-0
lines changed

api/src/devcomp/infrastructure/datasources/learning-content/modules/bac-a-sable.json

+62
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,68 @@
3838
}
3939
],
4040
"grains": [
41+
{
42+
"id": "0d4ef09a-ebb8-4514-a037-8fb22e540d7c",
43+
"type": "discovery",
44+
"title": "Voici un grain qui contient un webcomponent",
45+
"components": [
46+
{
47+
"type": "element",
48+
"element": {
49+
"id": "cfec5a0e-2ed5-462f-8974-e5ca25faae38",
50+
"type": "web-component",
51+
"tagName": "qcu-image",
52+
"props": {
53+
"name": "Liste d'applications",
54+
"maxChoicesPerLine": 3,
55+
"imageChoicesSize": "icon",
56+
"choices": [
57+
{
58+
"name": "Google",
59+
"image": {
60+
"width": 534,
61+
"height": 544,
62+
"loading": "lazy",
63+
"decoding": "async",
64+
"src": "https://epreuves.pix.fr/_astro/Google.B1bcY5Go_1BynY8.svg"
65+
}
66+
},
67+
{
68+
"name": "LibreOffice Writer",
69+
"image": {
70+
"width": 205,
71+
"height": 246,
72+
"loading": "lazy",
73+
"decoding": "async",
74+
"src": "https://epreuves.pix.fr/_astro/writer.3bR8N2DK_Z1iWuJ9.webp"
75+
}
76+
},
77+
{
78+
"name": "Explorateur",
79+
"image": {
80+
"width": 128,
81+
"height": 128,
82+
"loading": "lazy",
83+
"decoding": "async",
84+
"src": "https://epreuves.pix.fr/_astro/windows-file-explorer.CnF8MYwI_23driA.webp"
85+
}
86+
},
87+
{
88+
"name": "Geogebra",
89+
"image": {
90+
"width": 640,
91+
"height": 640,
92+
"loading": "lazy",
93+
"decoding": "async",
94+
"src": "https://epreuves.pix.fr/_astro/geogebra.CZH9VYqc_19v4nj.webp"
95+
}
96+
}
97+
]
98+
}
99+
}
100+
}
101+
]
102+
},
41103
{
42104
"id": "f312c33d-e7c9-4a69-9ba0-913957b8f7dd",
43105
"type": "discovery",

api/src/devcomp/infrastructure/factories/module-factory.js

+10
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export class ModuleFactory {
9393
return ModuleFactory.#buildDownload(element);
9494
case 'embed':
9595
return ModuleFactory.#buildEmbed(element);
96+
case 'web-component':
97+
return ModuleFactory.#buildWebComponent(element);
9698
case 'expand':
9799
return ModuleFactory.#buildExpand(element);
98100
case 'image':
@@ -138,6 +140,14 @@ export class ModuleFactory {
138140
});
139141
}
140142

143+
static #buildWebComponent(element) {
144+
return {
145+
...element,
146+
id: element.id,
147+
type: 'web-component',
148+
};
149+
}
150+
141151
static #buildExpand(element) {
142152
return new Expand({
143153
id: element.id,

mon-pix/app/app.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import './deprecation-workflow';
2+
import '@1024pix/web-components';
23

34
import Application from '@ember/application';
45
import { init as initSentry } from '@sentry/ember';

mon-pix/app/components/module/component/element.gjs

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import QrocmElement from 'mon-pix/components/module/element/qrocm';
1212
import SeparatorElement from 'mon-pix/components/module/element/separator';
1313
import TextElement from 'mon-pix/components/module/element/text';
1414
import VideoElement from 'mon-pix/components/module/element/video';
15+
import WebComponentElement from 'mon-pix/components/module/element/web-component';
1516

1617
export default class ModulixElement extends Component {
1718
@action
@@ -30,6 +31,8 @@ export default class ModulixElement extends Component {
3031
<DownloadElement @download={{@element}} @onDownload={{@onFileDownload}} />
3132
{{else if (eq @element.type "embed")}}
3233
<EmbedElement @embed={{@element}} @onAnswer={{@onElementAnswer}} />
34+
{{else if (eq @element.type "web-component")}}
35+
<WebComponentElement @component={{@element}} @onAnswer={{@onElementAnswer}} />
3336
{{else if (eq @element.type "expand")}}
3437
<ExpandElement @expand={{@element}} @onExpandToggle={{@onExpandToggle}} />
3538
{{else if (eq @element.type "separator")}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { on } from '@ember/modifier';
2+
import { action } from '@ember/object';
3+
import { eq } from 'ember-truth-helpers';
4+
5+
import ModuleElement from './module-element';
6+
7+
export default class ModulixWebComponent extends ModuleElement {
8+
@action
9+
handleAnswer(event) {
10+
this.args.onAnswer({
11+
userResponse: [event.detail[0]],
12+
element: this.args.embed,
13+
});
14+
}
15+
16+
<template>
17+
<div class="element-webcomponent">
18+
<div class="element-webcomponent__container">
19+
{{#if (eq @component.tagName "qcu-image")}}
20+
<qcu-image props={{@component.props}} />
21+
{{/if}}
22+
</div>
23+
</div>
24+
</template>
25+
}

mon-pix/app/components/module/grain/grain.gjs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class ModuleGrain extends Component {
1919
static AVAILABLE_ELEMENT_TYPES = [
2020
'download',
2121
'embed',
22+
'web-component',
2223
'expand',
2324
'flashcards',
2425
'image',

mon-pix/package-lock.json

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mon-pix/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@1024pix/eslint-plugin": "^2.1.0",
5050
"@1024pix/pix-ui": "^54.14.1",
5151
"@1024pix/stylelint-config": "^5.1.27",
52+
"@1024pix/web-components": "^0.2.7",
5253
"@babel/eslint-parser": "^7.25.1",
5354
"@babel/plugin-proposal-decorators": "^7.24.7",
5455
"@ember-data/json-api": "^5.3.8",

0 commit comments

Comments
 (0)