Skip to content

Commit ff95c1a

Browse files
t-richardtgalopin
authored andcommitted
[Vue] Introduce Vue UX component
1 parent ebe425c commit ff95c1a

27 files changed

+907
-0
lines changed

src/Vue/.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.gitattributes export-ignore
2+
/.gitignore export-ignore
3+
/.symfony.bundle.yaml export-ignore
4+
/phpunit.xml.dist export-ignore
5+
/Resources/assets/test export-ignore
6+
/Resources/assets/jest.config.js export-ignore
7+
/Tests export-ignore

src/Vue/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
vendor
2+
composer.lock
3+
.php_cs.cache
4+
.phpunit.result.cache

src/Vue/.symfony.bundle.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
branches: ["2.x"]
2+
maintained_branches: ["2.x"]
3+
doc_dir: "Resources/doc"

src/Vue/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CHANGELOG
2+
3+
## 2.4
4+
5+
- Component added
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\UX\Vue\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Definition;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
18+
use Symfony\UX\Vue\Twig\VueComponentExtension;
19+
20+
/**
21+
* @author Titouan Galopin <[email protected]>
22+
* @author Thibault RICHARD <[email protected]>
23+
*
24+
* @internal
25+
*/
26+
class VueExtension extends Extension
27+
{
28+
public function load(array $configs, ContainerBuilder $container)
29+
{
30+
$container
31+
->setDefinition('twig.extension.vue', new Definition(VueComponentExtension::class))
32+
->setArgument(0, new Reference('webpack_encore.twig_stimulus_extension'))
33+
->addTag('twig.extension')
34+
->setPublic(false)
35+
;
36+
}
37+
}

src/Vue/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2020-2022 Fabien Potencier
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

src/Vue/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Symfony UX Vue.js
2+
3+
Symfony UX Vue integrates [Vue.js](https://vuejs.org/) into Symfony applications.
4+
It provides tools to render Vue.js v3 components from Twig.
5+
6+
**This repository is a READ-ONLY sub-tree split**. See
7+
https://github.com/symfony/ux to create issues or submit pull requests.
8+
9+
## Resources
10+
11+
- [Documentation](https://symfony.com/bundles/ux-vue/current/index.html)
12+
- [Report issues](https://github.com/symfony/ux/issues) and
13+
[send Pull Requests](https://github.com/symfony/ux/pulls)
14+
in the [main Symfony UX repository](https://github.com/symfony/ux)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function registerVueControllerComponents(context) {
2+
const vueControllers = {};
3+
const importAllVueComponents = (r) => {
4+
r.keys().forEach((key) => (vueControllers[key] = r(key).default));
5+
};
6+
importAllVueComponents(context);
7+
window.resolveVueComponent = (name) => {
8+
const component = vueControllers[`./${name}.vue`];
9+
if (typeof component === 'undefined') {
10+
throw new Error('Vue controller "' + name + '" does not exist');
11+
}
12+
return component;
13+
};
14+
}
15+
16+
export { registerVueControllerComponents };
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Controller } from '@hotwired/stimulus';
2+
import { createApp } from 'vue';
3+
4+
class default_1 extends Controller {
5+
connect() {
6+
var _a;
7+
this.props = (_a = this.propsValue) !== null && _a !== void 0 ? _a : null;
8+
this._dispatchEvent('vue:connect', { componentName: this.componentValue, props: this.props });
9+
const component = window.resolveVueComponent(this.componentValue);
10+
this.app = createApp(component, this.props);
11+
this.app.mount(this.element);
12+
this._dispatchEvent('vue:mount', { componentName: this.componentValue, component: component, props: this.props });
13+
}
14+
disconnect() {
15+
this.app.unmount();
16+
this._dispatchEvent('vue:unmount', {
17+
componentName: this.componentValue,
18+
props: this.props,
19+
});
20+
}
21+
_dispatchEvent(name, payload) {
22+
this.element.dispatchEvent(new CustomEvent(name, { detail: payload, bubbles: true }));
23+
}
24+
}
25+
default_1.values = {
26+
component: String,
27+
props: Object,
28+
};
29+
30+
export { default_1 as default };
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const { defaults } = require('jest-config');
2+
const jestConfig = require('../../../../jest.config.js');
3+
4+
jestConfig.moduleFileExtensions = [...defaults.moduleFileExtensions, 'vue'];
5+
jestConfig.transform['^.+\\.vue$'] = ['@vue/vue3-jest'];
6+
7+
module.exports = jestConfig;

0 commit comments

Comments
 (0)