Skip to content

Commit 92a770e

Browse files
author
Flo
committed
Copy over everything from symfony/ux#2288
0 parents  commit 92a770e

38 files changed

+1368
-0
lines changed

.gitattributes

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

.gitignore

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

.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: "doc"

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# CHANGELOG
2+
3+
## 2.13.2
4+
5+
- Revert "Change JavaScript package to `type: module`"
6+
7+
## 2.13.0
8+
9+
- Add support for Svelte 4.
10+
- Add Symfony 7 support.
11+
- Change JavaScript package to `type: module`
12+
13+
## 2.9.0
14+
15+
- Add support for symfony/asset-mapper
16+
17+
- Replace `symfony/webpack-encore-bundle` by `symfony/stimulus-bundle` in dependencies
18+
19+
- Minimum PHP version is now 8.1
20+
21+
## 2.8.0
22+
23+
- Introduce the package

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2021-present 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.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Fork by ChqThomas
2+
3+
https://github.com/symfony/ux/pull/2288
4+
5+
# Symfony UX Svelte
6+
7+
Symfony UX Svelte integrates [Svelte](https://svelte.dev/) into Symfony applications.
8+
It provides tools to render Svelte 3 components from Twig.
9+
10+
**This repository is a READ-ONLY sub-tree split**. See
11+
https://github.com/symfony/ux to create issues or submit pull requests.
12+
13+
## Resources
14+
15+
- [Documentation](https://symfony.com/bundles/ux-svelte/current/index.html)
16+
- [Report issues](https://github.com/symfony/ux/issues) and
17+
[send Pull Requests](https://github.com/symfony/ux/pulls)
18+
in the [main Symfony UX repository](https://github.com/symfony/ux)
19+

assets/dist/components.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { SvelteComponent } from 'svelte';
2+
export interface ComponentCollection {
3+
[key: string]: SvelteComponent;
4+
}
5+
export declare const components: ComponentCollection;

assets/dist/components.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const components = {};
2+
3+
export { components };

assets/dist/loader.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { SvelteComponent } from 'svelte';
2+
import { type ComponentCollection } from './components.js';
3+
declare global {
4+
function resolveSvelteComponent(name: string): typeof SvelteComponent<any>;
5+
interface Window {
6+
resolveSvelteComponent(name: string): typeof SvelteComponent<any>;
7+
}
8+
}
9+
export declare function registerSvelteControllerComponents(svelteComponents?: ComponentCollection): void;

assets/dist/loader.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { components } from './components.js';
2+
3+
function registerSvelteControllerComponents(svelteComponents = components) {
4+
window.resolveSvelteComponent = (name) => {
5+
const component = svelteComponents[name];
6+
if (typeof component === 'undefined') {
7+
const possibleValues = Object.keys(svelteComponents).length > 0 ? Object.keys(svelteComponents).join(', ') : 'none';
8+
throw new Error(`Svelte controller "${name}" does not exist. Possible values: ${possibleValues}`);
9+
}
10+
return component;
11+
};
12+
}
13+
14+
export { registerSvelteControllerComponents };

assets/dist/register_controller.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { SvelteComponent } from 'svelte';
2+
declare global {
3+
function resolveSvelteComponent(name: string): typeof SvelteComponent<any>;
4+
interface Window {
5+
resolveSvelteComponent(name: string): typeof SvelteComponent<any>;
6+
}
7+
}
8+
export declare function registerSvelteControllerComponents(context: __WebpackModuleApi.RequireContext): void;

assets/dist/register_controller.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function registerSvelteControllerComponents(context) {
2+
const svelteControllers = {};
3+
const importAllSvelteComponents = (r) => {
4+
r.keys().forEach((key) => {
5+
svelteControllers[key] = r(key).default;
6+
});
7+
};
8+
importAllSvelteComponents(context);
9+
window.resolveSvelteComponent = (name) => {
10+
const component = svelteControllers[`./${name}.svelte`];
11+
if (typeof component === 'undefined') {
12+
throw new Error(`Svelte controller "${name}" does not exist`);
13+
}
14+
return component;
15+
};
16+
}
17+
18+
export { registerSvelteControllerComponents };

assets/dist/render_controller.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Controller } from '@hotwired/stimulus';
2+
import type { SvelteComponent } from 'svelte';
3+
export default class extends Controller<Element & {
4+
root?: SvelteComponent;
5+
}> {
6+
private app;
7+
readonly componentValue: string;
8+
private props;
9+
private intro;
10+
readonly propsValue: Record<string, unknown> | null | undefined;
11+
readonly introValue: boolean | undefined;
12+
static values: {
13+
component: StringConstructor;
14+
props: ObjectConstructor;
15+
intro: BooleanConstructor;
16+
};
17+
connect(): void;
18+
disconnect(): void;
19+
_destroyIfExists(): void;
20+
private dispatchEvent;
21+
}

assets/dist/render_controller.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Controller } from '@hotwired/stimulus';
2+
3+
class default_1 extends Controller {
4+
connect() {
5+
this.element.innerHTML = '';
6+
this.props = this.propsValue ?? undefined;
7+
this.intro = this.introValue ?? undefined;
8+
this.dispatchEvent('connect');
9+
const Component = window.resolveSvelteComponent(this.componentValue);
10+
this._destroyIfExists();
11+
this.app = new Component({
12+
target: this.element,
13+
props: this.props,
14+
intro: this.intro,
15+
});
16+
this.element.root = this.app;
17+
this.dispatchEvent('mount', {
18+
component: Component,
19+
});
20+
}
21+
disconnect() {
22+
this._destroyIfExists();
23+
this.dispatchEvent('unmount');
24+
}
25+
_destroyIfExists() {
26+
if (this.element.root !== undefined) {
27+
this.element.root.$destroy();
28+
delete this.element.root;
29+
}
30+
}
31+
dispatchEvent(name, payload = {}) {
32+
const detail = {
33+
componentName: this.componentValue,
34+
props: this.props,
35+
intro: this.intro,
36+
...payload,
37+
};
38+
this.dispatch(name, { detail, prefix: 'svelte' });
39+
}
40+
}
41+
default_1.values = {
42+
component: String,
43+
props: Object,
44+
intro: Boolean,
45+
};
46+
47+
export { default_1 as default };

assets/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "@symfony/ux-svelte",
3+
"description": "Integration of Svelte in Symfony",
4+
"main": "dist/register_controller.js",
5+
"version": "1.0.0",
6+
"license": "MIT",
7+
"symfony": {
8+
"controllers": {
9+
"svelte": {
10+
"main": "dist/render_controller.js",
11+
"fetch": "eager",
12+
"enabled": true
13+
}
14+
},
15+
"importmap": {
16+
"@hotwired/stimulus": "^3.0.0",
17+
"svelte/internal": "^3.0",
18+
"@symfony/ux-svelte": "path:%PACKAGE%/dist/loader.js"
19+
}
20+
},
21+
"peerDependencies": {
22+
"@hotwired/stimulus": "^3.0.0",
23+
"svelte": "^3.0 || ^4.0"
24+
},
25+
"devDependencies": {
26+
"@hotwired/stimulus": "^3.0.0",
27+
"@sveltejs/vite-plugin-svelte": "^2.4.6",
28+
"@types/webpack-env": "^1.16",
29+
"svelte": "^3.0 || ^4.0"
30+
}
31+
}

assets/src/components.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* This file is part of the Symfony package.
3+
*
4+
* (c) Fabien Potencier <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
// This file is dynamically rewritten by ux-svelte + AssetMapper.
11+
import type { SvelteComponent } from 'svelte';
12+
13+
export interface ComponentCollection {
14+
[key: string]: SvelteComponent;
15+
}
16+
17+
export const components: ComponentCollection = {};

assets/src/loader.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* This file is part of the Symfony package.
3+
*
4+
* (c) Fabien Potencier <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
import type { SvelteComponent } from 'svelte';
11+
import { type ComponentCollection, components } from './components.js';
12+
13+
declare global {
14+
function resolveSvelteComponent(name: string): typeof SvelteComponent<any>;
15+
16+
interface Window {
17+
resolveSvelteComponent(name: string): typeof SvelteComponent<any>;
18+
}
19+
}
20+
21+
export function registerSvelteControllerComponents(svelteComponents: ComponentCollection = components): void {
22+
// Expose a global Svelte loader to allow rendering from the Stimulus controller
23+
(window as any).resolveSvelteComponent = (name: string): SvelteComponent => {
24+
const component = svelteComponents[name];
25+
if (typeof component === 'undefined') {
26+
const possibleValues: string =
27+
Object.keys(svelteComponents).length > 0 ? Object.keys(svelteComponents).join(', ') : 'none';
28+
29+
throw new Error(`Svelte controller "${name}" does not exist. Possible values: ${possibleValues}`);
30+
}
31+
32+
return component;
33+
};
34+
}

assets/src/register_controller.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This file is part of the Symfony package.
3+
*
4+
* (c) Fabien Potencier <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
import type { SvelteComponent } from 'svelte';
11+
12+
declare global {
13+
function resolveSvelteComponent(name: string): typeof SvelteComponent<any>;
14+
15+
interface Window {
16+
resolveSvelteComponent(name: string): typeof SvelteComponent<any>;
17+
}
18+
}
19+
20+
export function registerSvelteControllerComponents(context: __WebpackModuleApi.RequireContext) {
21+
const svelteControllers: { [key: string]: object } = {};
22+
23+
const importAllSvelteComponents = (r: __WebpackModuleApi.RequireContext) => {
24+
r.keys().forEach((key) => {
25+
svelteControllers[key] = r(key).default;
26+
});
27+
};
28+
29+
importAllSvelteComponents(context);
30+
31+
// Expose a global Svelte loader to allow rendering from the Stimulus controller
32+
(window as any).resolveSvelteComponent = (name: string): object => {
33+
const component = svelteControllers[`./${name}.svelte`];
34+
if (typeof component === 'undefined') {
35+
throw new Error(`Svelte controller "${name}" does not exist`);
36+
}
37+
38+
return component;
39+
};
40+
}

0 commit comments

Comments
 (0)